Drawing and coordinates

Hello there,

I’ve read many tutorials about drawing and coordinates systems.
I understood the theory about matrix transformations and how to draw simple objects to the screen.

But I don’t understand how is drawing related to the different coordinates systems.
I’ve specified the triangle vertices coordinates, for example. After drawing it, how do I know which coordinate system they are drawn to?

I’m using shaders.
In the vertex shader, the gl_Position is being assigned to the vPos in variable which was multiplied by the transformation matrices (I know the order matters here).
But by doing that does OpenGL is aware that my object was in another coordinate system or does it always supposed I have vertices in device coordinates?

How should the vertices be specified before doing further transformations?

I’m very confused about this and would really appreciate any advices or links.

[QUOTE=koplersky;1255476]In the vertex shader, the gl_Position is being assigned to the vPos in variable which was multiplied by the transformation matrices (I know the order matters here).
But by doing that does OpenGL is aware that my object was in another coordinate system or does it always supposed I have vertices in device coordinates?[/QUOTE]

gl_Position is always in clip coordinates. The geometry will be clipped to to the homogeneous unit cube (-w<=x,y,z<=w), then converted to Euclidean coordinates by dividing x,y,z by w, then to screen coordinates according to the viewport and depth range.

OpenGL doesn’t care how you calculate gl_Position, only the value which is assigned to it. So you can pass vertices to the vertex shader in whichever coordinate system(s) you want. It’s up to the vertex shader to produce vertices in clip coordinates; that’s what vertex shaders are for (they can do other things, but the one thing which they must do is to store a vertex position in clip coordinates in gl_Position).

If you don’t use a vertex shader, the behaviour of the fixed-function pipeline is to transform the original vertex coordinates (from e.g. glVertex() or glVertexPointer() or whatever) by the concatenation of the projection and model-view matrices. IOW, the equivalent of:


void main() {
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}

That’s exactly the answer I was looking for.
A thousand thanks!