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

RECT rect;

GetWindowRect(hwnd, &rect);

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

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.

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

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.