-
Notifications
You must be signed in to change notification settings - Fork 2
/
opengl.js
71 lines (60 loc) · 1.54 KB
/
opengl.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
var GL11 = Java.type("org.lwjgl.opengl.GL11");
var script = registerScript({
name: 'boom',
version: '0.0.0',
authors: ['Shurpe']
});
script.registerModule({
name: 'box',
category: 'Fun',
description: ''
}, function (module) {
module.on('render3D', function() {
void init() {
glClearColor(0.1, 0.1, 0.4, 0.0);
glShadeModel(GL_SMOOTH);
}
// 绘图回调函数
void display() {
// 清除之前帧数据
glClear(GL_COLOR_BUFFER_BIT);
// 绘制三角形
glBegin(GL_TRIANGLES);
glColor3f(1, 0, 0);
glVertex3f(-1, -1, -5);
glColor3f(0, 1, 0);
glVertex3f(1, -1, -5);
glColor3f(0, 0, 1);
glVertex3f(0, 1, -5);
glEnd();
// 执行绘图命令
glFlush();
}
// 窗口大小变化回调函数
void reshape(int w, int h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, (GLfloat)w/(GLfloat)h, 0.1, 100000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc, const char * argv[]) {
// 初始化显示模式
glutInit(&argc, const_cast<char **>(argv));
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
// 初始化窗口
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
init();
glutReshapeFunc(reshape);
glutDisplayFunc(display);
// 开始主循环绘制
glutMainLoop();
return 0;
}
});
module.on('render2D', function() {
});
});