Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

lecarlson

gluOrtho2D().. please help

This topic is 5232 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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..

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
screen coordinates start in the upper left of the screen & x goes positive to the right & y goes positive downwards (don''t ask).

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!