Coordinates, Vertex Array, glDrawElements,etc

Hi, these are a few newbie questions which I could not really find answers to after briefly scanning through the forum.

Background: I am using glut (based on samples in the redbook), with Visual C++.


Can anyone tell me what the arguments mean? 400 in x direction ? In what units? where is (0,0)?

glutInitWindowPostion(100, 100);

(100, 100) is based on what? where is (0,0)?


is this (x,y,z)? once again, in what units and where is (0,0,0)?

static GLubyte allIndices = 4,5,6,7,1,2,6,5,0,1,5,4,0,3,2,1,0,4,7,3,2,3,7,6);
glDrawElements(GL_QUADS, 24, GL_UNSIGNED_BYTE, allIndices);

Once again, what does the (4,5,6,7…) mean?

I would be grateful if anyone can just answer any of the questions, pls reply even if you just want to answer one question and not all of them, i’ll be happy to get any help. Thanks!!

400 is the width of the window and 150 is height

glutInitWindowPostion(100, 100);
left top (0,0)


you can render glVertex3f(0,0,0) to see where it is

static GLubyte allIndices = 4,5,6,7,1,2,6,5,0,1,5,4,0,3,2,1,0,4,7,3,2,3,7,6);
glDrawElements(GL_QUADS, 24, GL_UNSIGNED_BYTE, allIndices);

4,5,6,7 means the fourth vertex in the vertex array and fifth vertex etc…
you must set the point array first

If you were doing your drawing in 2d then 0,0 would be bottom left
If you were doing it in 3d then 0,0,0 (z axis aswell) would be in the centre of the screen

>>glutInitWindowPostion(100, 100);
This basically means where on your screen to draw your window, the numbers are poixels, i think, and 0,0 would be top left

This is used to draw things, it uses coordinates. In this case it would use 3d space where 5 = x 10=y and 1.5 = z. On its own it doesnt do much, but if you did something like this:


Then that should draw a line 10 large on the y axis, i.e. going straight up.

The f in the vertex line denotes float. From what i can gather ints can be used, i think if you substitute the f with a d then that would use ints.

Similarly glVertex2f uses 2 dimensions when drawing, i.e. x,y. So with our example of before the following would draw the same line


All these values are in pixels if what i understand is correct.

I think that should help you out, as for the other one you asked for i have no idea, sorry dude

To answer the “units” question - it’s entirely up to you. You pass numbers to OpenGL and it draws things on the screen based on how you’ve set things up - there’s no concept of units in OpenGL’s mind.

Inches, centimeters, fathoms, parsecs, whatever.

If you are unsure about a function say like glVertex??
On the main page of this website if a search bar, enter the openGL command and it will display a link for information on that command.

You can download for free the Red and blut book in PDF format, both are a good refernce on the openGL commands.

As for coordinates, you have diffrent values for diffrent aspects of openGL.

First you have pixel coordinates, that is how big our window’s drawing area is.
These commands set up drawing area in window

  1. Example void glutInitWindowSize(int width, int height) Set hight and width of a window in pixels. The windows start with 0,0 so no need to state it.
    0,0 is located at the top left corner in a window.

  2. void glutInitWindowPosition(int x, int y); Position of window on the desktop, again 0,0 is the top left corner of the desktop.

Next we have world coordinates and projection coordinates.

Projection is what part of our 3D world we are looking at, like in a 3D shooter we see only the view of the world as from a person’s eyes.

World or Model matrix is where an object is located in our 3D world.

Just like in real life if you place an object behind the camara you will not see anything. So it is important to understand how to use the projection and model matrix.

The same with your line if you draw it outside of the projection matrix you will never see it, even though it is being processed.

Example: glVertex3f( x, y, z) f= float valus, 3 means the function requires three values. you can also use only 2 for a 2D drawing(glVertex2f(x,y).

Where on the screen 0,0,0 is in relation to your objects depends on the projection setup. You can set your projection to match your windows coordinates or 0,0,0 could be the center of the window in gl units.