Advertisement
Guest User

Example.cpp

a guest
Dec 3rd, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #ifdef _WIN32
  2. #include <windows.h>
  3. #endif
  4. #include <gl/GL.h>
  5. #include <gl/GLU.h>
  6. #include "Example.h"
  7.  
  8. Example::Example()
  9. {
  10.     m_rotationAngle = 0.0f;
  11. }
  12.  
  13. bool Example::init()
  14. {
  15.     glEnable(GL_DEPTH_TEST);
  16.     glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
  17.  
  18.     //Return success
  19.     return true;
  20. }
  21.  
  22. void Example::prepare(float dt)
  23. {
  24.     const float SPEED = 15.0f;
  25.     m_rotationAngle += SPEED*dt;
  26.     if (m_rotationAngle > 360.0f)
  27.     {
  28.         m_rotationAngle -=360.f;
  29.     }
  30. }
  31.  
  32. void Example::render()
  33. {
  34.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  35.     glLoadIdentity();
  36.  
  37.     glRotatef(m_rotationAngle, 0.0f, 0.0f, 1.0f);
  38.  
  39.     glBegin(GL_TRIANGLES);
  40.         glColor3f(1.0f, 0.0f, 0.0f);
  41.         glVertex3f(-0.5f, -0.5f, -2.0f);
  42.         glColor3f(1.0f, 1.0f, 0.0f);
  43.         glVertex3f(0.5f, -0.5f, -2.0f);
  44.         glColor3f(0.0f, 0.0f, 1.0f);
  45.         glVertex3f(0.0f, 0.5f, -2.0f);
  46.     glEnd();
  47. }
  48.  
  49. void Example::shutdown()
  50. {
  51.     //Nothing here yet
  52. }
  53.  
  54. void Example::onResize(int width, int height)
  55. {
  56.     glViewport(0,0,width,height);
  57.  
  58.     glMatrixMode(GL_PROJECTION);
  59.     glLoadIdentity();
  60.  
  61.     gluPerspective(45.0f, float(width)/float(height), 1.0f, 100.0f);
  62.  
  63.     glMatrixMode(GL_MODELVIEW);
  64.     glLoadIdentity();
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement