Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //http://www.youtube.com/user/thecplusplusguy
- //Thanks for the typed in code to Tapit85
- #include <SDL/SDL.h>
- #include <GL/gl.h>
- #include <GL/glu.h>
- //-lGL -lGLU
- //opengl32
- //glu32
- float angle = 0.0;
- const int triangle = 1;
- void init()
- {
- glClearColor(1.0,0.0,0.0,1.0); //background color and alpha
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(45,640.0/480.0,1.0,500.0);
- // glOrtho(...?);
- glMatrixMode(GL_MODELVIEW);
- // glShadeModel(GL_FLAT); // no color interpolation
- // glShadeModel(GL_SMOOTH); // color interpolation (default)
- // glColor3f(0.0,1.0,0.0);
- glNewList(triangle, GL_COMPILE);
- glBegin(GL_TRIANGLES);
- glColor3f(1.0,0.0,0.0);
- glVertex3f(0.0,2.0,0.0);
- glColor3f(0.0,1.0,0.0);
- glVertex3f(-2.0,-2.0,0.0);
- glColor3f(0.0,0.0,1.0);
- glVertex3f(2.0,-2.0,0.0);
- glEnd();
- glEndList();
- }
- void display()
- {
- glClear(GL_COLOR_BUFFER_BIT);
- glLoadIdentity();
- glTranslatef(0.0,0.0,-5.0);
- glRotatef(angle,0.0,1.0,0.0); // angle, x-axis, y-axis, z-axis
- glCallList(triangle);
- }
- int main(int argc, char** argv)
- {
- SDL_Init(SDL_INIT_EVERYTHING);
- SDL_Surface *screen;
- screen = SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE|SDL_OPENGL);
- // screen = SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE|SDL_FULLSCREEN);
- bool running = true;
- const int FPS = 30;
- Uint32 start;
- SDL_Event event;
- init();
- while(running) {
- start = SDL_GetTicks();
- while(SDL_PollEvent(&event)) {
- switch(event.type) {
- case SDL_QUIT:
- running = false;
- break;
- }
- }
- display();
- SDL_GL_SwapBuffers();
- angle += 0.5;
- if(1000/FPS > SDL_GetTicks()-start)
- SDL_Delay(1000/FPS-(SDL_GetTicks()-start));
- }
- SDL_Quit();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement