Archived

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

Trouble with glBegin(GL_POLYGON)

This topic is 5656 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

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 on other sites

  glBegin(GL_POLYGON);glVertex3f(0,1,1);glVertex3f(1,.75,1);glVertex3f(.75,0,1);glVertex3f(-.75,0,1);glVertex3f(-1,.75,1);glEnd();

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 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 on other sites
Maybe he is drawing it counter clockwise ?
So it faces him backwards.

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 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 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 on other sites
Alright it works now. Thanks for the help.

1. 1
2. 2
3. 3
4. 4
5. 5
Rutin
17

• 9
• 12
• 9
• 12
• 37
• Forum Statistics

• Total Topics
631420
• Total Posts
2999990
×