-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathlispCallbacks.cpp
More file actions
216 lines (176 loc) · 6.86 KB
/
lispCallbacks.cpp
File metadata and controls
216 lines (176 loc) · 6.86 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#include "lispCallbacks.h"
#include "lispInterface.h"
#include "PraxisTexture.h"
#include "PraxisServer.h"
#include "PraxisLog.h"
#include "World.h"
#include "SingleWorldConfiguration.h"
#include <sstream>
extern s7_scheme * g_pLisp;
#include <glm/vec3.hpp> // glm::vec3
#include <glm/vec4.hpp> // glm::vec4
#include <glm/mat4x4.hpp> // glm::mat4
#include <glm/gtc/matrix_transform.hpp> // glm::translate, glm::rotate, glm::scale, glm::perspective
static int s7_type_tag_transform = 0;
static s7_pointer s7cbDrawLine(s7_scheme *sc, s7_pointer args)
{
float x1 = s7_number_to_real(sc, s7_list_ref(sc, args, 0));
float y1 = s7_number_to_real(sc, s7_list_ref(sc, args, 1));
float z1 = s7_number_to_real(sc, s7_list_ref(sc, args, 2));
float x2 = s7_number_to_real(sc, s7_list_ref(sc, args, 3));
float y2 = s7_number_to_real(sc, s7_list_ref(sc, args, 4));
float z2 = s7_number_to_real(sc, s7_list_ref(sc, args, 5));
glBegin(GL_LINES);
glVertex3f(x1,y1,z1);
glVertex3f(x2,y2,z2);
glEnd();
return(s7_make_integer(sc, 0));
}
// Old OpenGL, adequate for low poly
static s7_pointer s7cbGLBegin(s7_scheme * sc, s7_pointer args)
{
GLenum mode = s7_number_to_integer(sc, s7_list_ref(sc, args, 0));
glBegin(mode);
return s7_nil(sc);
}
static s7_pointer s7cbGLEnd(s7_scheme * sc, s7_pointer args)
{
glEnd();
return s7_nil(sc);
}
static s7_pointer s7cbGLVertex(s7_scheme * sc, s7_pointer args)
{
GLfloat x,y,z;
x = s7_number_to_real(sc, s7_list_ref(sc, args, 0));
y = s7_number_to_real(sc, s7_list_ref(sc, args, 1));
z = s7_number_to_real(sc, s7_list_ref(sc, args, 2));
glVertex3f(x,y,z);
return s7_nil(sc);
}
static s7_pointer s7cbGLColor(s7_scheme * sc, s7_pointer args)
{
GLubyte r,g,b,a;
r = s7_number_to_integer(sc, s7_list_ref(sc, args, 0));
g = s7_number_to_integer(sc, s7_list_ref(sc, args, 1));
b = s7_number_to_integer(sc, s7_list_ref(sc, args, 2));
a = s7_number_to_integer(sc, s7_list_ref(sc, args, 3));
glColor4ub(r,g,b,a);
return s7_nil(sc);
}
static s7_pointer s7cbGLNormal(s7_scheme * sc, s7_pointer args)
{
GLfloat x,y,z;
x = s7_number_to_real(sc, s7_list_ref(sc, args, 0));
y = s7_number_to_real(sc, s7_list_ref(sc, args, 1));
z = s7_number_to_real(sc, s7_list_ref(sc, args, 2));
glNormal3f(x,y,z);
return s7_nil(sc);
}
static s7_pointer s7cbGLTexCoord(s7_scheme * sc, s7_pointer args)
{
GLfloat s,t;
s = s7_number_to_real(sc, s7_list_ref(sc, args, 0));
t = s7_number_to_real(sc, s7_list_ref(sc, args, 1));
glTexCoord2f(s,t);
return s7_nil(sc);
}
static s7_pointer s7cbGLEnable(s7_scheme * sc, s7_pointer args)
{
GLenum cap = s7_number_to_integer(sc, s7_list_ref(sc, args, 0));
glEnable(cap);
return s7_nil(sc);
}
static s7_pointer s7cbGLDisable(s7_scheme * sc, s7_pointer args)
{
GLenum cap = s7_number_to_integer(sc, s7_list_ref(sc, args, 0));
glDisable(cap);
return s7_nil(sc);
}
static s7_pointer s7cbGLMatrixMode(s7_scheme * sc, s7_pointer args)
{
GLenum mode = s7_number_to_integer(sc, s7_list_ref(sc, args, 0));
glMatrixMode(mode);
return s7_nil(sc);
}
static s7_pointer s7cbGLPushMatrix(s7_scheme * sc, s7_pointer args)
{
glPushMatrix();
return s7_nil(sc);
}
static s7_pointer s7cbGLPopMatrix(s7_scheme * sc, s7_pointer args)
{
glPopMatrix();
return s7_nil(sc);
}
static s7_pointer s7cbGLTranslate(s7_scheme * sc, s7_pointer args)
{
GLfloat x,y,z;
x = s7_number_to_real(sc, s7_list_ref(sc, args, 0));
y = s7_number_to_real(sc, s7_list_ref(sc, args, 1));
z = s7_number_to_real(sc, s7_list_ref(sc, args, 2));
glTranslatef(x,y,z);
return s7_nil(sc);
}
static s7_pointer s7cbGLRotate(s7_scheme * sc, s7_pointer args)
{
GLfloat angle,x,y,z;
angle = s7_number_to_real(sc, s7_list_ref(sc, args, 0));
x = s7_number_to_real(sc, s7_list_ref(sc, args, 1));
y = s7_number_to_real(sc, s7_list_ref(sc, args, 2));
z = s7_number_to_real(sc, s7_list_ref(sc, args, 3));
glRotatef(angle, x,y,z);
return s7_nil(sc);
}
static s7_pointer s7cbGLScale(s7_scheme * sc, s7_pointer args)
{
GLfloat x,y,z;
x = s7_number_to_real(sc, s7_list_ref(sc, args, 0));
y = s7_number_to_real(sc, s7_list_ref(sc, args, 1));
z = s7_number_to_real(sc, s7_list_ref(sc, args, 2));
glScalef(x,y,z);
return s7_nil(sc);
}
static s7_pointer s7cbNewTransform(s7_scheme * sc, s7_pointer args)
{
return s7_make_object(sc, s7_type_tag_transform, (void *)0);
}
void lispInitCallbacks()
{
s7_type_tag_transform = s7_new_type("transform", NULL, NULL, NULL, NULL, NULL, NULL);
stringstream ss;
ss << "(define GL_PROJECTION " << GL_PROJECTION << ")\n";
ss << "(define GL_MODELVIEW " << GL_MODELVIEW << ")\n";
ss << "(define GL_TRIANGLES " << GL_TRIANGLES << ")\n";
ss << "(define GL_QUADS " << GL_QUADS << ")\n";
ss << "(define GL_LINES " << GL_LINES << ")\n";
ss << "(define GL_LIGHTING " << GL_LIGHTING << ")\n";
ss << "(define GL_LIGHT0 " << GL_LIGHT0 << ")\n";
ss << "(define GL_LIGHT1 " << GL_LIGHT1 << ")\n";
ss << "(define GL_TEXTURE_2D " << GL_TEXTURE_2D << ")\n";
ss << "(define GL_POLYGON_OFFSET_FILL " << GL_POLYGON_OFFSET_FILL << ")\n";
ss << "(define GL_LINEAR " << GL_LINEAR << ")\n";
ss << "(define GL_NEAREST " << GL_NEAREST << ")\n";
ss << "(define GL_CLAMP_TO_EDGE " << GL_CLAMP_TO_EDGE << ")\n";
ss << "(define GL_REPEAT " << GL_REPEAT << ")\n";
lispCall(ss.str());
s7_define_function(g_pLisp, "draw-line", s7cbDrawLine, 6, 0, false, "");
s7_define_function(g_pLisp, "glBegin", s7cbGLBegin, 1, 0, false, "");
s7_define_function(g_pLisp, "glEnd", s7cbGLEnd, 0, 0, false, "");
s7_define_function(g_pLisp, "glVertex", s7cbGLVertex, 3, 0, false, "");
s7_define_function(g_pLisp, "glColor", s7cbGLColor, 4, 0, false, "");
s7_define_function(g_pLisp, "glNormal", s7cbGLNormal, 3, 0, false, "");
s7_define_function(g_pLisp, "glTexCoord", s7cbGLTexCoord, 2, 0, false, "");
s7_define_function(g_pLisp, "glEnable", s7cbGLEnable, 1, 0, false, "");
s7_define_function(g_pLisp, "glDisable", s7cbGLDisable, 1, 0, false, "");
s7_define_function(g_pLisp, "glMatrixMode", s7cbGLMatrixMode, 1, 0, false, "");
s7_define_function(g_pLisp, "glPushMatrix", s7cbGLPushMatrix, 0, 0, false, "");
s7_define_function(g_pLisp, "glPopMatrix", s7cbGLPopMatrix, 0, 0, false, "");
s7_define_function(g_pLisp, "glTranslate", s7cbGLTranslate, 3, 0, false, "");
s7_define_function(g_pLisp, "glRotate", s7cbGLRotate, 3, 0, false, "");
s7_define_function(g_pLisp, "glScale", s7cbGLScale, 3, 0, false, "");
// Shader functions
// Uniforms
// FBO functions
// DrawArrays
// GLM
}