Multiple Viewports

Questions regarding game mechanics and graphic programming should go here.

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

Multiple Viewports

Postby taymo2020 » Mon Sep 05, 2005 4:47 pm

I'm having trouble with makeing muiltiple viewports in me OGL project. Heres the code:
Code: Select all
   while (!done)
   {
      for( int i = 0; i <= 1; i++)
      {
         if( i == 0)
         {
            glViewport(0, 0, 200, 400);       
            glMatrixMode(GL_PROJECTION);           
            glLoadIdentity();                     

            gluPerspective(52.0f,(GLfloat)200/(GLfloat)400,1.0f,1000.0f);

            glMatrixMode(GL_MODELVIEW);
         }
         if(i == 1)
         {
            glViewport(200, 0, 200, 400);       
            glMatrixMode(GL_PROJECTION);           
            glLoadIdentity();                     

            gluPerspective(52.0f,(GLfloat)200/(GLfloat)400,1.0f,1000.0f);

            glMatrixMode(GL_MODELVIEW); 
         }
         if( i == 1)
         {
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            glLoadIdentity();
            glClearColor(0.0,0.0,0.0,0.0);
         }
         if( i == 0)
         {
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            glLoadIdentity();
            glClearColor(1.0,0.0,1.0,0.0);
         }

      }

      SwapBuffers(hdc);   //display back buffer

      while (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
      {
         if (!GetMessage (&msg, NULL, 0, 0))
         {
            done = true;
            break;
         }

         TranslateMessage (&msg);
         DispatchMessage (&msg);
      }
   }

This is me message loop and im thinking one viewporet should be black and the other should be purpleish but they should be differnt. SO whats wrong with this?
taymo2020
 
Posts: 998
Joined: Mon Mar 07, 2005 5:39 pm
Location: On the pot..

Postby Animatronic » Tue Sep 06, 2005 10:04 am

Can't see anything wrong, whats happenning? is anything showing at all?. All I can think is that one of your viewport is out of the screen (maybe by 1px) which will (in directx at least) cause the render in that viewport to fail.
Animatronic
 
Posts: 90
Joined: Wed Jun 23, 2004 9:08 pm

Postby Alvaro » Tue Sep 06, 2005 1:51 pm

I am sorry I am not answering the OpenGL question (I haven't used it in a long time and I don't remember many details).

I have a comment on your code structure, though: Isn't this code
[syntax="cpp"] for( int i = 0; i <= 1; i++)
{
if( i == 0)
{
// Some code 1
}
if(i == 1)
{
// Some code 2
}
if( i == 1)
{
// Some code 3
}
if( i == 0)
{
// Some code 4
}

}
[/syntax]

just a complicated version of this

[syntax="cpp"] // Some code 1
// Some code 4
// Some code 2
// Some code 3
[/syntax]
?

Or am I missing anything?
User avatar
Alvaro
Moderator
 
Posts: 5185
Joined: Mon Sep 22, 2003 4:57 pm
Location: NY, USA

Postby Alvaro » Tue Sep 06, 2005 1:58 pm

Let me guess: you are just seeing all black.

if(I_am_right){
That's because glViewport just sets a coordinate change matrix; it doesn't describe a clipping area that drawing primitives aply to. So you are first painting everything purple, and then everything black, and then drawing it, as the coordinate settings don't matter much to glClearColor.
}
else{
Well, my OpenGL skills are a little rusty, as I said.
}
User avatar
Alvaro
Moderator
 
Posts: 5185
Joined: Mon Sep 22, 2003 4:57 pm
Location: NY, USA

Postby taymo2020 » Tue Sep 06, 2005 3:50 pm

Oh ya the code is kinda off casue I was tired when i was writing it. You are right Alvaro sow hat should I do?
taymo2020
 
Posts: 998
Joined: Mon Mar 07, 2005 5:39 pm
Location: On the pot..

Postby Samuel » Wed Sep 07, 2005 2:53 am

Animatronic wrote:Can't see anything wrong, whats happenning? is anything showing at all?. All I can think is that one of your viewport is out of the screen (maybe by 1px) which will (in directx at least) cause the render in that viewport to fail.


Im pretty sure thats not the problem.

Taymo, I think what you are doing is setting the first view port up at 0, 0 and then moving it to 200, 0 and changing the background to black. You can test my theory by making the 'second' viewport purple.
But apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, the fresh-water system, and public health, what have the Romans ever done for us?
User avatar
Samuel
 
Posts: 676
Joined: Wed Apr 06, 2005 7:43 pm
Location: Australia

Postby Animatronic » Wed Sep 07, 2005 9:27 am

But it could have been, if opengl worked like DX. It turns out that opengl dosent apply the viewport if you try to make a viewport bigger than the backbuffer. The problem here is that opengl dosen't seem to use the current viewprt when clearing the bb, it just clears the whole thing. So taymo2020 your viewports are setup right, you just have to start drawing something in them to see the effect.

@Alvaro: the glViewport call also sets up the scissor region (in my tests at least).
Animatronic
 
Posts: 90
Joined: Wed Jun 23, 2004 9:08 pm


Return to Games and Graphics

Who is online

Users browsing this forum: No registered users and 0 guests