Jump to content
  • Advertisement
Sign in to follow this  
toogreat4u

Problem with Reshape calback

This topic is 3525 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to have my reshape callback preserve all aspects when the screen is being adjusted and I am having troubles. When resized I get all sorts of views/clipping views that I do not intend to get. Any help would be great.
#include <gl/glut.h>
#include <cmath>

// this is the initial gluOrtho2D area
GLdouble left = 0.0;
GLdouble right = 700.0;
GLdouble bottom = 0.0;
GLdouble top = 700.0;

void scene()
{
        // all these functions work correctly
	grass_area();
	sky_area();
	mountains();
	houses();
	trees();
	fox_hole();
	ug_hideout();
	tent();
}

void display()
{
	/* clear window */
	glClear(GL_COLOR_BUFFER_BIT);

	/* draw scene */
	scene();

	/* for single buffer us glFlush
	 * technically can use for double as well
	 * just pointless
	 */
	glutSwapBuffers();
}

// problem area here
void myreshape(GLsizei w, GLsizei h)
{
	/* adjust clipping window */
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	if(w <= h)
		gluOrtho2D(left,right, bottom * (GLfloat) h / (GLfloat) w, top * (GLfloat) h / (GLfloat) w);
	else
		gluOrtho2D(left * (GLfloat) w / (GLfloat) h, right * (GLfloat) w / (GLfloat) h, bottom, top);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	/* adjust viewport */
	glViewport(0,0,w,h);

	right = w;
	top = h;
}

void init()
{
	/* set clear color */
	glClearColor(0.0,0.0,0.0,1.0);
}

int main(int argc, char** argv)
{
	/* intialize mode and open a window in upper-left corner of
	 * screen
	 *
	 * window titles is name of program (arg[0])
	 */
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
	glutInitWindowSize(700,700);
	glutInitWindowPosition(0,0);
	glutCreateWindow("Game Title");
	glutDisplayFunc(display);
	glutReshapeFunc(myreshape);
	init();
	glutMainLoop();
}

I am thinking I am missing something easy but I cant figure it out.

Share this post


Link to post
Share on other sites
Advertisement
Ok I figured out what I was doing wrong even though its pretty much identical to the code above here is my solution:


void myreshape(GLsizei w, GLsizei h)
{
// adjust clipping window
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(w <= h)
{
gluOrtho2D(left, right, bottom * (GLfloat) h / (GLfloat) w, top * (GLfloat) h / (GLfloat) w);
}
else
{
gluOrtho2D(left * (GLfloat) w / (GLfloat) h, right * (GLfloat) w / (GLfloat) h, bottom , top);
}
glMatrixMode(GL_MODELVIEW);

// adjust viewport
glViewport(0, 0, w, h);

}


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!