Archived

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

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

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 on other sites
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 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???
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);
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);
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);
glClear (GL_DEPTH_BUFFER_BIT);

if (loop==0)
{
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)
{
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 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 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 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 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 on other sites
screen coordinates start in the upper left of the screen & x goes positive to the right & y goes positive downwards (don''t ask).

Share on other sites
fine! mr. nice anonymous guy....

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

1. 1
2. 2
3. 3
Rutin
21
4. 4
frob
18
5. 5

• 33
• 13
• 10
• 10
• 12
• Forum Statistics

• Total Topics
632568
• Total Posts
3007119

×