Yet another question...

Started by
3 comments, last by Sam Gamgee 19 years, 3 months ago
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.
Advertisement
the code you posted looks correct

maybe the problem is elsewhere in your code
I used the code from this topic (the last post):

http://www.gamedev.net/community/forums/topic.asp?topic_id=294988
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
Matt
I think you're drawing your verticies in the incorrect order. It should go in a CW or CCW circle like so:

glBegin(GL_QUADS);
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();

This topic is closed to new replies.

Advertisement