2011-11-29 40 views
2

这是在opengl中的简单矩形图形代码..我想用某种颜色填充矩形,并且想要应用非零缠绕规则来告诉用户矩形是否填充到内部或外面...我怎么能做到这一点?在opengl中填充矩形并应用非零缠绕规则

#include <cstdlib> 
#include <iostream> 
#include<GL/glut.h> 

using namespace std; 

#include <GL/glut.h> 

void display(void) 
{ 
    glClear (GL_COLOR_BUFFER_BIT); 


    glColor3f (1.0, 1.0, 1.0); 
    glBegin(GL_POLYGON); 
     glVertex3f (0.25, 0.25, 0.0); 
     glVertex3f (0.75, 0.25, 0.0); 
     glVertex3f (0.75, 0.75, 0.0); 
     glVertex3f (0.25, 0.75, 0.0); 
    glEnd(); 


    glFlush(); 
} 

void init (void) 
{ 

    glClearColor (0.0, 0.0, 0.0, 0.0); 


    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity(); 
    glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0); 
} 


int main(int argc, char** argv) 
{ 
    glutInit(&argc, argv); 
    glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); 
    glutInitWindowSize (250, 250); 
    glutInitWindowPosition (100, 100); 
    glutCreateWindow ("hello"); 
    init(); 
    glutDisplayFunc(display); 
    glutMainLoop(); 
    return 0; 
} 
+1

不推荐使用glBegin()和glEnd()对,不再使用旧功能。只是在说' :) – ScarletAmaranth

回答