How do you get the dimensions of the viewport

Started by
5 comments, last by try_catch_this 20 years ago
I am just looking for a way to calculatewhat will be on the screen and what will not. I use this to resize

bool MainWindow::Reshape( long width, long height )
{
   if( height == 0 ) // Prevent A Divide By Zero By

      height=1;
   ::glViewport( 0, 0, (GLsizei)(width), (GLsizei)(height) );
   ::glMatrixMode( GL_PROJECTION );
   ::glLoadIdentity();                                          // Reset The Projection Matrix

   ::gluPerspective( 45.0f, (GLfloat)(width)/(GLfloat)(height), // Calculate The Aspect Ratio Of The Window

					 0.010f, 1000.0f);
   ::glMatrixMode( GL_MODELVIEW );                              // Select The Modelview Matrix

   ::glLoadIdentity();
   SetPlayingAreaRect();
   SetInitialPaddlePositions();
   return false;
}
I would like to be able to make the playing area a percentage of the visable area but I dont know how to calculate it, I just go by trial and error. ::gluPerspective( 45.0f, (GLfloat)(width)/(GLfloat)(height), // Calculate The Aspect Ratio Of The Window 0.010f, 1000.0f); If I draw something at z = -40 I would like to know what are the limits of visability based on this calll to gluPerspective. thanks gdipong oglpong
Advertisement
Same as with any other piece of state information you want from OpenGL, you use glGet*().

[edited by - Fruny on April 21, 2004 10:21:20 PM]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
GLdouble viewport[4];
::glGetDoublev( GL_VIEWPORT, viewport );

When I used this viewport gave me { 0, 0, 1280, 1024 }
the window size was 1280, 1024.

I want the GL coordinates of the viewport at a given value of z.

I think that that gave me the with and hight of the viewport in pixels at 0.

If I do this

glTranslatef( 10, -10, -40 )

I want to know if at that value of z x = -10 is on the screen or not without trial and error.
Check the coordinates returned by gluUnproject against those of the viewport.

Edit - I basically did answer to the question in the topic. glGet returns the coordinates of the viewport, i.e. what you passed to glViewport. Sorry about that

[edited by - Fruny on April 21, 2004 10:55:25 PM]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Actually I dont think its the viewport that I am trying to get.

I am not sure what you call it.

But from what I understand the farther you draw things away from z = 0 the more room you have to draw.

That is what I am trying to calculate.
...
What you are after is a frustum check. There''s plenty of threads and resources regarding this topic - google it.

James

This topic is closed to new replies.

Advertisement