looks to me like a GL_POLYGON is internally drawn as a GL_TRIANGLE_FAN.
if you switch to glPolygonMode(GL_FRONT_AND_BACK, GL_LINE), you should see that all triangles start at one single point.
and since your polygon is not konvex, some triangles overlap.
[QUOTE=RigidBody;1251205]looks to me like a GL_POLYGON is internally drawn as a GL_TRIANGLE_FAN.
if you switch to glPolygonMode(GL_FRONT_AND_BACK, GL_LINE), you should see that all triangles start at one single point.
and since your polygon is not konvex, some triangles overlap.
btw, which country is that?[/QUOTE]
Its a city limits from Blumenau - Santa Catarina - Brasil…
OpenGL only guarantees drawing convex polygons correctly with glBegin/glEnd. It states this here: glBegin
The bit that covers in in the compatibility spec is:
//INIT CODE
glEnable(GL_DEPTH_TEST);
//DRAW CODE
glClear(GL_COLOR_BUFFER_BIT|GL_STENCIL_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glEnable(GL_STENCIL_TEST);
glBindVertexArray(m_VAO);
//Dont write in the color buffer
//Dont write in the depth buffer
glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
glDepthMask(GL_FALSE);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS,0x1,0x1);
glStencilOp(GL_KEEP,GL_KEEP,GL_INVERT);
glDrawArrays(GL_TRIANGLE_FAN,0,m_Vertices.size());
//Draw the triangle strip a second time but only where the stencil is one
glDepthMask(GL_TRUE);
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
glStencilFunc(GL_EQUAL,0x1,0x1);
//NOT TESTED: using GL_INVERT as the last parameter permit to clear stencil value to 0 where
//stencil value is one and to draw multiple concave polygon in the same frame.
glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
glDrawArrays(GL_TRIANGLE_FAN,0,m_Vertices.size());
glDisable(GL_STENCIL_TEST);
It work fine for me.
Also,when you create your rendering context with GLUT for example, you must ask for a depth buffer with a stencil buffer to be present when you call glutInitDisplayMode.
glVertexPointer(3, GL_DOUBLE, 0, data());
glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
glDepthMask(GL_FALSE);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS,0x1,0x1);
glStencilOp(GL_KEEP,GL_KEEP,GL_INVERT);
glDrawArrays(GL_TRIANGLE_FAN,0,size());
//Draw the triangle strip a second time but only where the stencil is one
glDepthMask(GL_TRUE);
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
glStencilFunc(GL_EQUAL,0x1,0x1);
//NOT TESTED: using GL_INVERT as the last parameter permit to clear stencil value to 0 where
//stencil value is one and to draw multiple concave polygon in the same frame.
glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
glDrawArrays(GL_TRIANGLE_FAN,0,size());
glDisable(GL_STENCIL_TEST);
//Desenha contorno
glColor3f(0,0,0);
glDrawArrays(GL_LINE_LOOP,0,size());
I have tried your data and the algorithm with stencil buffer work as is. I think your problem is when you read your data in a file or when you pass the data to OpenGL. Check if the value of your points in the array is all valid.
To test your data, I have computed the min and max for x and y. Then computed the mean value for both min max for each x,y and subtracted that value to each point. I do so because it easier to hardcode the value for the orthographic projection and I have read on this forum (but I don’t remember well) that when you give large value for translatef, strange things can happen (Your vertices are far away the origin). When you call VertexPointer with GL_DOUBLE most if not all OpenGL implementations convert your data to GL_FLOAT type, but I don’t think it will solve your problem.
[QUOTE=trinitrotoluene;1251315]To test your data, I have computed the min and max for x and y. Then computed the mean value for both min max for each x,y and subtracted that value to each point. I do so because it easier to hardcode the value for the orthographic projection and I have read on this forum (but I don’t remember well) that when you give large value for translatef, strange things can happen (Your vertices are far away the origin). When you call VertexPointer with GL_DOUBLE most if not all OpenGL implementations convert your data to GL_FLOAT type, but I don’t think it will solve your problem.
I never used MFC so I can’t help for this.[/QUOTE]
My ortho has the min and max x/y…
I will try to do this, subtract the min x and y to each point. And set my ortho do 0 and width of the limit map.