Results 1 to 4 of 4

Thread: Do not resize the DrawArea

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2015
    Posts
    21

    Do not resize the image, just draw more

    Hello there,

    this is probably a stupid question, simple math, or something else, i am not sure.

    What i have is a window with a small 3D scene (thats just 2 models rendered) in opengl. It starts as a window in 1024x768, thats cool. Then i resize the window (maximize it), and my handler does on resizing the following:

    Code :
    void onResize(GLFWwindow* window, int width, int height){
    	//This is my projection-matrix which gets multiplicated with the model and viewmatrix, the usual stuff.
    	Projection = glm::perspective(45.0f, (float)width/(float)height, 0.1f, 100.0f);
    	glViewport(0, 0, width, height);
    }
    and it works great. Nothing stretched, everything in the correct resolution. But: It just draws everything bigger. So if i would resize my window from, lets say, 500x500 to 1000x1000 it would just draw it twice as big (in both dimensions), but what i would like to have is, that it does not draws it bigger, but just draws "more" of the scene around. You understand what i mean? So if you look through a hole in a piece of paper, and then just remove the paper, you don't see the exact same things bigger, but you see actually more around you.
    What i actually tried is, remove one of the both lines in the onResize function, but this does more harm then help.

    My guess is, that its just a matrix i have to set up correctly or a gl-call i have to do but i'm clueless since the glm:erspective does not take any size-arguments (just the aspect,ratio) and glViewport seems to just set up the screen-area i can draw in but has nothing to do with the actual drawing.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,103
    Quote Originally Posted by tkausl View Post
    what i would like to have is, that it does not draws it bigger, but just draws "more" of the scene around.
    IOW, you want a larger view angle.

    Quote Originally Posted by tkausl View Post
    the glm::perspective does not take any size-arguments (just the aspect,ratio)
    It takes an aspect ratio and a view angle.

    Quote Originally Posted by tkausl View Post
    and glViewport seems to just set up the screen-area i can draw in but has nothing to do with the actual drawing.
    glViewport() sets the portion of the window which is mapped to X and Y coordinates of the clip space. Enlarging the viewport while keeping all other factors (e.g. the projection matrix) constant will enlarge the rendered image).

    If you want a larger window to result in a larger view angle, you could just calculate the appropriate view angle and aspect ratio based upon the window dimensions, but it's probably easier to use glm::frustum() instead. glm::perspective() is effectively just a convenience wrapper; any glm::perspective() call can be translated to an equivalent glm::frustum() call, i.e.
    Code :
    double rf = tan(fovy/2);
    double dy = zNear * rf;
    double dx = aspect * dy;
    return glm::frustum(-dx,dx,-dy,dy,zNear,zFar);
    So rather than calculating dx and dy based upon fovy and aspect, you can just calculate them as e.g.
    Code :
    double dy = zNear * window_width / size;
    double dx = zNear * window_height / size;
    return glm::frustum(-dx,dx,-dy,dy,zNear,zFar);
    where size is the window size corresponding to a 90 view angle (45).

  3. #3
    Quote Originally Posted by GClements View Post
    Code :
    double rf = tan(fovy/2);
    double dy = zNear * rf;
    double dx = aspect * dy;
    return glm::frustum(-dx,dx,-dy,dy,zNear,zFar);
    So rather than calculating dx and dy based upon fovy and aspect, you can just calculate them as e.g.
    Code :
    double dy = zNear * window_width / size;
    double dx = zNear * window_height / size;
    return glm::frustum(-dx,dx,-dy,dy,zNear,zFar);
    where size is the window size corresponding to a 90 view angle (45).
    Can you clarify that the fovy means field of view on Y axis/plane and not the usually implied X axis/plane which is usually the case.

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,103
    Quote Originally Posted by EmJayJay View Post
    Can you clarify that the fovy means field of view on Y axis/plane
    Yes. fovy is the angle between the top and bottom edges of the view frustum (the angle between either edge and the centre is fovy/2).

Similar Threads

  1. how to resize FBO???
    By red112 in forum OpenGL ES
    Replies: 1
    Last Post: 02-01-2013, 08:59 AM
  2. Resize windo
    By Slookeur in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 07-25-2011, 05:25 AM
  3. Viewport resize and fit
    By alb84 in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 05-13-2010, 02:55 AM
  4. Is this possible - Draw & resize BB to RT
    By Johnnie in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 04-29-2010, 03:49 PM
  5. Resize Window\Resize Image
    By Cerv36 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-16-2003, 04:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean