Archived

This topic is now archived and is closed to further replies.

XeroGaMeR

Trouble with glBegin(GL_POLYGON)

Recommended Posts

Ok I''m new so bear with me. Ok I can draw using GL_QUADS and GL_TRIANGLES but I''m having trouble getting something drawn with GL_POLYGON. The program doesn''t crash or anything bad, but it doesn''t actually draw the polygon. All I need is a quick example (I think) to show my how to use GL_POLYGON. Thanks.

Share this post


Link to post
Share on other sites
Ok that still doesn''t work. I inserted it into the lesson 2 code (replacing the triangle and square) and it still doesn''t work. Here''s my draw code:

int DrawGLScene(GLvoid) // Here''s Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(0.0f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0
glBegin(GL_POLYGON);
glVertex3f(0,1,1);
glVertex3f(1,.75,1);
glVertex3f(.75,0,1);
glVertex3f(-.75,0,1);
glVertex3f(-1,.75,1);
glEnd(); // Done Drawing The Quad
return TRUE; // Keep Going
}

Share this post


Link to post
Share on other sites
It is possibly being culled as backfacing, try

glDisable(GL_CULL_FACE);

somewhere before the glBegin. That should at least show you it works. When you start using it you''ll have to make sure your polygons are wound the correct way.

Share this post


Link to post
Share on other sites
You should be passing the numbers to glVertex3f like this, glVertex3f(1.0f,0.6f,0.3f); <-- notice the f part, that way it they won''t get treated as doubles but as floats.

Share this post


Link to post
Share on other sites
GL_POLYGON, as far as I can remember, has exactly the same end result as GL_TRIANGLE_FAN (except when viewed in wireframe that is)... so it may just be you have misunderstood how the format works.

| - Project-X - my mega project.. big things comming soon - | - adDeath - an ad blocker I made - | - email me - |

Share this post


Link to post
Share on other sites
ok then. i copyed the code you pasted and it works fine for me AS IS so look elsewere in your code for the problem. `:O


anyways GL_POLYGON is NOT the same as GL_TRIANGLE_FAN. if you use GL_POLYGON then the specs say the following about it:


Only convex polygons are guaranteed to be drawn correctly by the GL. If a
specified polygon is nonconvex when projected onto the window, then the rendered
polygon need only lie within the convex hull of the projected vertices defining its
boundary.



so make shore that if all the edges are extended indefinatly that they only cross another edge twice. this is not the case with GL_TRIANGLE_FAN as it draws sepperat triangles. that meens that some of the triangels could overlap if drawing a concave hull and/or be drawn backwards.



- Jono AH

Share this post


Link to post
Share on other sites