Advertisement

WM_SIZE and OpenGL

Started by March 18, 2000 10:57 PM
4 comments, last by acw83 24 years, 5 months ago
I am coding in Win32 with OpenGL. I am trying to adjust the viewport size as the window size is changed. It works EXCEPT when certain places are reached. When decreasing the width, eventually the image dissapears. When decreases teh height, the images aspect gets messed up. To see it download my executible at members.home.com/acw83/terraingen.exe Here is my code for case WM_SIZE:
oops, forgotthe code. oh well, take a look at the file and see if you can tell me what is wrong anywho. If I must post the code, let me know.

members.home.com/acw83/TerrainGen.exe
Advertisement
I downloaded it and see the problems you''ve described, but I think the code will be necessary in order to solve them. It looks to me as though it''s in the statements that determine the new length and width of the mesh, but I''d need to see those statements to determine anything more.

Or are you leaving the mesh alone and changing the frustum when you resize? I could see a miscalculation in that causing some problems too.
I am resizing the frustrum. Here is my code:

case WM_SIZE:

w = LOWORD(lParam);
h = HIWORD(lParam);

// Prevent a divide by zero.
if( h == 0 )
h = 1;

// Set viewport to window dimensions.
glViewport(0, 0, w, h);

// Reset coordinate system.
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

// Establish clipping volume.
fAspect = (GLfloat)(w / h);
gluPerspective(45.0f, fAspect, 0.0, 500.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
break;

Here''s your problem:

fAspect = (GLfloat)(w / h);

It should be:

fAspect = (GLfloat)w / (GLfloat)h;

If you do it your way you loose the fractional part as it is an integer division.
Great, it no longer disappears. However, a new problem has emerged. With the code above changed as stated in the previous post, when I resize the window, the image does not change dimensions to stay proportional to the nwe window. For example, when I resize vertically, the entire image is scaled down, but wouldn''t the image be strechted out really thin? Downlaod my program to see the problem. members.home.com/acw83/terraingen.exe

This topic is closed to new replies.

Advertisement