Public Group

# Yet another question...

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

## Recommended Posts

Sorry to keep bothering you guys. One of these days I will get it right. OK so I'm using OpenGL to draw some simple polygons on the screen for practice. Here's what I tried:
       glBegin(GL_QUADS);
glVertex3f(1.0, 1.0, -10.0);
glVertex3f(1.0, 2.0, -10.0);
glVertex3f(2.0, 1.0, -10.0);
glVertex3f(2.0, 2.0, -10.0);
glEnd();

But what shows up is unexpected. It shows a strange looking quadrilateral that has five sides yet I specified four vertices. The first parameter of glVertex3f is the x coordinate in space, the second one being the y coordinate, and the last one being the z coordinate correct? So Then wouldn't this code draw out a square on the screen? Not sure why that shape is showing up. Thanks for any help.

##### Share on other sites
the code you posted looks correct

maybe the problem is elsewhere in your code

##### Share on other sites
I used the code from this topic (the last post):

http://www.gamedev.net/community/forums/topic.asp?topic_id=294988

##### Share on other sites
I think you're not defining vertices in the right order.

A(1,2)   B(2,2)+--------+|        ||        ||        |+--------+D(1,1)   C(2,1)

Here is what you do, you define your quad this way DACB
but you should be defining it ABCD. Try using coordinates as follow:
glBegin(GL_QUADS);  glVertex3f(1.0, 2.0, -10.0);  glVertex3f(2.0, 2.0, -10.0);  glVertex3f(2.0, 1.0, -10.0);  glVertex3f(1.0, 1.0, -10.0);glEnd();

hope that helps !
Matt

##### Share on other sites
I think you're drawing your verticies in the incorrect order. It should go in a CW or CCW circle like so:

glVertex3f(1.0, 1.0, -10.0);
glVertex3f(1.0, 2.0, -10.0);
glVertex3f(2.0, 2.0, -10.0);
glVertex3f(2.0, 1.0, -10.0);
glEnd();

1. 1
Rutin
41
2. 2
3. 3
4. 4
5. 5

• 16
• 18
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633362
• Total Posts
3011526
• ### Who's Online (See full list)

There are no registered users currently online

×