How to resize a window properly
Hello
I have a problem - I can't move/resize an opengl window properly for screen to world coordinates conversion to work afterwards. All elements of the scene are drawn using screen-to-world conversion. After I resize the window the width and height change as they should but the scene stays at the same place [(0,0) coordinate remains at the exactly same place of the screen not "following" the top of the window]
I mean what must I reset during the resize for gluunproject to work as it should (and map window coordinates to opengl coordinates)
Here's the resize code:
procedure glResizeWnd(Sirina, Visina : Integer);
begin
..glViewport(0, 0, Sirina, Visina); // Set the viewport for the OpenGL window
..glMatrixMode(GL_PROJECTION); // Change Matrix Mode to Projection
..glLoadIdentity(); // Reset View
..gluPerspective(45.0, Sirina/Visina, 2.0, 100.0); // Do the perspective calculations. Last value = max clipping depth
..glMatrixMode(GL_MODELVIEW); // Return to the modelview matrix
..glLoadIdentity(); // Reset View
end;
function glPostaviProzParam(x, y, Sirina, Visina : integer) : Integer;
var flag : uint;
rez : bool;
begin
..Result := 0;
..flag := SWP_ASYNCWINDOWPOS or SWP_NOACTIVATE or SWP_NOOWNERZORDER;
..rez := SetWindowPos(gl_HWND, HWND_TOPMOST, x, y, Sirina, Visina, flag);
.....if (smallint(rez) = 0) then
.....begin
........Result := GetLastError;
.....end;
// Dohvati device context
..gl_HDC := GetDC(gl_HWND);
..if (gl_HDC = 0) then
..begin
....glUnistiProzor;
....Result := 3;
....Exit;
..end;
..glResizeWnd(Sirina, Visina);
end;
When I want to resize I call the second function which adjusts the window size/position via windows function setwindowpos and then calls glResizeWnd
Here is the code for screen coordinate mapping:
function GetOGLPos(X, Y: Integer): T3D_Point;
var
..viewport: array [1..4] of Integer;
..modelview: array [1..16] of Double;
..projection: array [1..16] of Double;
..winZ: Single;
begin
..glGetDoublev( GL_MODELVIEW_MATRIX, @modelview );
..glGetDoublev( GL_PROJECTION_MATRIX, @projection );
..glGetIntegerv( GL_VIEWPORT, @viewport );
..if( Y = 0 )then Y := 1;
..gluUnProject( X, viewport[4]-Y, 0.5,
..@modelview, @projection, @viewport, Result[1], Result[2], Result[3]);
end;
When I add the SWP_NOSIZE flag to setwindowpos function so it just moves the window - the top (0,0) is where it should be; at the top of the window. If I then call setwindowpos again with SWP_NOMOVE so it just sizes the window - the top drops and it's not at the top of the window...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement