PDA

View Full Version : glDrawArrays & glDrawElements GL_POLYGON Problems

DragonSpawn
04-15-2005, 03:11 AM
Hey,

I'm having some problems drawing a polygon using a vertex array :(

If I put the vertex data into a glBegin(GL_POLYGON), glEnd() it will work fine but the below code refuses to work. I have enabled the vertex array in another function, this code works if you tell it to draw points or lines but not polygons.

Any ideas?

Thanks

Paul

static GLint vertices[] = { 0.25, 0.25, 0.0,
0.75, 0.25, 0.0,
0.75, 0.75, 0.0,
0.25, 0.75, 0.0 };

static GLfloat colors[] = { 0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
0.0, 0.0, 1.0 };

static GLubyte indices[] = { 0, 1, 2, 3 };

glVertexPointer (3, GL_INT, 0, vertices);
glColorPointer (3, GL_FLOAT, 0, colors);

glDrawElements (GL_POLYGON, 4, GL_UNSIGNED_BYTE, indices);

//glDrawArrays (GL_POLYGON, 0, 4);

jide
04-15-2005, 03:16 AM
Originally posted by DragonSpawn:

static GLint vertices[] = { 0.25, 0.25, 0.0,
0.75, 0.25, 0.0,
0.75, 0.75, 0.0,
0.25, 0.75, 0.0 };

Oups ! I didn't see if the other things are right. But that is wrong. You say you put GLint inside vertices but you use float values. If I'm not wrong, this simply cast values, all to zero. So you can not see anything at all.

DragonSpawn
04-15-2005, 04:48 AM
Oops, that was a typo :)

But this code does not work, the only difference being that instead of creating a square, it creates a 8-sided polygon.

/-\
| |
\-/

Any ideas?

static GLfloat vertices[] = { -1.00, 0.00, 0.00,
-2.00, 0.00, -1.00,
-2.00, 0.00, -2.00,
-1.00, 0.00, -3.00,
1.00, 0.00, -3.00,
2.00, 0.00, -2.00,
2.00, 0.00, -1.00,
1.00, 0.00, 0.00 };

static GLfloat colors[] = { 0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
0.0, 0.0, 1.0 };

static GLubyte indices[] = { 0, 1, 2, 3, 4, 5, 6, 7 };

glVertexPointer (3, GL_FLOAT, 0, vertices);
glColorPointer (3, GL_FLOAT, 0, colors);

glDrawElements (GL_POLYGON, 8, GL_UNSIGNED_BYTE, indices);

jide
04-15-2005, 07:28 AM
for drawing squares, try GL_QUADS instead of GL_POLYGON. The last draws only one polygon whatever how many vertices you specify in the array.

DragonSpawn
04-15-2005, 07:36 AM
I'm not trying to draw a square :p I'm trying to draw a polygon shaped like:

/-\
| |
\-/

but the above code is not drawing anything :(

jide
04-15-2005, 10:37 AM
OK. I didn't noticed that.

It's simply because you culled the back faces and you draw it so it can be seen from bottom only.

DragonSpawn
04-15-2005, 10:44 AM
Ah....forgive me, its been one of those days.

Thankyou :)