Advertisement
thecplusplusguy

OpenGL (SDL,C++) - tutorial 1

Oct 13th, 2012
3,713
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. //http://www.youtube.com/user/thecplusplusguy
  2. //OpenGL tutorial 1
  3. #include <iostream>
  4. #include <SDL/SDL.h>
  5. #include <GL/gl.h>
  6. #include <GL/glu.h>
  7.  
  8. void init()
  9. {
  10.     glClearColor(0.0,0.0,0.0,1.0);
  11.     glMatrixMode(GL_PROJECTION);
  12.     glLoadIdentity();
  13.     gluPerspective(45.0,640.0/480.0,1.0,500.0);
  14.     glMatrixMode(GL_MODELVIEW);
  15.     glLoadIdentity();
  16. }
  17.  
  18. void display()
  19. {
  20.     glClear(GL_COLOR_BUFFER_BIT);
  21.     glBegin(GL_TRIANGLES);
  22.         glVertex3f(0.0,2.0,-5.0);
  23.         glVertex3f(-2.0,-2.0,-5.0);
  24.         glVertex3f(2.0,-2.0,-5.0);
  25.     glEnd();
  26. }
  27.  
  28. int main(int main,char** argv)
  29. {
  30.     SDL_Init(SDL_INIT_EVERYTHING);
  31.     SDL_Surface* screen=SDL_SetVideoMode(640,480,32,SDL_SWSURFACE|SDL_OPENGL);
  32.     bool running=true;
  33.     Uint32 start;
  34.     SDL_Event event;
  35.     init();
  36.     while(running)
  37.     {
  38.         start=SDL_GetTicks();
  39.         while(SDL_PollEvent(&event))
  40.         {
  41.             switch(event.type)
  42.             {
  43.                 case SDL_QUIT:
  44.                     running=false;
  45.                     break;
  46.             }
  47.         }
  48.         display();
  49.         SDL_GL_SwapBuffers();
  50.         if(1000/30>(SDL_GetTicks()-start))
  51.             SDL_Delay(1000/30-(SDL_GetTicks()-start));
  52.     }
  53.     SDL_Quit();
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement