Advertisement
Guest User

Untitled

a guest
Apr 24th, 2016
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #include "SceneOpenGl.h"
  2.  
  3. SceneOpenGL::SceneOpenGL(SDL_Window* window) {
  4.     if (window == NULL) {
  5.         throw new SceneOpenGLException();
  6.     }
  7.     // Engine
  8.     this->window = window;
  9.     // Tools
  10.     this->fps = new FPSCount();
  11.     this->input = new Input();
  12.     // Scene
  13.     this->run = false;
  14.  
  15.     int w, h;
  16.     SDL_GetWindowSize(window, &w, &h);
  17.     this->projection = glm::perspective(70.0, (double)(w/h), 1.0, 100.0);
  18.     this->modelview = glm::mat4(1.0);
  19. }
  20.  
  21.  
  22. SceneOpenGL::~SceneOpenGL()
  23. {
  24.     delete fps;
  25.     delete input;
  26. }
  27.  
  28. void SceneOpenGL::start() {
  29.     run = true;
  30.  
  31.     // Test en attendant ObjectGL.show() //
  32.     float vertices[] = { -0.5, -0.5,   0.0, 0.5,   0.5, -0.5 };
  33.     // /Test //
  34.  
  35.     while (run) {
  36.         // FPS flag
  37.         if (fps->flag()) {
  38.             std::cout << "FPS : " << fps->getFps() << std::endl;
  39.         }
  40.  
  41.         // Input check/actions
  42.         input->updateEvents();
  43.         if (input->isKeyPush(SDL_SCANCODE_ESCAPE)) {
  44.             run = false;
  45.         }
  46.  
  47.         // Cleaning last frame
  48.         glClear(GL_COLOR_BUFFER_BIT);
  49.  
  50.         // Test en attendant ObjectGL.show() //
  51.         glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertices);
  52.         glEnableVertexAttribArray(0);
  53.         glDrawArrays(GL_TRIANGLES, 0, 3);
  54.         glDisableVertexAttribArray(0);
  55.         // /Test //
  56.  
  57.         // FPS add frame
  58.         fps->addFrame();
  59.  
  60.         // Rendering
  61.         SDL_GL_SwapWindow(window);
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement