Archived

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

How do you get the dimensions of the viewport

This topic is 4982 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

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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites