From Ohm

QGL Example

A simple animated rotating green triangle with OpenGL:

const double QGLWindow::fps=30.0; // animated frames per second

void QGLWindow::paintGL()
{
   // clear frame buffer
   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

   // setup perspective matrix
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   gluPerspective(90.0,1.0,0.1,10.0);

   // setup model-view matrix
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
   gluLookAt(0,0,0, 0,0,-1, 0,1,0);

   // define local rotated coordinate system
   static double angle=0.0; // rotation angle in degrees
   static const double omega=180.0; // rotation speed in degrees/s
   glTranslated(0.0,0.0,-2.0);
   glRotated(angle,0.0,1.0,0.0);

   // render triangles
   glBegin(GL_TRIANGLES);
      glColor3f(0.0f,0.75f,0.0f);
      glVertex3d(-0.5,-0.5,0.0);
      glVertex3d(0.5,-0.5,0.0);
      glVertex3d(0.0,0.5,0.0);
   glEnd();

   // angle delta equals time delta times omega
   double dt=1.0/fps;
   angle+=dt*omega;
}

Compare:

Retrieved from http://schorsch.efi.fh-nuernberg.de/roettger/index.php/MedicalVisualization/QGLExample

Page last modified on December 27, 2015, at 02:16 PM