Set origin for vertex array


I’m drawing bounding boxes for objects in a scene to better debug a physics engine I’m in the middle of writting. The code is nothing all that crazy; for each object with collisions enabled, I just do

glVertex3f(x1,y1,z1); (...) glVertex3f(xn, yn, zn);

And it works, the boxes are drawn correctly. However, the resulting lines – whose xyz values are world coordinates, ie not relative to object space – will automatically adopt the origin of the last drawn object as world origin, meaning every other box already drawn gets translated by that vector.

My guess is the shader I use to render the 3d objects is messing with me and multiplying the coordinates by the model matrix, but I’m not really sure what’s going on. So, how do we ensure that these vertex positions are not modified after glEnd() ?

Yes. Specifically the then-current GL_MODELVIEW and GL_PROJECTION matrices.

The positions you provide aren’t all provided in some shared coordinate frame (e.g. eye-space, or clip-space). The space they’re provided in is defined by the active GL_MODELVIEW and GL_PROJECTION matrices.

So you need to make sure the active MODELVIEW and PROJECTION transforms are active at the top of these stacks when you draw your boxes.