1. 环境搭建
a.安装opengl的库
cong@msi:~$ sudo apt-get install mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev
cong@msi:~$ sudo apt-get install freeglut3-dev
b. 查看
-
a.查看libgl库及头文件
-
cong@msi:~$ ls /usr/lib/libGL*
-
ls: cannot access /usr/lib/libGL*: No such file or directory
-
cong@msi:~$ ls /usr/lib/x86_64-linux-gnu/libGL*
-
/usr/lib/x86_64-linux-gnu/libGLEWmx.so.1.10 /usr/lib/x86_64-linux-gnu/libGLEW.so.1.10.0 /usr/lib/x86_64-linux-gnu/libGLU.so
-
/usr/lib/x86_64-linux-gnu/libGLEWmx.so.1.10.0 /usr/lib/x86_64-linux-gnu/libGL.so /usr/lib/x86_64-linux-gnu/libGLU.so.1
-
/usr/lib/x86_64-linux-gnu/libGLEW.so.1.10 /usr/lib/x86_64-linux-gnu/libGLU.a /usr/lib/x86_64-linux-gnu/libGLU.so.1.3.1
-
-
cong@msi:~$ ls /usr/include/GL/{gl,glu}.h
-
/usr/include/GL/gl.h /usr/include/GL/glu.h
-
-
-
b. 查看glut库及头文件
-
cong@msi:~$ ls /usr/lib/libglut*
-
ls: cannot access /usr/lib/libglut*: No such file or directory
-
cong@msi:~$ ls /usr/lib/x86_64-linux-gnu/libglut*
-
/usr/lib/x86_64-linux-gnu/libglut.a /usr/lib/x86_64-linux-gnu/libglut.so /usr/lib/x86_64-linux-gnu/libglut.so.3 /usr/lib/x86_64-linux-gnu/libglut.so.3.9.0
-
-
cong@msi:~$ ls /usr/include/GL/glut.h
-
/usr/include/GL/glut.h
c.opengl版本查看
-
cong@msi:~$ sudo apt-get install mesa-utils
-
cong@msi:~$ glxinfo | grep "OpenGL"
-
OpenGL vendor string: Intel Open Source Technology Center
-
OpenGL renderer string: Mesa DRI Intel(R) Haswell Desktop
-
OpenGL core profile version string: 3.3 (Core Profile) Mesa 10.1.3
-
OpenGL core profile shading language version string: 3.30
-
OpenGL core profile context flags: (none)
-
OpenGL core profile profile mask: core profile
-
OpenGL core profile extensions:
-
OpenGL version string: 3.0 Mesa 10.1.3 -->opengl version
-
OpenGL shading language version string: 1.30 -->shader version
-
OpenGL context flags: (none)
-
OpenGL extensions:
2.测试demo
2.1 hello.c
-
#include <GL/glut.h>
-
void display()
-
{
-
glClear(GL_COLOR_BUFFER_BIT); //现在还不太了解这个,暂时理解为默认的颜色是黑色,用黑色刷新一下窗口
-
glRectf(-0.5f,-0.5f, 0.5f, 0.5f); //画一个矩形,opengl的坐标范围(-1,1),坐标原点在窗口的中心
-
glFlush(); //立即刷新到窗口上
-
}
-
int main(int argc, char* argv[])
-
{
-
glutInit(&argc, argv); //对GLUT进行初始化
-
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE); //设置显示方式,GLUT_RGB-->使用RGB颜色,GLUT_SINGLE-->使用单缓冲
-
glutInitWindowPosition(0, 0); //设置窗口在屏幕中的位置
-
glutInitWindowSize(300, 300); //设置窗口的大小
-
glutCreateWindow("OpenGL 3D View"); //创建窗口,其中的参数是标题
-
glutDisplayFunc(display); //设置刷新窗口的回调函数
-
glutMainLoop(); //现在还不太了解这个,暂时理解为sleep(100)
-
return 0;
-
}
2.2 Makefile
-
EXE=hello
-
CC=gcc
-
SRC=$(wildcard *.c)
-
#OBJ=$(SRC:.c=.o)
-
OBJ=$(patsubst %.c,%.o,$(SRC))
-
DEP=$(patsubst %.c,.%.d,$(SRC))
-
CFLAGS=-g -O0
-
LDFLAGS=-lGL -lGLU -lglut
-
$(EXE):$(OBJ)
-
$(CC) $^ -o $@ $(LDFLAGS)
-
-
$(DEP):.%.d:%.c
-
@set -e; rm -f $@; \
-
$(CC) -MM $< > $@.$$$$; \
-
sed 's,/($*/)/.o[ :]*,/1.o $@ : ,g' < $@.$$$$ > $@; \
-
rm -f $@.$$$$
-
-
-include $(DEP)
-
clean:
-
@rm $(EXE) $(OBJ) $(DEP) -f
2.3 运行结果
是一个矩形
2.4 下载
1hello.rar(下载后改名为1hello.tar.gz)
参考文章:
Building OpenGL/GLUT Programs
~sugih/courses/eecs487/glut-howto/
OpenGl env setup ubuntu14.04
OpenGL入门学习
http://www.cnblogs.com/crazyxiaom/articles/2073586.html
阅读(1745) | 评论(0) | 转发(0) |