made it work with boost 1.32
[luabind.git] / examples / glut / glut_bind.cpp
blob955aa0a574435059c3fc4b73863cf91ea739b6b4
1 extern "C"
3 #include "lua.h"
4 #include "lauxlib.h"
5 #include "lualib.h"
8 #include <luabind/luabind.hpp>
9 #include <luabind/class.hpp>
10 #include <luabind/function.hpp>
11 #include <luabind/functor.hpp>
14 #include <GL/glut.h>
15 #include <GL/gl.h>
16 #include <GL/glu.h>
18 struct glut_constants {};
19 struct gl_constants {};
21 namespace glut_bindings
23 luabind::functor<void> displayfunc;
25 void displayfunc_callback()
27 displayfunc();
30 void set_displayfunc(const luabind::functor<void>& fun)
32 glutDisplayFunc(&displayfunc_callback);
33 displayfunc = fun;
36 luabind::functor<void> idlefunc;
38 void idlefunc_callback()
40 idlefunc();
43 void set_idlefunc(const luabind::functor<void>& fun)
45 glutIdleFunc(&idlefunc_callback);
46 idlefunc = fun;
50 luabind::functor<void> reshapefunc;
52 void reshapefunc_callback(int w, int h)
54 reshapefunc(w,h);
57 void set_reshapefunc(const luabind::functor<void>& fun)
59 reshapefunc = fun;
62 luabind::functor<void> keyboardfunc;
64 void keyboardfunc_callback(unsigned char key, int x, int y)
66 keyboardfunc(key,x,y);
69 void set_keyboardfunc(const luabind::functor<void>& fun)
71 glutKeyboardFunc(&keyboardfunc_callback);
72 keyboardfunc = fun;
75 luabind::functor<void> mousefunc;
77 void mousefunc_callback(int button, int state, int x, int y)
79 mousefunc(button, state, x, y);
82 void set_mousefunc(const luabind::functor<void>& fun)
84 mousefunc = fun;
88 void bind_glut(lua_State* L)
90 using namespace luabind;
91 using namespace glut_bindings;
93 open(L);
95 module(L)
97 def("glutInitWindowSize", &glutInitWindowSize),
98 def("glutInitWindowPosition", &glutInitWindowPosition),
99 def("glutInitDisplayMode", &glutInitDisplayMode),
101 class_<glut_constants>("glut")
102 .enum_("constants")
104 value("RGB", GLUT_RGB),
105 value("RGBA", GLUT_RGBA),
106 value("INDEX", GLUT_INDEX),
107 value("SINGLE", GLUT_SINGLE),
108 value("DOUBLE", GLUT_DOUBLE),
109 value("DEPTH", GLUT_DEPTH),
110 value("STENCIL", GLUT_STENCIL),
111 value("LEFT_BUTTON", GLUT_LEFT_BUTTON),
112 value("MIDDLE_BUTTON", GLUT_MIDDLE_BUTTON),
113 value("RIGHT_BUTTON", GLUT_RIGHT_BUTTON),
114 value("UP", GLUT_UP),
115 value("DOWN", GLUT_DOWN),
116 value("ELAPSED_TIME", GLUT_ELAPSED_TIME)
119 def("glutCreateWindow", &glutCreateWindow),
120 def("glutDestroyWindow", &glutDestroyWindow),
121 def("glutFullScreen", &glutFullScreen),
122 def("glutDisplayFunc", &set_displayfunc),
123 def("glutKeyboardFunc", &set_keyboardfunc),
124 def("glutReshapeFunc", &set_reshapefunc),
125 def("glutIdleFunc", &set_idlefunc),
126 def("glutMainLoop", &glutMainLoop),
127 def("glutSwapBuffers", &glutSwapBuffers),
128 def("glutGet", &glutGet),
129 def("glutSolidSphere", &glutSolidSphere),
130 def("glutWireSphere", &glutWireSphere),
131 def("glutWireTeapot", &glutWireTeapot),
132 def("glutSolidTeapot", &glutSolidTeapot),
134 // -- opengl
136 class_<gl_constants>("gl")
137 .enum_("constants")
139 value("COLOR_BUFFER_BIT", GL_COLOR_BUFFER_BIT),
140 value("DEPTH_BUFFER_BIT", GL_DEPTH_BUFFER_BIT),
141 value("TRIANGLES", GL_TRIANGLES),
142 value("MODELVIEW", GL_MODELVIEW),
143 value("PROJECTION", GL_PROJECTION)
146 def("glBegin", &glBegin),
147 def("glVertex3", &glVertex3f),
148 def("glEnd", &glEnd),
149 def("glClear", &glClear),
150 def("glPushMatrix", &glPushMatrix),
151 def("glPopMatrix", &glPopMatrix),
152 def("glRotate", &glRotatef),
153 def("glColor3", &glColor3f),
154 def("glColor4", &glColor4f),
155 def("glMatrixMode", &glMatrixMode),
156 def("glLoadIdentity", &glLoadIdentity),
157 def("glViewport", &glViewport),
158 def("glTranslate", &glTranslatef),
160 // -- glu
162 def("gluPerspective", &gluPerspective)
166 int main()
168 lua_State* L = lua_open();
169 lua_baselibopen(L);
170 lua_mathlibopen(L);
171 bind_glut(L);
173 int argc = 1;
174 char* argv[1];
175 argv[0] = "blabla";
177 glutInit (&argc, argv);
179 lua_dofile(L, "glut_bindings.lua");
181 lua_close(L);
182 return 0;