9 #include <luabind/luabind.hpp>
10 #include <luabind/class.hpp>
11 #include <luabind/function.hpp>
12 #include <luabind/functor.hpp>
19 struct glut_constants
{};
20 struct gl_constants
{};
22 namespace glut_bindings
24 luabind::functor
<void> displayfunc
;
26 void displayfunc_callback()
31 void set_displayfunc(const luabind::functor
<void>& fun
)
33 glutDisplayFunc(&displayfunc_callback
);
37 luabind::functor
<void> idlefunc
;
39 void idlefunc_callback()
44 void set_idlefunc(const luabind::functor
<void>& fun
)
46 glutIdleFunc(&idlefunc_callback
);
51 luabind::functor
<void> reshapefunc
;
53 void reshapefunc_callback(int w
, int h
)
58 void set_reshapefunc(const luabind::functor
<void>& fun
)
63 luabind::functor
<void> keyboardfunc
;
65 void keyboardfunc_callback(unsigned char key
, int x
, int y
)
67 keyboardfunc(key
,x
,y
);
70 void set_keyboardfunc(const luabind::functor
<void>& fun
)
72 glutKeyboardFunc(&keyboardfunc_callback
);
76 luabind::functor
<void> mousefunc
;
78 void mousefunc_callback(int button
, int state
, int x
, int y
)
80 mousefunc(button
, state
, x
, y
);
83 void set_mousefunc(const luabind::functor
<void>& fun
)
89 void bind_glut(lua_State
* L
)
91 using namespace luabind
;
92 using namespace glut_bindings
;
96 function(L
, "glutInitWindowSize", &glutInitWindowSize
);
97 function(L
, "glutInitWindowPosition", &glutInitWindowPosition
);
98 function(L
, "glutInitDisplayMode", &glutInitDisplayMode
);
100 class_
<glut_constants
>(L
, "glut")
103 value("RGB", GLUT_RGB
),
104 value("RGBA", GLUT_RGBA
),
105 value("INDEX", GLUT_INDEX
),
106 value("SINGLE", GLUT_SINGLE
),
107 value("DOUBLE", GLUT_DOUBLE
),
108 value("DEPTH", GLUT_DEPTH
),
109 value("STENCIL", GLUT_STENCIL
),
110 value("LEFT_BUTTON", GLUT_LEFT_BUTTON
),
111 value("MIDDLE_BUTTON", GLUT_MIDDLE_BUTTON
),
112 value("RIGHT_BUTTON", GLUT_RIGHT_BUTTON
),
113 value("UP", GLUT_UP
),
114 value("DOWN", GLUT_DOWN
),
115 value("ELAPSED_TIME", GLUT_ELAPSED_TIME
)
118 function(L
, "glutCreateWindow", &glutCreateWindow
);
119 function(L
, "glutDestroyWindow", &glutDestroyWindow
);
120 function(L
, "glutFullScreen", &glutFullScreen
);
121 function(L
, "glutDisplayFunc", &set_displayfunc
);
122 function(L
, "glutKeyboardFunc", &set_keyboardfunc
);
123 function(L
, "glutReshapeFunc", &set_reshapefunc
);
124 function(L
, "glutIdleFunc", &set_idlefunc
);
125 function(L
, "glutMainLoop", &glutMainLoop
);
126 function(L
, "glutSwapBuffers", &glutSwapBuffers
);
127 function(L
, "glutGet", &glutGet
);
128 function(L
, "glutSolidSphere", &glutSolidSphere
);
129 function(L
, "glutWireSphere", &glutWireSphere
);
130 function(L
, "glutWireTeapot", &glutWireTeapot
);
131 function(L
, "glutSolidTeapot", &glutSolidTeapot
);
135 class_
<gl_constants
>(L
, "gl")
138 value("COLOR_BUFFER_BIT", GL_COLOR_BUFFER_BIT
),
139 value("DEPTH_BUFFER_BIT", GL_DEPTH_BUFFER_BIT
),
140 value("TRIANGLES", GL_TRIANGLES
),
141 value("MODELVIEW", GL_MODELVIEW
),
142 value("PROJECTION", GL_PROJECTION
)
145 function(L
, "glBegin", &glBegin
);
146 function(L
, "glVertex3", &glVertex3f
);
147 function(L
, "glEnd", &glEnd
);
148 function(L
, "glClear", &glClear
);
149 function(L
, "glPushMatrix", &glPushMatrix
);
150 function(L
, "glPopMatrix", &glPopMatrix
);
151 function(L
, "glRotate", &glRotatef
);
152 function(L
, "glColor3", &glColor3f
);
153 function(L
, "glColor4", &glColor4f
);
154 function(L
, "glMatrixMode", &glMatrixMode
);
155 function(L
, "glLoadIdentity", &glLoadIdentity
);
156 function(L
, "glViewport", &glViewport
);
157 function(L
, "glTranslate", &glTranslatef
);
161 function(L
, "gluPerspective", &gluPerspective
);
166 lua_State
* L
= lua_open();
175 glutInit (&argc
, argv
);
177 lua_dofile(L
, "glut_bindings.lua");