View Full Version : 2d snake game - help needed to implement reshape method

10-26-2013, 02:52 AM
Hi all;

I've been working on a snake game in C++ using version 3.7 of glut. So far, I can draw the graphics to the screen, but I'm not very experienced with the glortho method and I'm assuming that this and the glviewport are the main culprits. This is the code I've used to set these properties in the reshape method. I want to maintain the size of the sprites with the reshape method applied, but for some reason - the projection is way in the top-left hand corner of my 640 * 480 window rather than filling the entire window. If anyone can give me any tips on how to remedy this, I will be forever grateful.

Thank you

void reshape(GLsizei w, GLsizei h)

if (h == 0) {
h = 1;
glViewport(0,0, w, h); // set viewport to entire window
glMatrixMode (GL_PROJECTION); // use projection matrix
glLoadIdentity(); // reset matrix
glOrtho(0.0f, w, h, 0.0f, 0.0f, 1.0f);
glMatrixMode (GL_MODELVIEW); // back to model viewglLoadIdentity();

Main method
glutInitWindowSize(640, 480);