From 0fcdcce0bba803bdb7d3165a3884e4e0f50553bc Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Fri, 15 Jul 2016 13:37:08 +0200 Subject: [PATCH 1/1] Implemented correct reshaping --- seamulator.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) 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(); -- 2.39.5