I just want to know how to specify co-ordinate ranges myself, for example:
* Change to absolut co-ordinates, so that 1 pixel == 1.
* And the more common, make lower left part of the window/screen (0,0). Though I think glScalef(...) is the way to go for this...
Thanks for the reply, but as far as I understand, gluOrtho2D only sets up the max/min clipping limits. so would
gluOrtho2D (0, windowWidth, 0, windowHeight);
mean that windowWidth is now the maximum possible x co-ordinate? And 0 being the bottom left co-ord? --Ive had this in my program already, but it seems that some sort of relative system is still used - as my x is between -3.0 and 3.0, whilst y is -2.0 <= y <= 1.94
You should not put gluPerspective after gluOrtho2D !
Read the docs …
"The matrix generated by gluPerspective is multipled by the
current matrix, just as if glMultMatrix were called with the
generated matrix. To load the perspective matrix onto the
current matrix stack instead, precede the call to
gluPerspective with a call to glLoadIdentity.
" http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/glu/perspective.html
Yhea, I just tried putting it there to see if it makes a difference… tbh, it doesnt for some reason :s
Maybe I explained myself wrong initially… I wish to set the maximum and minimum that I choose (though I used absolute as an example, after thinking about window resizes, I would rather just stick to a relative system). Heres my initGL code at attempting this, am I missing something?
As far as I understand, you want 2D projection and coordinates in pixel, I mean, lower left corner is (0,0) and upper right one is (w,h) where w is the window width and h the window height in pixels, is that correct?
you need to do something like this, when you resize the window:
void reshape(GLuint wWidth, GLuint wHeight)
{
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
// set a 2D orthographic projection
// x range: [0 wWidth]
// y range: [0 wHeight]
glOrtho(0, wWidth, 0, wHeight -1, 1);
glMatrixMode(GL_MODELVIEW);
}
Note that the opengl default window origin is the lower left corner.
Oups, you are right, you need to remove, the line with the glPushMatrix call. That worked in one my programs because it is not the entire code. Otherwise you should have a GL_STACK_OVERFLOW error.