Hello everybody. Im new to OpenGL. As a project im assigned to create a simple program that creates polygons.
When you click on the window a vertex appears and with each subsequent click the vertexes connect with each other which results in creating a polygon.
Im assigned to fill the polygons according to some rules. Two of them are the “non zero” winding rule and the “odd” winding rule.
Ive the done the part where you create the polygons. But i struggle to find helpful info for the “gluTess” functions and simple examples.
Does anybody have any idea where to start from? I’ve read some tutorials on glprogramming site and Khronos site but these doesnt help a lot a beginner.
Thanks in advance!
Edit: Lets say for example i want to fill this polygon. What is going wrong with this code? Again im sorry if this example is totally wrong but im really trying to find out how the “glutess” works
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <GL\glut.h>
GLdouble rect[4][3] = {{50.0, 50.0, 0.0},
{200.0, 50.0, 0.0},
{200.0, 200.0, 0.0},
{50.0, 200.0, 0.0}};
void beginCallback(GLenum which){
glBegin(which);
}
void endCallback(void){
glEnd();
}
void errorCallback(GLenum errorCode){
const GLubyte *estring;
estring = gluErrorString(errorCode);
fprintf (stderr, "Tessellation Error: %s
", estring);
exit (0);
}
void display(){
glColor3f(0, 0, 0);
glPointSize(5);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 500.0, 0.0, 500.0);
GLUtesselator *tobj = gluNewTess();
gluTessCallback(tobj, GLU_TESS_ERROR, (void (__stdcall*)(void))glVertex3dv);
gluTessCallback(tobj, GLU_TESS_ERROR, (void (__stdcall*)(void))endCallback);
gluTessCallback(tobj, GLU_TESS_ERROR, (void (__stdcall*)(void))beginCallback);
gluTessCallback(tobj, GLU_TESS_ERROR, (void (__stdcall*)(void))errorCallback);
glShadeModel(GL_FLAT);
gluTessBeginPolygon(tobj, NULL);
gluTessBeginContour(tobj);
glColor3f(1, 0, 0);
gluTessVertex(tobj, rect[0], rect[0]);
gluTessVertex(tobj, rect[1], rect[1]);
gluTessVertex(tobj, rect[2], rect[2]);
gluTessVertex(tobj, rect[3], rect[3]);
gluTessEndContour(tobj);
glFlush();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}