1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
using namespace std;
void Display();
void Reshape(int w, int h);
GLvoid initGL()
{
glClearColor(1,0,0,1);
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);//a besoin des arguments de la digne de commande
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
glutInitWindowSize(400, 400);
glutInitWindowPosition(100, 50);
glutCreateWindow("view");
glutDisplayFunc(Display);
glutReshapeFunc(Reshape);
glutMainLoop();
}
void Display()
{
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);//matrice de modele de vue
glLoadIdentity();
glBegin(GL_TRIANGLES); // triangle
glVertex2i(0,1);
glVertex2i(-1,0);
glVertex2i(1,0);
glEnd();
glBegin(GL_QUADS); // carre
glVertex2d(2,-1);
glVertex2d(4,-1);
glVertex2d(4,1);
glVertex2d(2,1);
glEnd();
glutSwapBuffers();
}
void Reshape(int w, int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
float L;
float H;
if( w <= h)
{
H = (float)(10*h/w);
L = 10.0;
}
else
{
H = 10.0;
L = (float)(10*w/h);
}
gluOrtho2D(-L/2,L/2,-H/2,H/2);
} |
Partager