View Full Version : Get OpenGL width/height view units

Herr Bohm

05-19-2006, 09:13 AM

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

xavirn

05-19-2006, 12:29 PM

RECT rect;

GetWindowRect(hwnd, &rect);

Jack Dingler

05-19-2006, 03:08 PM

double ViewPortParams[4];

glGetDoublev(GL_VIEWPORT, ViewPortParams);

Herr Bohm

05-19-2006, 05:11 PM

@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?

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

Overmind

05-21-2006, 06:17 AM

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.

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.