Results 1 to 6 of 6

Thread: Get OpenGL width/height view units

  1. #1
    Junior Member Newbie
    Join Date
    May 2006
    Posts
    13

    Get OpenGL width/height view units

    I would like to know how OpenGL calculates the view width and height in opengl units when i have an opengl window in a win32 app.
    I tried some calculations but they werent correct

  2. #2
    Junior Member Newbie
    Join Date
    May 2006
    Posts
    7

    Re: Get OpenGL width/height view units

    RECT rect;

    GetWindowRect(hwnd, &rect);

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2006
    Posts
    26

    Re: Get OpenGL width/height view units

    double ViewPortParams[4];
    glGetDoublev(GL_VIEWPORT, ViewPortParams);

  4. #4
    Junior Member Newbie
    Join Date
    May 2006
    Posts
    13

    Re: Get OpenGL width/height view units

    @xarvin
    I didnt ment the size of the win32 window but the size of the opengl window in opengl units, but thanks anyway.

    @Jack Dingler
    Thank you, ill try it with that.

    edit:
    With the code provided by Jack Dingler i get the size of the win32 window.
    I really need the size of the opengl window in opengl units.
    Example:
    win32 height is 480 and win32 width is 640.
    I have a zoom of -10.0f.
    How do i get the size of the opengl window?

  5. #5

    Re: Get OpenGL width/height view units

    there's no such things as opengl units.
    The size of the window (where opengl will draw) is, as Jack Dingler says, the size of the viewport.

    Those numbers will give you the size of the window where opengl will draw, and usually they correspond to the size of your application window.

    Take a look here:

    http://www.mevis.de/opengl/glViewport.html
    Virtual Reality: Insideo

  6. #6
    Senior Member OpenGL Pro
    Join Date
    May 2000
    Location
    Naarn, Austria
    Posts
    1,102

    Re: Get OpenGL width/height view units

    There is no direct way to get the size of what you call the "OpenGL window", because it is three-dimensional (most of the time it's a frustum).

    Most of the times it is a lot easier to just keep track of all transformations yourself. For example, you know the parameters you originally passed to gluPerspective and you know your current zoom, so you can calculate the size of the frustum yourself.

    If you really want a general solution, you have to do some matrix math:

    - Get the modelview and projection matrix (with glGetFloatv(GL_MODELVIEW_MATRIX or GL_PROJECTION_MATRIX); )
    - multiply them together (P * M)
    - invert the result
    - transform the vertices of the unit cube with the resulting matrix

    This will give you the vertices of the current view frustum. From this it should be easy to derive all sizes you want.

Similar Threads

  1. OpenGL ES - set the width, height, depth of an object in 3D
    By bluewonder in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-13-2013, 01:58 AM
  2. Finding screen width and height dynamically in OpenGL GLUT program
    By kindergartenbaby in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 07-23-2012, 06:31 PM
  3. How do I get the width and height of a texture
    By justin123 in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 11-28-2009, 09:21 PM
  4. glTexImage* with width/height == 0
    By Jens Scheddin in forum OpenGL: Advanced Coding
    Replies: 6
    Last Post: 03-01-2007, 03:26 AM
  5. S3TC, width has to be = height? Please help
    By Anatrax in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 06-27-2002, 02:43 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