From: Alexander Schmidt Date: Fri, 15 Jul 2016 11:37:08 +0000 (+0200) Subject: Implemented correct reshaping X-Git-Url: http://git.treefish.org/~alex/seamulator.git/commitdiff_plain/0fcdcce0bba803bdb7d3165a3884e4e0f50553bc?hp=e0522b705b9988ff07e42ab14689bd0b8c4745cb Implemented correct reshaping --- diff --git a/seamulator.cpp b/seamulator.cpp index 572c154..15b731b 100644 --- a/seamulator.cpp +++ b/seamulator.cpp @@ -11,18 +11,8 @@ const double LATTICE_UNIT = 1; SeaPtr sea; WaterSurfacePtr surface; -void setupView() +void glDisplayFunc() { - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(50, (GLfloat)300 / (GLfloat)300, 0, 1000); - gluLookAt(0,-10,10, 0,0,0, 0,1,0); -} - -void displayMe(void) -{ - setupView(); - glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -36,6 +26,15 @@ void displayMe(void) glutPostRedisplay(); } +void glReshapeFunc(int width, int height) +{ + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(50.0, ((float)width/(float)height), 0, 1000.0); + glViewport(0, 0, width, height); + gluLookAt(0,-10,10, 0,0,0, 0,1,0); +} + int main(int argc, char** argv) { std::srand(std::time(0)); @@ -51,7 +50,8 @@ int main(int argc, char** argv) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - glutDisplayFunc(displayMe); + glutDisplayFunc(glDisplayFunc); + glutReshapeFunc(glReshapeFunc); glutMainLoop();