填充矩形并在opengl中应用非零缠绕规则

时间:2011-11-29 14:21:48

标签: c++ 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 个答案:

答案 0 :(得分:1)

使用GLU Tesselator