MFC resizing OpenGL
-
hey guys this is more of a MFC-question than OpenGL I guess, that's why I put it here. I integrated an OpenGL-control in my MFC-proggy, like from here: (http://www.codeguru.com/cpp/g-m/opengl/article.php/c5583) all works fine, except that "glViewport(0, 0, width, height);" makes no difference and I cannot get the correct aspect ratio for my OpenGL-viewport (Except my app is squared). When the app is resized I call the Resize-function of my opengl-class which looks like this
void COpenGL::Resize(int posx, int posy, int width, int height) { if (height==0) height=1; // prevent division by zero } this->SetWindowPos(&CWnd::wndBottom, posx, posy, width, height, NULL); glViewport(0,0,(GLsizei)width,( GLsizei)height); //<-- problem here glMatrixMode(GL_PROJECTION); glLoadIdentity (); gluPerspective(45.0f,(float)width/((float)height),0.1f,100.0f); glMatrixMode(GL_MODELVIEW); }
The first part resizes OpenGL-Control... works The second part should resize the viewport (camera/aspect-ratio)... those commands work fine in a console app using only glut. any idea? thx in advance zqueezy -
hey guys this is more of a MFC-question than OpenGL I guess, that's why I put it here. I integrated an OpenGL-control in my MFC-proggy, like from here: (http://www.codeguru.com/cpp/g-m/opengl/article.php/c5583) all works fine, except that "glViewport(0, 0, width, height);" makes no difference and I cannot get the correct aspect ratio for my OpenGL-viewport (Except my app is squared). When the app is resized I call the Resize-function of my opengl-class which looks like this
void COpenGL::Resize(int posx, int posy, int width, int height) { if (height==0) height=1; // prevent division by zero } this->SetWindowPos(&CWnd::wndBottom, posx, posy, width, height, NULL); glViewport(0,0,(GLsizei)width,( GLsizei)height); //<-- problem here glMatrixMode(GL_PROJECTION); glLoadIdentity (); gluPerspective(45.0f,(float)width/((float)height),0.1f,100.0f); glMatrixMode(GL_MODELVIEW); }
The first part resizes OpenGL-Control... works The second part should resize the viewport (camera/aspect-ratio)... those commands work fine in a console app using only glut. any idea? thx in advance zqueezy -
so guys, sorry for posting that early... the answer is: the definition has to be done before drawing not in resizing... donnu why, but that works fine... but thanx for this cool forum
Glad you found the solution. Come back and visit us again.
Best wishes, Hans
[CodeProject Forum Guidelines] [How To Ask A Question] [My Articles]