Hi guys, I'm a bit stumped. I've been following several online tutorials but havn't managed to find a fix for my problem.
I'm making a platform game, and when the window is resized everything needs to scale with it. At the moment everything scales, but proportionality is not kept.
I understand as it's only a 2d game I should be using GLOrtho instead of GLPerspective.
Here's my attempt:
void reshape(int width, int height){
if (height == 0) height = 1; //Prevents a divide by zero.
glViewport(0, 0, (GLsizei)width, (GLsizei)height); // Set our viewport to the size of our window
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45, (GLfloat)width / (GLfloat)height, 0.0, 100.0); // Set the Field of view angle (in degrees), the aspect ratio of our window, and the new and far planes
//gluOrtho2D(0, width, 0, height);
glMatrixMode(GL_MODELVIEW); // Switch back to the model view matrix, so that we can start drawing shapes correctly
}
This code is called by :
glutReshapeFunc(reshape);
In the main method.
I am using freeGlut and running linux, IDE is netbeans if any of these details are relevant.
Question
Sensayshun
Hi guys, I'm a bit stumped. I've been following several online tutorials but havn't managed to find a fix for my problem.
I'm making a platform game, and when the window is resized everything needs to scale with it. At the moment everything scales, but proportionality is not kept.
I understand as it's only a 2d game I should be using GLOrtho instead of GLPerspective.
Here's my attempt:
This code is called by :
glutReshapeFunc(reshape);
In the main method.
I am using freeGlut and running linux, IDE is netbeans if any of these details are relevant.
Thanks.
Link to comment
https://www.neowin.net/forum/topic/974220-opengl-window-resize/Share on other sites
1 answer to this question
Recommended Posts