# And now a scale/coordinate question.

Title says it all!

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 people!

Hey there,

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

hmm, that doesnâ€™t sound right, do you do any other transformations (either projection or modelview)?

On the projection matrix, theres only the ortho2D, and gluPerspective:

``````
glMatrixMode( GL_PROJECTION );

gluOrtho2D( 0, globuiWidth, 0, globuiHeight );
gluPerspective( 45.0f, ( GLfloat )globuiWidth / ( GLfloat )globuiHeight, -1.0f, 1.0f );

``````

where globuiWidth is an unsigned integer for the window widthâ€¦

Ive also tried replacing gluPerspective with glFrustum, as such:

``````
glFrustum( 0, globuiWidth, globuiHeight, 0, -1, 1 );

``````

Just to clarify, these ^^ are the only transformations occuring. and ofc, only on the perspective matrix.

Cheers

You should not put gluPerspective after gluOrtho2D !
"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?

``````
glMatrixMode( GL_PROJECTION );

//gluOrtho2D( 0, globuiWidth, 0, globuiHeight );
gluOrtho2D( -1, 1, -1, 1 );

glMatrixMode( GL_MODELVIEW );
/* Now some niceities */
glDisable( GL_DEPTH_TEST );
glEnable( GL_TEXTURE_2D );

glClear( GL_COLOR_BUFFER_BIT );
glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );					/* Clear BG colour to black */
glClearDepth( 1.0 );									/* Enable clearing to the depth buffer too */

glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
glEnable( GL_BLEND );
glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA );

gluLookAt( 0, 0, 5, 0, 0, 0, 0, 10, 0 );
glFlush();

``````

Thanks people

Anyone?

Iâ€™ve asked my lecturer, but he just said hes going to sleep, at 1828â€¦ Yheaâ€¦

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();
// 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.

Thanks for the rep, but your code didnt seem to work - just gave me a black screenâ€¦

However, I decided to play some more with my gluLookAt function, and now it works!! change the eyez from 5 to 1

Thanks for the reps!!

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.