]> git.treefish.org Git - seamulator.git/commitdiff
Implemented correct reshaping
authorAlexander Schmidt <alex@treefish.org>
Fri, 15 Jul 2016 11:37:08 +0000 (13:37 +0200)
committerAlexander Schmidt <alex@treefish.org>
Fri, 15 Jul 2016 11:37:08 +0000 (13:37 +0200)
seamulator.cpp

index 572c154f256dcb4004a45abb5220f19b480a07e5..15b731bcaf68b211411d5e58b3c8c9ca299d99e7 100644 (file)
@@ -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();