• Advertisement

Archived

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

How do you get the dimensions of the viewport

This topic is 5056 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
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]

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

Share this post


Link to post
Share on other sites
What you are after is a frustum check. There''s plenty of threads and resources regarding this topic - google it.

James

Share this post


Link to post
Share on other sites

  • Advertisement