Advertisement

gluOrtho2D().. please help

Started by February 27, 2004 08:07 AM
8 comments, last by lecarlson 21 years ago
Hi, I''m using the multiple viewports tutorial for my code.. on the upper left corner the viewport uses the gluOrtho2d perspective but my square wont come out on screen.. this is the code I made for the quads glBegin(GL_QUADS); glVertex2i(0,0); glVertex2i(0,1); glVertex2i(1,1); glVertex2i(1,0); glEnd(); how do I do this.. please help..
Are you in the correct matrix mode (MODELVIEW)?
What is the current modelview matrix? Identity?
Do you have texturing enabled?
What is the orthographic projection? Same as in the tutorial or have you changed the parameters?

Enigma
Advertisement
I think so...
this is the code that I am using(down below inside the ===) which I had from the tutorial and modified it a bit.. I am assuming that from what you are saying the matrix mode of the first viewport (loop==0) is supposed to be the MODELVIEW???

That this:>>
if (loop==0)
{
glViewport (0, window_height/2, window_width/2,window_height/2);
glMatrixMode (GL_PROJECTION);>>>>>GL_MODELVIEW???
glLoadIdentity ();
gluOrtho2D(0, window_width/2, window_height/2, 0);
}


this one I really got from the tutorial code...


==========================================
void Draw (void)
{
::
::
::
if (loop==0)
{
glViewport (0, window_height/2, window_width/2,window_height/2);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D(0, window_width/2, window_height/2, 0);
}

if (loop==1)
{glViewport (window_width/2, window_height/2, window_width/2, window_height/2);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective( 45.0, (GLfloat)(width)/(GLfloat)(height), 0.1f, 500.0 );
}
::
::
if loop==2-3 are the same with if loop==1
::
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
glClear (GL_DEPTH_BUFFER_BIT);

if (loop==0)
{
glLoadIdentity();
glBegin(GL_TRIANGLES);
glColor3f(1.0f,1.0f,0.0f);
glVertex2i(0,0);
glVertex2i(0,0.5);
glVertex2i(0.5,0.5);
//glVertex2i(0.5,0);
glEnd();
}

if (loop==1)
{
glLoadIdentity();
glTranslatef(-1.5f,0.0f,-6.0f);
glRotatef(rtri,0.0f,1.0f,0.0f);

glBegin(GL_TRIANGLES);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(-1.0f,-1.0f, 1.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f( 1.0f,-1.0f, 1.0f);
glEnd();
}

if (loop==2)
{::same as loop 1::}
if (loop==3)
{::same as loop 1::}

glFlush ();
}
================================================

[edited by - lecarlson on February 27, 2004 11:06:59 AM]
No. Your matrices are correct. You should be in PROJECTION mode when setting up the projection matrix (ortho or perspective) and MODELVIEW when translating, scaling, e.t.c., which you are.

You problem is here:
 glVertex2i(0,0);glVertex2i(0,0.5);glVertex2i(0.5,0.5);//glVertex2i(0.5,0); 

glVertex2i takes integer arguments. 0.5 rounds down to 0 as an integer, so you are effectively calling:
 glVertex2i(0,0);glVertex2i(0,0);glVertex2i(0,0);//glVertex2i(0,0); 

This is why you''re not seeing anything. Use whole numbers, or glVertex2f(). You probably also want to use larger numbers since the orthographic projection spans from (0, 0) to (windowWidth/2, windowHeight/2) so (0, 0) to (0.5, 0.5) will be very small.

Enigma
ah yes.. I seem to have copied the old code... anyway I am using whole numbers... but since half of my resolution is 512X384 then the one unit of line is really not visible?
It should be visible, but will be very small. Try making it bigger and see if you can see it then. If that doesn''t work then post your full draw function. The problem doesn''t appear to be in the code you posted already. You don''t have backface culling enabled do you?

Enigma
Advertisement
alright!!.. thanks.. it worked already.. guess I was just tired hehe =).. but howcome that the origin of the cartesian plane is on the upper left corner of the viewport and not on the center..and the values are

(0,0)------> (+512)
| \
| \ this is how my triangle looks like at
| \ (0,0) (0,100), (100,100)
|----
(+384)


thanks for the help
screen coordinates start in the upper left of the screen & x goes positive to the right & y goes positive downwards (don''t ask).
fine! mr. nice anonymous guy....
quote:
Original post by lecarlson ...but howcome that the origin of the cartesian plane is on the upper left corner of the viewport and not on the center..


Because that''s what you specified with your gluOrtho2D call:
gluOrtho2d(left, right, bottom, top) 


Enigma

This topic is closed to new replies.

Advertisement