安装相应的库:
sudo apt-get install build-essential libgl1-mesa-dev
sudo apt-get install freeglut3-dev
sudo apt-get install libglew-dev libsdl2-dev libsdl2-image-dev libglm-dev libfreetype6-dev
实例:
#include "GL/glut.h"
void RenderScene(void)
{
// Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
void SetupRC(void)
{
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
}
void main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(200,100);
glutCreateWindow("Simple");
glutDisplayFunc(RenderScene);
SetupRC();
glutMainLoop();
}
MakeFile:
LIBDIR = -L/usr/X11R6/lib
CC = gcc
CFLAGS = $(COMPILERFLAGS)
LIBRARIES = -lX11 -lXi -lglut -lGL -lGLU -lm
simple :simple.o
$(CC) $(CFLAGS) -o $@ $(LIBDIR) $? $(LIBRARIES)
clean : rm -f *.o
运行效果: