sunwengang blog

developer | android display/graphics

  1. 1. 安装
  2. 2. 测试
    1. 2.1. 测试C代码
    2. 2.2. 编译
    3. 2.3. 测试C++代码
    4. 2.4. 编译

安装

1
2
3
4
sudo apt-get install build-essential
sudo apt-get install libgl1-mesa-dev
sudo apt-get install libglu1-mesa-dev
sudo apt-get install freeglut3-dev

安装完成后,库文件:

1
2
3
4
5
6
7
8
9
wizzie@wizzie:/usr/lib/x86_64-linux-gnu|
⇒ ls -tl lib[gG][lL]*.so
lrwxrwxrwx 1 root root 22 5月 10 20:17 libGLdispatch.so -> libGLdispatch.so.0.0.0
lrwxrwxrwx 1 root root 15 5月 10 20:17 libGLX.so -> libGLX.so.0.0.0
lrwxrwxrwx 1 root root 17 2月 14 2019 libGLESv1_CM.so -> libGLESv1_CM.so.1
lrwxrwxrwx 1 root root 14 2月 14 2019 libGLESv2.so -> libGLESv2.so.2
lrwxrwxrwx 1 root root 10 2月 14 2019 libGL.so -> libGL.so.1
lrwxrwxrwx 1 root root 16 8月 24 2016 libglut.so -> libglut.so.3.9.0
lrwxrwxrwx 1 root root 15 5月 22 2016 libGLU.so -> libGLU.so.1.3.1

测试

测试C代码

test.c
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
#include <GL/glut.h>


void init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glOrtho(-5, 5, -5, 5, 5, 15);
glMatrixMode(GL_MODELVIEW);
gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0);

return;
}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 0, 0);
glutWireTeapot(3);
glFlush();

return;
}

int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(0, 0);
glutInitWindowSize(300, 300);
glutCreateWindow("OpenGL 3D View");
init();
glutDisplayFunc(display);
glutMainLoop();

return 0;
}

编译

1
2
$ gcc -o test test.c -lGL -lGLU -lglut
$ ./test

编译结束后执行,会出现一个红色的小茶壶,表示配置完成。

测试C++代码

test1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// File Name: example.cpp                                                  
#include <GL/glut.h>

void draw()
{
glClearColor(1, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(100, 100);
glutInitWindowSize(300, 300);
glutCreateWindow("My First OpenGL Program");
glutDisplayFunc(draw);
glutMainLoop();
return 0;
}

编译

1
2
gcc -o test1 test1.cpp -lGL -lGLU -lglut
./test1

编译结束后执行,会出现一个红色的窗口,表示配置完成。

本文作者 : sunwengang
本文使用 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 协议
本文链接 : https://alonealive.github.io/Blog/2019/08/20/2019/190820_opengl_setup/

本文最后更新于 天前,文中所描述的信息可能已发生改变