Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "EngineOpenGL.h"
- EngineOpenGL::EngineOpenGL(std::string title, unsigned int height, unsigned int width) {
- this->title = title;
- this->height = height;
- this->width = width;
- this->window = NULL;
- this->contextOpenGL = NULL;
- this->sceneOpenGL = NULL;
- }
- EngineOpenGL::~EngineOpenGL() {
- SDL_GL_DeleteContext(contextOpenGL);
- SDL_DestroyWindow(window);
- SDL_Quit();
- delete sceneOpenGL;
- }
- void EngineOpenGL::initWindow() {
- // SDL Initialisation
- if (SDL_Init(SDL_INIT_VIDEO) < 0) {
- throw new SDLInitVideoException();
- }
- // OpenGL Version
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
- // Double Buffer
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
- SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
- // Window creation
- window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width,
- height, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
- if (window == NULL) {
- throw new SDLCreateWindowException();
- }
- // Add context OpenGL
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
- contextOpenGL = SDL_GL_CreateContext(window);
- if (contextOpenGL == NULL) {
- throw new SDLCreateContextGLException();
- }
- }
- void EngineOpenGL::initGL() {
- //Initialisation of GLEW
- if (glewInit() != GLEW_OK) {
- throw new GLEWInitException();
- }
- glEnable(GL_DEPTH_TEST);
- }
- void EngineOpenGL::init() {
- initWindow();
- std::cout << "Window initialise..." << std::endl;
- initGL();
- std::cout << "Glew initialise..." << std::endl;
- }
- void EngineOpenGL::start() {
- sceneOpenGL = new SceneOpenGL(window);
- sceneOpenGL->start();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement