PDA

View Full Version : Draw a square?



Cucus
05-02-2011, 09:12 AM
Hi, I try to draw a square but I have the problem which can be see and the images. Can someone explain me why?

I use GL_QUADS.

Thanks

McLeary
05-02-2011, 09:26 AM
It looks like you are drawing the vertices in the wrong order. You need to keep an orientation. Can you post your draw code here?

Cucus
05-02-2011, 09:36 AM
The coords:

GLfloat a[]={
0.0f,0.0f,0.0f,0.0f,
0.0f,1.0f,0.0f,0.0f,
0.0f,0.0f,1.0f,0.0f,
0.0f,1.0f,1.0f,0.0f
};

McLeary
05-02-2011, 09:42 AM
As I said, it is in the wrong order.



GLfloat a[]={
0.0f,0.0f,0.0f,0.0f,
0.0f,1.0f,0.0f,0.0f,
0.0f,1.0f,1.0f,0.0f
0.0f,0.0f,1.0f,0.0f,
};

// change coord 3 with 4.


BTW, why homogeneous coords are set to 0.0f? It shouldn't be 1.0f?

Cucus
05-02-2011, 09:45 AM
Ok, it works! Thank you!

I try with 0.0f and 1.0f and I don't see any difference, so I prefer with 0.0f because it's easier to read.

McLeary
05-02-2011, 10:13 AM
It is odd. Using 0.0 as the homogeous coordinates gives you a vector instead of a point. Maybe, when you are drawing, you are ignoring the fourth coordinate. In order to have project points on screen, OpenGL divides x,y and z by the w value, if it is different from 0.

Cucus
05-02-2011, 11:05 AM
I see,

In my code I write:
glVertexPointer(3,GL_FLOAT,4*sizeof(GL_FLOAT),0);
It has been copied from a code on Internet

Now I put glVertexPointer(4,GL_FLOAT,4*sizeof(GL_FLOAT),0);
with the w value to 1.0f.

Thanks