projects
/
laserbrain_demo
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
metascene initial implementation
[laserbrain_demo]
/
src
/
main.cc
diff --git
a/src/main.cc
b/src/main.cc
index
c4696f6
..
f0ac037
100644
(file)
--- a/
src/main.cc
+++ b/
src/main.cc
@@
-7,140
+7,98
@@
#else
#include <GL/glut.h>
#endif
#else
#include <GL/glut.h>
#endif
-#include "gear.h"
+#include "app.h"
-bool init();
-void cleanup();
-void display();
-void draw_gears();
-void reshape(int x, int y);
-void keyb(unsigned char key, int x, int y);
-void mouse(int bn, int st, int x, int y);
-void motion(int x, int y);
+static bool init();
+static void display();
+static void idle();
+static void reshape(int x, int y);
+static void key_press(unsigned char key, int x, int y);
+static void key_release(unsigned char key, int x, int y);
+static void mouse(int bn, int st, int x, int y);
-static float cam_dist = 2;
-static float cam_theta, cam_phi;
-static int prev_mx, prev_my;
-static bool bnstate[8];
-
-static Gear *test_gear;
+static unsigned int start_time;
int main(int argc, char **argv)
{
int main(int argc, char **argv)
{
- glutInit(&argc, argv);
glutInitWindowSize(1024, 768);
glutInitWindowSize(1024, 768);
- glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
- glutCreateWindow("Antikythera");
+ glutInit(&argc, argv);
+ glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | GLUT_MULTISAMPLE);
+ glutCreateWindow("demo");
glutDisplayFunc(display);
glutDisplayFunc(display);
+ glutIdleFunc(idle);
glutReshapeFunc(reshape);
glutReshapeFunc(reshape);
- glutKeyboardFunc(keyb);
+ glutKeyboardFunc(key_press);
+ glutKeyboardUpFunc(key_release);
glutMouseFunc(mouse);
glutMouseFunc(mouse);
- glutMotionFunc(motion);
+ glutMotionFunc(app_mouse_motion);
+ glutPassiveMotionFunc(app_mouse_motion);
if(!init()) {
return 1;
}
if(!init()) {
return 1;
}
- atexit(cleanup);
+ atexit(app_cleanup);
glutMainLoop();
return 0;
}
glutMainLoop();
return 0;
}
-bool init()
+void app_swap_buffers()
{
{
- glewInit();
-
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_CULL_FACE);
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- glEnable(GL_NORMALIZE);
-
- Mesh::use_custom_sdr_attr = false;
-
- test_gear = new Gear;
- test_gear->gen_mesh();
-
- return true;
+ glutSwapBuffers();
}
}
-void cleanup()
+void app_quit()
{
{
- delete test_gear;
+ exit(0);
}
}
-void display()
+static bool init()
{
{
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0, 0, -cam_dist);
- glRotatef(cam_phi, 1, 0, 0);
- glRotatef(cam_theta, 0, 1, 0);
+ glewInit();
- draw_gears();
+ if(!app_init()) {
+ return false;
+ }
- glutSwapBuffers();
- assert(glGetError() == GL_NO_ERROR);
+ start_time = glutGet(GLUT_ELAPSED_TIME);
+ return true;
}
}
-void draw_gears()
+static void display()
{
{
- /* world scale is in meters, gears are in millimeters, sclae by 1/1000 */
- glPushMatrix();
- glScalef(0.001, 0.001, 0.001);
-
- test_gear->draw();
+ time_msec = glutGet(GLUT_ELAPSED_TIME) - start_time;
+ app_display();
+}
- glPopMatrix();
+static void idle()
+{
+ glutPostRedisplay();
}
}
-void reshape(int x, int y)
+static void reshape(int x, int y)
{
{
- glViewport(0, 0, x, y);
+ win_width = x;
+ win_height = y;
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(50.0, (float)x / (float)y, 0.05, 100.0);
+ app_reshape(x, y);
}
}
-void keyb(unsigned char key, int x, int y)
+static void key_press(unsigned char key, int x, int y)
{
{
- switch(key) {
- case 27:
- exit(0);
- }
+ app_keyboard(key, true);
}
}
-void mouse(int bn, int st, int x, int y)
+static void key_release(unsigned char key, int x, int y)
{
{
- prev_mx = x;
- prev_my = y;
- bnstate[bn - GLUT_LEFT_BUTTON] = st == GLUT_DOWN;
+ app_keyboard(key, false);
}
}
-void motion(int x, int y)
+static void mouse(int bn, int st, int x, int y)
{
{
- int dx = x - prev_mx;
- int dy = y - prev_my;
- prev_mx = x;
- prev_my = y;
-
- if(!dx && !dy) return;
-
- if(bnstate[0]) {
- cam_theta += dx * 0.5;
- cam_phi += dy * 0.5;
+ int bidx = bn - GLUT_LEFT_BUTTON;
+ bool down = st == GLUT_DOWN;
- if(cam_phi < -90) cam_phi = -90;
- if(cam_phi > 90) cam_phi = 90;
- glutPostRedisplay();
- }
- if(bnstate[2]) {
- cam_dist += dy * 0.05;
- if(cam_dist < 0.0) cam_dist = 0.0;
- glutPostRedisplay();
- }
+ app_mouse_button(bidx, down, x, y);
}
}