Advertisement
thecplusplusguy

OpenGL tutorial 1,2

Jun 23rd, 2012
1,047
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. //http://www.youtube.com/user/thecplusplusguy
  2. //Thanks for the typed in code to Tapit85
  3. #include <SDL/SDL.h>
  4. #include <GL/gl.h>
  5. #include <GL/glu.h>
  6. //-lGL -lGLU
  7. //opengl32
  8. //glu32
  9.  
  10. void init()
  11. {
  12.     glClearColor(1.0,0.0,0.0,1.0);  //background color and alpha
  13.     glMatrixMode(GL_PROJECTION);
  14.     glLoadIdentity();
  15.     gluPerspective(45,640.0/480.0,1.0,500.0);
  16.     glMatrixMode(GL_MODELVIEW);
  17. //  glShadeModel(GL_FLAT);      // no color interpolation
  18. //  glShadeModel(GL_SMOOTH);    // color interpolation (default)
  19. //  glColor3f(0.0,1.0,0.0);
  20. }
  21.  
  22. void display()
  23. {
  24.     glClear(GL_COLOR_BUFFER_BIT);
  25.     glBegin(GL_TRIANGLES);
  26.         glColor3f(1.0,0.0,0.0);
  27.         glVertex3f(0.0,2.0,-5.0);
  28.         glColor3f(0.0,1.0,0.0);
  29.         glVertex3f(-2.0,-2.0,-5.0);
  30.         glColor3f(0.0,0.0,1.0);
  31.         glVertex3f(2.0,-2.0,-5.0);
  32.     glEnd();
  33. }
  34.  
  35. int main(int argc, char** argv)
  36. {
  37.     SDL_Init(SDL_INIT_EVERYTHING);
  38.     SDL_Surface *screen;
  39.     screen = SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE|SDL_OPENGL);
  40. //  screen = SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE|SDL_FULLSCREEN);
  41.     bool running = true;
  42.     const int FPS = 30;
  43.     Uint32 start;
  44.     SDL_Event event;
  45.     init();
  46.     while(running) {
  47.         start = SDL_GetTicks();
  48.         while(SDL_PollEvent(&event)) {
  49.             switch(event.type) {
  50.                 case SDL_QUIT:
  51.                     running = false;
  52.                     break;
  53.             }
  54.         }
  55.  
  56.         display();
  57.         SDL_GL_SwapBuffers();
  58.         if(1000/FPS > SDL_GetTicks()-start)
  59.             SDL_Delay(1000/FPS-(SDL_GetTicks()-start));
  60.     }
  61.     SDL_Quit();
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement