Advertisement
Saraphite

SDL window being slow.

Nov 21st, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5.  
  6. #include <GL/glew.h>
  7. #include <SDL.h>
  8.  
  9. #define GLM_FORCE_RADIANS //force glm to use radians //must do **before** including GLM headers
  10. //NOTE: GLSL uses radians, so will do the same, for consistency
  11.  
  12. #include <glm/glm.hpp> //include the main glm header
  13. #include <glm/gtc/matrix_transform.hpp> //include functions to ease the calculation of the view and projection matrices
  14. #include <glm/gtc/type_ptr.hpp> //include functionality for converting a matrix object into a float array for usage in OpenGL
  15.  
  16. using namespace std;
  17.  
  18. int main( int argc, char* args[] )
  19. {
  20.     SDL_Init(SDL_INIT_EVERYTHING);
  21.     cout << "SDL Initialised\n";
  22.     SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
  23.     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
  24.     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
  25.     cout << "Happy hats!" << endl;
  26.     SDL_Window* window = SDL_CreateWindow("OpenGL Tutorial Fun!", 100, 100, 800, 600, SDL_WINDOW_OPENGL);
  27.     cout << "SDL Window Created" << endl;
  28.     SDL_GLContext context = SDL_GL_CreateContext(window);
  29.     cout << "Context Created." << endl;
  30.  
  31.     glewExperimental = GL_TRUE;
  32.     glewInit();
  33.     GLuint vertexBuffer;
  34.     glGenBuffers(1, &vertexBuffer);
  35.     printf("Vertex Buffer Created", vertexBuffer);
  36.  
  37.  
  38.     SDL_Event windowEvent;
  39.     while(true){
  40.         if (SDL_PollEvent(&windowEvent)){
  41.             if(windowEvent.type == SDL_QUIT) break;
  42.             if(windowEvent.type == SDL_KEYUP && windowEvent.key.keysym.sym == SDLK_ESCAPE) break;
  43.         }
  44.  
  45.         SDL_GL_SwapWindow(window);
  46.     }
  47.  
  48.     SDL_GL_DeleteContext(context);
  49.     SDL_Quit();
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement