gokernel
(usa Linux Mint)
Enviado em 06/10/2009 - 12:03h
Este é um exemplo retirado da documentação do glut("simple.c").
Lembrando que você pode substituir o glut pelo SDL para JANELAS.
Para compilar:
gcc -o simple simple.c -lglut -lGLU -lGL -lXmu -lXext -lX11 -lm
-----------------------------------------------------------------
#include <GL/glut.h>
void reshape(int w, int h) {
glViewport(0, 0, w, h); /* Establish viewing area to cover entire window. */
glMatrixMode(GL_PROJECTION); /* Start modifying the projection matrix. */
glLoadIdentity(); /* Reset project matrix. */
glOrtho(0, w, 0, h, -1, 1); /* Map abstract coords directly to window coords. */
glScalef(1, -1, 1); /* Invert Y axis so increasing Y goes down. */
glTranslatef(0, -h, 0); /* Shift origin up to upper-left corner. */
}
void display(void) {
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.0, 1.0); /* blue */
glVertex2i(0, 0);
glColor3f(0.0, 1.0, 0.0); /* green */
glVertex2i(200, 200);
glColor3f(1.0, 0.0, 0.0); /* red */
glVertex2i(20, 200);
glEnd();
glFlush(); /* Single buffered, so needs a flush. */
}
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutCreateWindow("single triangle");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}
-----------------------------------------------------------------