View Full Version : glutReshapeFunc
bagiles
04-02-2002, 07:52 AM
I have a small OpenGL program that displays a small square in a window. When I add the glutReshapeFunc to the program it crashes at the call to glutMainLoop.
nexusone
04-02-2002, 07:58 AM
You need to post the code, without seeing what you are doing we have no clue as to what is causing the crash.
Originally posted by bagiles:
I have a small OpenGL program that displays a small square in a window. When I add the glutReshapeFunc to the program it crashes at the call to glutMainLoop.
bagiles
04-02-2002, 08:07 AM
#include <gl\glut.h>
void RenderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f,0.0f,0.0f);
glRectf(100.0f,150.0f,150.0f,100.0f);
glFlush();
}
void SetupRC(void)
{
glClearColor(0.0f,0.0f,0.0f,1.0f);
}
void ChangeSize(GLsizei w, GLsizei h)
{
//prevent divide by zero
if(h==0)
h=1;
//set viewport to window dimensions
glViewport(0,0,w,h);
//Reset corrdinate system
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//Establish clipping volume (left,right,bottom,near,far)
if(w<=h)
glOrtho(0.0f,250.0f,0.0f,250.0f*h/w,1.0f,-1.0f);
else
glOrtho(0.0f,250.0f*w/h,0.0f,250.0f,1.0f,-1.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(void)
{
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutCreateWindow("Simple");
glutDisplayFunc(RenderScene);
glutReshapeFunc(ChangeSize);
SetupRC();
glutMainLoop();
return 0;
}
BBrown
04-02-2002, 12:37 PM
Don't you have to size the window initially?
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(width,height);
glutCreateWindow("Simple");
glutDisplayFunc(RenderScene);
glutReshapeFunc(ChangeSize);
I think entering in the initial size might help. Otherwise you could get a divide by 0 on line :
glOrtho(0.0f,250.0f,0.0f,250.0f*h/w,1.0f,-1.0f);
because if w and h = 0 this line is run. Only the divide by 0 for h was taken care of with:
//prevent divide by zero
if(h==0)
h=1;
See if that works.
zeckensack
04-02-2002, 12:48 PM
What's that SetupRC thing? Throw it away, it's certainly not needed with glut and might interfere!
BBrown
04-02-2002, 12:52 PM
zeckensack,
SetupRC is ok. Thats how examples are done in the OpenGL Superbible. Shouldn't be a problem here.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.