openGL/GLUT 简单的demo程序

ubuntu 安装 GLUT :

sudo apt-get install freeglut3*

main.c

#include "GL/freeglut.h"

void drawTriangle()
{
    glClearColor(0.4, 0.4, 0.4, 0.4);
    glClear(GL_COLOR_BUFFER_BIT);

    glBegin(GL_TRIANGLES);
	    glColor3f(1.0, 0.0, 0.0);    // Red
	    glVertex3f(0.0, 1.0, 0.0);

	    glColor3f(0.0, 1.0, 0.0);    // Green
	    glVertex3f(-1.0, -1.0, 0.0);

	    glColor3f(0.0, 0.0, 1.0);    // Blue
	    glVertex3f(1.0, -1.0, 0.0);
    glEnd();

    glFlush();
}

int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE);
    glutCreateWindow("OpenGL - Creating a triangle");
    glutDisplayFunc(drawTriangle);
    glutMainLoop();
    return 0;
}

编译命令:

gcc main.c -lglut -lOpenGL -o testGLUT

你可能感兴趣的:(openGL,Linux)