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
;
95 function(L
, "glutInitWindowSize", &glutInitWindowSize
);
96 function(L
, "glutInitWindowPosition", &glutInitWindowPosition
);
97 function(L
, "glutInitDisplayMode", &glutInitDisplayMode
);
99 class_
<glut_constants
>(L
, "glut")
102 value("RGB", GLUT_RGB
),
103 value("RGBA", GLUT_RGBA
),
104 value("INDEX", GLUT_INDEX
),
105 value("SINGLE", GLUT_SINGLE
),
106 value("DOUBLE", GLUT_DOUBLE
),
107 value("DEPTH", GLUT_DEPTH
),
108 value("STENCIL", GLUT_STENCIL
),
109 value("LEFT_BUTTON", GLUT_LEFT_BUTTON
),
110 value("MIDDLE_BUTTON", GLUT_MIDDLE_BUTTON
),
111 value("RIGHT_BUTTON", GLUT_RIGHT_BUTTON
),
112 value("UP", GLUT_UP
),
113 value("DOWN", GLUT_DOWN
),
114 value("ELAPSED_TIME", GLUT_ELAPSED_TIME
)
117 function(L
, "glutCreateWindow", &glutCreateWindow
);
118 function(L
, "glutDestroyWindow", &glutDestroyWindow
);
119 function(L
, "glutFullScreen", &glutFullScreen
);
120 function(L
, "glutDisplayFunc", &set_displayfunc
);
121 function(L
, "glutKeyboardFunc", &set_keyboardfunc
);
122 function(L
, "glutReshapeFunc", &set_reshapefunc
);
123 function(L
, "glutIdleFunc", &set_idlefunc
);
124 function(L
, "glutMainLoop", &glutMainLoop
);
125 function(L
, "glutSwapBuffers", &glutSwapBuffers
);
126 function(L
, "glutGet", &glutGet
);
127 function(L
, "glutSolidSphere", &glutSolidSphere
);
128 function(L
, "glutWireSphere", &glutWireSphere
);
129 function(L
, "glutWireTeapot", &glutWireTeapot
);
130 function(L
, "glutSolidTeapot", &glutSolidTeapot
);
134 class_
<gl_constants
>(L
, "gl")
137 value("COLOR_BUFFER_BIT", GL_COLOR_BUFFER_BIT
),
138 value("DEPTH_BUFFER_BIT", GL_DEPTH_BUFFER_BIT
),
139 value("TRIANGLES", GL_TRIANGLES
),
140 value("MODELVIEW", GL_MODELVIEW
),
141 value("PROJECTION", GL_PROJECTION
)
144 function(L
, "glBegin", &glBegin
);
145 function(L
, "glVertex3", &glVertex3f
);
146 function(L
, "glEnd", &glEnd
);
147 function(L
, "glClear", &glClear
);
148 function(L
, "glPushMatrix", &glPushMatrix
);
149 function(L
, "glPopMatrix", &glPopMatrix
);
150 function(L
, "glRotate", &glRotatef
);
151 function(L
, "glColor3", &glColor3f
);
152 function(L
, "glColor4", &glColor4f
);
153 function(L
, "glMatrixMode", &glMatrixMode
);
154 function(L
, "glLoadIdentity", &glLoadIdentity
);
155 function(L
, "glViewport", &glViewport
);
156 function(L
, "glTranslate", &glTranslatef
);
160 function(L
, "gluPerspective", &gluPerspective
);
165 lua_State
* L
= lua_open();
174 glutInit (&argc
, argv
);
176 lua_dofile(L
, "glut_bindings.lua");