Advertisement
fayimora

Untitled

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