Trouble with glBegin(GL_POLYGON)

Started by
7 comments, last by XeroGaMeR 21 years, 3 months ago
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.
--Insert smart and witty signature here--
Advertisement

  glBegin(GL_POLYGON);glVertex3f(0,1,1);glVertex3f(1,.75,1);glVertex3f(.75,0,1);glVertex3f(-.75,0,1);glVertex3f(-1,.75,1);glEnd();  
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
}
--Insert smart and witty signature here--
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.

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


- JonoRule #1: If you build it, they will come -- to hack and cheat.
Alright it works now. Thanks for the help.
--Insert smart and witty signature here--

This topic is closed to new replies.

Advertisement