24 void reshape(int x, int y);
25 void keyb(unsigned char key, int x, int y);
26 void keyb_up(unsigned char key, int x, int y);
27 void mouse(int bn, int st, int x, int y);
28 void motion(int x, int y);
30 int win_width, win_height;
34 unsigned int fb[FB_W * FB_H];
36 int mouse_x, mouse_y, mwarp, mbstate[3];
39 int32_t pos[2], angle;
44 int main(int argc, char **argv)
46 glutInit(&argc, argv);
47 glutInitWindowSize(1280, 960);
48 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
49 glutCreateWindow("voxel landscape test");
51 glutDisplayFunc(display);
53 glutReshapeFunc(reshape);
54 glutKeyboardFunc(keyb);
55 glutKeyboardUpFunc(keyb_up);
57 glutMotionFunc(motion);
76 if(!(vox = vox_open("data/height.png", "data/color.png"))) {
79 vox_framebuf(vox, FB_W, FB_H, fb);
80 vox_proj(vox, 45, 1, 200);
81 vox_view(vox, pos[0], pos[1], angle);
83 glfb_setup(FB_W, FB_H, GLFB_RGBA32, FB_W * 4);
92 #define WALK_SPEED 0x40000
93 #define TURN_SPEED 0x100
97 int32_t fwd[2], right[2];
99 if(input & INP_LTURN) angle += TURN_SPEED;
100 if(input & INP_RTURN) angle -= TURN_SPEED;
102 fwd[0] = -SIN(angle);
107 if(input & INP_FWD) {
111 if(input & INP_BACK) {
115 if(input & INP_RIGHT) {
119 if(input & INP_LEFT) {
124 vox_view(vox, pos[0], pos[1], angle);
131 memset(fb, 0, sizeof fb);
134 vox_sky_grad(vox, 0xcc77ff, 0x5588cc);
140 assert(glGetError() == GL_NO_ERROR);
144 glutWarpPointer(win_width / 2, win_height / 2);
153 void reshape(int x, int y)
155 glViewport(0, 0, x, y);
161 void keyb(unsigned char key, int x, int y)
191 void keyb_up(unsigned char key, int x, int y)
218 void mouse(int bn, int st, int x, int y)
220 int bidx = bn - GLUT_LEFT_BUTTON;
223 mbstate[bidx] = st == GLUT_DOWN;
228 if(st == GLUT_DOWN) {
229 glutSetCursor(GLUT_CURSOR_NONE);
231 glutSetCursor(GLUT_CURSOR_LEFT_ARROW);
235 void motion(int x, int y)
237 int dx = x - mouse_x;
238 int dy = y - mouse_y;
246 if(!(dx | dy)) return;