View Full Version : And now a scale/coordinate question.
12-05-2008, 08:12 PM
Title says it all! :D
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...
12-06-2008, 02:06 AM
for both :
http://www.opengl.org/wiki/index.php/Vie...3D_rendering.3F (http://www.opengl.org/wiki/index.php/Viewing_and_Transformations#How_do_I_draw_2D_contr ols_over_my_3D_rendering.3F)
12-06-2008, 05:38 AM
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
12-06-2008, 06:04 AM
hmm, that doesn't sound right, do you do any other transformations (either projection or modelview)?
12-06-2008, 07:25 AM
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 );
12-06-2008, 11:19 AM
Just to clarify, these ^^ are the only transformations occuring. and ofc, only on the perspective matrix.
12-06-2008, 12:58 PM
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.
12-09-2008, 11:10 AM
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 */
glShadeModel( GL_SMOOTH );
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 );
Thanks people :)
12-10-2008, 12:19 PM
I've asked my lecturer, but he just said hes going to sleep, at 1828... Yhea...
12-10-2008, 02:12 PM
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.
12-10-2008, 04:04 PM
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 :D
Thanks for the reps!! :)
12-11-2008, 03:23 AM
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.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.