Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //http://www.youtube.com/user/thecplusplusguy
- //use glPush/popMatrix with (old) OpenGL 1.1
- #include <iostream>
- #include <SDL/SDL.h>
- #include <GL/gl.h>
- #include <GL/glu.h>
- void init()
- {
- glClearColor(0,0,0,1);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(50,640.0/480.0,1,1000);
- glMatrixMode(GL_MODELVIEW);
- glEnable(GL_DEPTH_TEST);
- }
- void drawTriangle()
- {
- glBegin(GL_TRIANGLES);
- glVertex3f(-1.0,0.0,0.0);
- glVertex3f(1.0,0.0,0.0);
- glVertex3f(0.0,1.0,0.0);
- glEnd();
- }
- float angle=0.0;
- void display()
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glLoadIdentity();
- glPushMatrix();
- glTranslatef(-5.0,0.0,-14.0);
- drawTriangle();
- glPopMatrix();
- glPushMatrix();
- glTranslatef(0.0,0.0,-14.0);
- glRotatef(angle,0.0,1.0,0.0);
- drawTriangle();
- glPopMatrix();
- glPushMatrix();
- glTranslatef(5.0,0.0,-14.0);
- drawTriangle();
- glPopMatrix();
- angle+=1.0;
- if(angle>=360.0)
- angle-=360;
- }
- int main()
- {
- SDL_Init(SDL_INIT_EVERYTHING);
- SDL_SetVideoMode(640,480,32,SDL_OPENGL);
- Uint32 start;
- SDL_Event event;
- bool running=true;
- init();
- bool b=false;
- while(running)
- {
- start=SDL_GetTicks();
- while(SDL_PollEvent(&event))
- {
- switch(event.type)
- {
- case SDL_QUIT:
- running=false;
- break;
- case SDL_KEYDOWN:
- switch(event.key.keysym.sym)
- {
- case SDLK_ESCAPE:
- running=false;
- break;
- }
- break;
- }
- }
- display();
- SDL_GL_SwapBuffers();
- if(1000.0/30>SDL_GetTicks()-start)
- SDL_Delay(1000.0/30-(SDL_GetTicks()-start));
- }
- SDL_Quit();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement