Opengl glDrawArrays

GLfixed box[] = {
-0.5f, -0.5f, 0.5f,
0.5f, -0.5f, 0.5f,
-0.5f, 0.5f, 0.5f,
0.5f, 0.5f, 0.5f,
};
glVertexPointer(3, GL_FIXED, 0, box);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDrawArrays(GL_TRIANGLE_STRIP, 4, 4);

Why it works if the array have only 4 elements?

Thanx, Giuseppe

GLfixed box[] = {
-0.5f, -0.5f, 0.5f,
0.5f, -0.5f, 0.5f,
-0.5f, 0.5f, 0.5f,
0.5f, 0.5f, 0.5f,
};

the box[] have only the vertex of one side of a cube.

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDrawArrays(GL_TRIANGLE_STRIP, 4, 4);

the last 2 parameters of the method glDrawArrays its the initial position and vertex count… so, the code you posted here, you should have at least 8 vertex, since you start in the position 4 and draw 4 vertex

if you wanna know how triangle strip works,

No, You don’t understand…the code works properly, but the vertex array has ONLY 4 vertex instead 8…but the program works! This is very strange…or not?

The program might “work” on your machine but it could just as well crash on another. You’re accessing undefined memory. You are responsible for making sure GL can access the vertices you point it to.

Besides, you can’t properly convert from float to GLfixed without an explicit conversion. Here the values will all be rounded to 0.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.