# How to draw or translate into world space?

I've been hacking around with OpenGL, but there's a few concepts which I can not find the answer on.

I want to draw three GL_QUADS next to eachoter like so: 1[2][3]

I know GL_QUADS are deprecated, but for this question i'd like to use them nonetheless. Each quad will have its own color, the first being red, second green and the third blue. [r][g][b]

my code:

void display()
{
glClear(GL_COLOR_BUFFER_BIT);

GLfloat vertices[] = {
-1, -1,  1, -1,  1, 1,  -1, 1,
1, -1,  3, -1,  3, 1,   1, 1,
3, -1,  5, -1,  5, 1,   3, 1
};

GLfloat colors[] = {
1, 0, 0,  1, 0, 0,  1, 0, 0,  1, 0, 0,
0, 1, 0,  0, 1, 0,  0, 1, 0,  0, 1, 0,
0, 0, 1,  0, 0, 1,  0, 0, 1,  0, 0, 1
};

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);

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

glMatrixMode(GL_PROJECTION);
glTranslatef(-1, 0, 0);

glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);

glFlush();
}


result being:

• I'm confused as which to which matrix I should apply the translation matrix and in which order.
• I'm almost certain I should not use glMatrixMode(GL_PROJECTION)
• What are the initial values of a matrix?
• I'm not certain which coords to pass in the vertex array at this point, model space or world space?

I hope you can shed some light in my confusion.

I'm confused as which to which matrix I should apply the translation matrix and in which order.

OpenGL mixes camera and model transformations which is highly unintuitive at first (GL_MODELVIEW). Read the tutorials at the end on my answer to better understand things.

I'm almost certain I should not use glMatrixMode(GL_PROJECTION)

True. GL_PROJECTION is for choosing between orthogonal (2D, UI) and perspective (3D) projection. Do not touch yet.

What are the initial values of a matrix?

All zeroes but ones on the diagonal. Called identity matrix. Does nothing when multiplied on a vector or matrix. Use glLoadIdentity to reset matrices.

1 0 0
0 1 0
0 0 1


I'm not certain which coords to pass in the vertex array at this point, model space or world space?

Model space!

See the ancient but still excellent NeHe tutorials for more info on these topics: http://nehe.gamedev.net/tutorial/lessons_01__05/22004/ , especially http://nehe.gamedev.net/tutorial/your_first_polygon/13002/

• Thank you, this answers all my questions perfectly. Also thanks for the references. Up until now i avoided NeHe because i've been told how ancient it was, but that's been a mistake! There's really valuable information there for beginning opengl programmers.
– Oje
Feb 10, 2014 at 11:51
• Yes, many concepts like immediate mode GL are obsolete nowadays, but many others (like camera transforms) are not. Plus you will be able to translate the obsolete concepts into their modern counterparts easily. Feb 12, 2014 at 4:58