And now a scale/coordinate question.

Title says it all! :smiley:

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!

for both :…3D_rendering.3F

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.


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.

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 );
        glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );					/* Clear BG colour to black */
        glClearDepth( 1.0 );									/* Enable clearing to the depth buffer too */
        glShadeModel( GL_SMOOTH );
	glEnable( GL_BLEND );
	gluLookAt( 0, 0, 5, 0, 0, 0, 0, 10, 0 );

Thanks people :slight_smile:


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)
	// set a 2D orthographic projection
        // x range: [0 wWidth]
        // y range: [0 wHeight]
	glOrtho(0, wWidth, 0, wHeight -1, 1);

Note that the opengl default window origin is the lower left corner.

Thanks for the rep, but your code didnt seem to work :frowning: - 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 :smiley:

Thanks for the reps!! :slight_smile:

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.