Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SDL.h>
- #include <GL/gl.h>
- #include <GL/glu.h>
- #include <cstdlib>
- #include <iostream>
- #include <string>
- using namespace std;
- void Dessiner();
- int main(int argc, char *argv[])
- {
- char* name = "TerraCraft";
- SDL_Event event;
- int const WIDTH_SCREEN = 800, HEIGHT_SCREEN = 600;
- SDL_Init(SDL_INIT_VIDEO);
- atexit(SDL_Quit);
- SDL_Window *screen = SDL_CreateWindow(name, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_OPENGL);
- SDL_GLContext glcontext = SDL_GL_CreateContext(screen);
- bool continuer = true;
- while(continuer)
- {
- glMatrixMode( GL_PROJECTION );
- glLoadIdentity();
- gluPerspective(70,(double)640/480,1,1000);
- glEnable(GL_DEPTH_TEST);
- Dessiner();
- SDL_GL_SwapWindow(screen);
- SDL_WaitEvent(&event);
- switch(event.type)
- {
- case SDL_QUIT:
- continuer = false;
- }
- }
- SDL_Quit();
- return 0;
- }
- void Dessiner()
- {
- glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- glMatrixMode( GL_MODELVIEW );
- glLoadIdentity( );
- gluLookAt(3,4,2,0,0,0,0,0,1);
- glBegin(GL_QUADS);
- glColor3ub(255,0,0); //face rouge
- glVertex3d(1,1,1);
- glVertex3d(1,1,-1);
- glVertex3d(-1,1,-1);
- glVertex3d(-1,1,1);
- glColor3ub(0,255,0); //face verte
- glVertex3d(1,-1,1);
- glVertex3d(1,-1,-1);
- glVertex3d(1,1,-1);
- glVertex3d(1,1,1);
- glColor3ub(0,0,255); //face bleue
- glVertex3d(-1,-1,1);
- glVertex3d(-1,-1,-1);
- glVertex3d(1,-1,-1);
- glVertex3d(1,-1,1);
- glColor3ub(255,255,0); //face jaune
- glVertex3d(-1,1,1);
- glVertex3d(-1,1,-1);
- glVertex3d(-1,-1,-1);
- glVertex3d(-1,-1,1);
- glColor3ub(0,255,255); //face cyan
- glVertex3d(1,1,-1);
- glVertex3d(1,-1,-1);
- glVertex3d(-1,-1,-1);
- glVertex3d(-1,1,-1);
- glColor3ub(255,0,255); //face magenta
- glVertex3d(1,-1,1);
- glVertex3d(1,1,1);
- glVertex3d(-1,1,1);
- glVertex3d(-1,-1,1);
- glEnd();
- glFlush();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement