Main.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include <GL/freeglut.h>
  2. #include "CrystalJohan.h"
  3. #include <stdio.h>
  4. #include "vector.h"
  5. CrystalJohan* app;
  6. bool justMoved = false;
  7. int main(int argc, char* argv[])
  8. {
  9. app = new CrystalJohan();
  10. glutInit(&argc, argv);
  11. //Init window and glut display mode
  12. glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  13. glutInitWindowSize(800, 600);
  14. glutCreateWindow("Crystal Point");
  15. glutFullScreen();
  16. //glutPositionWindow((glutGet(GLUT_SCREEN_WIDTH) / 2) - (glutGet(GLUT_WINDOW_WIDTH) / 2), (glutGet(GLUT_SCREEN_HEIGHT) / 2) - (glutGet(GLUT_WINDOW_HEIGHT) / 2));
  17. app->init();
  18. glutDisplayFunc([]() { app->draw(); } );
  19. glutIdleFunc([]() { app->update(); } );
  20. glutReshapeFunc([](int w, int h) { app->width = w; app->height = h; glViewport(0, 0, w, h); });
  21. //Keyboard
  22. glutKeyboardFunc([](unsigned char c, int, int) { app->keyboardState.keys[c] = true; });
  23. glutKeyboardUpFunc([](unsigned char c, int, int) { app->keyboardState.keys[c] = false; });
  24. //Mouse
  25. // glutMouseFunc(mouse);
  26. glutPassiveMotionFunc([](int x, int y)
  27. {
  28. if (justMoved)
  29. {
  30. justMoved = false;
  31. return;
  32. }
  33. int dx = x - app->width / 2;
  34. int dy = y - app->height / 2;
  35. if ((dx != 0 || dy != 0) && abs(dx) < 400 && abs(dy) < 400)
  36. {
  37. app->mouseOffset = app->mouseOffset + Vec2f(dx,dy);
  38. glutWarpPointer(app->width / 2, app->height / 2);
  39. justMoved = true;
  40. }
  41. });
  42. glutMainLoop();
  43. return 0;
  44. }