Advertisement
Guest User

Untitled

a guest
Apr 24th, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1. #include "EngineOpenGL.h"
  2.  
  3. EngineOpenGL::EngineOpenGL(std::string title, unsigned int height, unsigned int width) {
  4.     this->title = title;
  5.     this->height = height;
  6.     this->width = width;
  7.     this->window = NULL;
  8.  
  9.     this->contextOpenGL = NULL;
  10.     this->sceneOpenGL = NULL;
  11. }
  12.  
  13. EngineOpenGL::~EngineOpenGL() {
  14.     SDL_GL_DeleteContext(contextOpenGL);
  15.     SDL_DestroyWindow(window);
  16.     SDL_Quit();
  17.     delete sceneOpenGL;
  18. }
  19.  
  20. void EngineOpenGL::initWindow() {
  21.     // SDL Initialisation
  22.     if (SDL_Init(SDL_INIT_VIDEO) < 0) {
  23.         throw new SDLInitVideoException();
  24.     }
  25.  
  26.     // OpenGL Version
  27.     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
  28.     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
  29.  
  30.     // Double Buffer
  31.     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
  32.     SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
  33.  
  34.     // Window creation
  35.     window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width,
  36.         height, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
  37.     if (window == NULL) {
  38.         throw new SDLCreateWindowException();
  39.     }
  40.  
  41.     // Add context OpenGL
  42.     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
  43.     contextOpenGL = SDL_GL_CreateContext(window);
  44.     if (contextOpenGL == NULL) {
  45.         throw new SDLCreateContextGLException();
  46.     }
  47. }
  48.  
  49. void EngineOpenGL::initGL() {
  50.     //Initialisation of GLEW
  51.     if (glewInit() != GLEW_OK) {
  52.         throw new GLEWInitException();
  53.     }
  54.     glEnable(GL_DEPTH_TEST);
  55. }
  56.  
  57. void EngineOpenGL::init() {
  58.     initWindow();
  59.     std::cout << "Window initialise..." << std::endl;
  60.     initGL();
  61.     std::cout << "Glew initialise..." << std::endl;
  62. }
  63.  
  64. void EngineOpenGL::start() {
  65.     sceneOpenGL = new SceneOpenGL(window);
  66.     sceneOpenGL->start();
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement