8 #include <luabind/luabind.hpp>
9 #include <luabind/class.hpp>
10 #include <luabind/function.hpp>
11 #include <luabind/functor.hpp>
18 struct glut_constants
{};
19 struct gl_constants
{};
21 namespace glut_bindings
23 luabind::functor
<void> displayfunc
;
25 void displayfunc_callback()
30 void set_displayfunc(const luabind::functor
<void>& fun
)
32 glutDisplayFunc(&displayfunc_callback
);
36 luabind::functor
<void> idlefunc
;
38 void idlefunc_callback()
43 void set_idlefunc(const luabind::functor
<void>& fun
)
45 glutIdleFunc(&idlefunc_callback
);
50 luabind::functor
<void> reshapefunc
;
52 void reshapefunc_callback(int w
, int h
)
57 void set_reshapefunc(const luabind::functor
<void>& 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
);
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
)
88 void bind_glut(lua_State
* L
)
90 using namespace luabind
;
91 using namespace glut_bindings
;
97 def("glutInitWindowSize", &glutInitWindowSize
),
98 def("glutInitWindowPosition", &glutInitWindowPosition
),
99 def("glutInitDisplayMode", &glutInitDisplayMode
),
101 class_
<glut_constants
>("glut")
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
),
136 class_
<gl_constants
>("gl")
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
),
162 def("gluPerspective", &gluPerspective
)
168 lua_State
* L
= lua_open();
177 glutInit (&argc
, argv
);
179 lua_dofile(L
, "glut_bindings.lua");