Guest User

SDL draft app

a guest
May 1st, 2012
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include <SDL/SDL.h>
  2. #include <GL/glew.h>
  3. #include <GL/gl.h>
  4. #include <GL/glu.h>
  5. #include <wchar.h>
  6. #include <math.h>
  7.  
  8. static int scrWidth = 640;
  9. static int scrHeight = 480;
  10.  
  11. #undef main
  12.  
  13. int main(int argc, char** argv){
  14.     SDL_Init(SDL_INIT_VIDEO);
  15.    
  16.     SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
  17.     SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
  18.     SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
  19.     SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
  20.     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
  21.     SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 0);
  22.  
  23.     printf("test");
  24.  
  25.     if (SDL_SetVideoMode(scrWidth, scrHeight, 32, SDL_OPENGL) == 0){
  26.         fprintf(stderr, "couldn't set mode %dx%d!\n", 640, 480);
  27.         SDL_Quit();
  28.         return -1;
  29.     }
  30.     glewInit();
  31.    
  32.     SDL_ShowCursor(SDL_DISABLE);
  33.    
  34.     glClearColor(0.2, 0.2, 0.2, 0.2);
  35.     glClearDepth(1.0);
  36.    
  37.     glEnable(GL_DEPTH_TEST);
  38.    
  39.     bool running = true;
  40.     while (running){
  41.         SDL_Event event;
  42.         if (SDL_PollEvent(&event)){
  43.             switch(event.type){
  44.                 case SDL_QUIT:
  45.                     running = false;
  46.                     break;
  47.             };
  48.         }
  49.         timer.update();
  50.         Keyboard::update();
  51.        
  52.         glMatrixMode(GL_PROJECTION);
  53.         glLoadIdentity();
  54.         gluOrtho2D(-scrWidth/2.0f, scrWidth/2.0f, scrHeight/2.0f, -scrHeight/2.0f);
  55.    
  56.         glMatrixMode(GL_MODELVIEW);
  57.         glLoadIdentity();
  58.        
  59.         glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  60.            
  61.         glDisable(GL_DEPTH_TEST);
  62.        
  63.         glFlush();
  64.         SDL_GL_SwapBuffers();      
  65.     }  
  66.    
  67.     SDL_Quit();
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment