Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4584956
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:25:40+00:00 2026-05-21T21:25:40+00:00

I have a 3d scene drawn by OpenGL to a resizeable window. Now, when

  • 0

I have a 3d scene drawn by OpenGL to a resizeable window. Now, when the window gets resized, I do not want to scale the viewport, rather I want to keep the scene at a fixed size and show a larger portion of it (or crop the scene image). This is my current code:

GLfloat ratio;

// Protect against a divide by zero
if ( height == 0 )
    height = 1;

ratio = ( GLfloat )width / ( GLfloat )height;
// Setup our viewport.
glViewport( 0, 0, ( GLint )width, ( GLint )height );

// change to the projection matrix and set our viewing volume.
glMatrixMode( GL_PROJECTION );
glLoadIdentity( );

gluPerspective( 60.0f, ratio, 0.1f, 1000.0f );
// Switch back to the modelview
glMatrixMode( GL_MODELVIEW );

If I keep the ratio fixed, then the scene image simply gets scaled, but I want to keep it at fixed size and simply show a wider view. Any ideas on this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T21:25:41+00:00Added an answer on May 21, 2026 at 9:25 pm

    Adjust the fov parameters. Technically what you want to do is easier if done using glFrustum instead of gluPerspective.

    // Protect against a divide by zero
    if ( height == 0 )
        height = 1;
    
    // Setup our viewport.
    glViewport( 0, 0, ( GLint )width, ( GLint )height );
    
    // change to the projection matrix and set our viewing volume.
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity( );
    
    // supply some sensefull value for this; ideally let the user adjust it somehow
    exterm float Zoom;
    
    // near far should tightly wrap the actually visible set of objects. Hardcoded values
    // like 0.1 ... 1000.f are problematic. Also your choosen value range slices your viewport
    // into 10000 depth slices. Say you get only a 16 bit depth buffer already in the lineary
    // slicing ortho projection a OpenGL length units in depth would recieve only about 6 
    // slices. In perspective mode the slice density follows a 1/depth law. So already at depth
    // 10 you'll run into depth resolution problems.
    glFrustum(-Zoom * width, Zoom * width, -Zoom * height, Zoom * height, near, far);
    
    // Switch back to the modelview
    glMatrixMode( GL_MODELVIEW );
    

    Take note that this code belongs into the display function. Any tutorial that sets viewport and projection in a window reshape handler is very bad style; don’t follow it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a 3D scene and I want to be able to zoom in
I have two canvas's in a Grid, full scene images that I want to
I have a program in which the user adds multiple objects to a scene.
I have an OpenGL program that works on all of my computers but one.
I have a problem with lighting in my OpenGL application. When one of the
I have a simple iPhone application which uses OpenGL ES (v1) to draw a
I am rendering an OpenGL scene that include some bitmap text. It is my
I have a simple particle effect in OpenGL using GL_POINTS. The following is called,
I'm working on getting a simple lighting right on my OpenGL ES iPhone scene.
I'm using OpenGL ES on Android to draw some shapes, so I have some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.