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];
37 int hfilt = VOX_LINEAR, cfilt = VOX_LINEAR;
40 int32_t pos[2], theta, phi;
45 #define COLOR_HORIZON 0xcc77ff
46 #define COLOR_ZENITH 0x5588cc
49 int main(int argc, char **argv)
51 glutInit(&argc, argv);
52 glutInitWindowSize(1280, 960);
53 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
54 glutCreateWindow("voxel landscape test");
56 glutDisplayFunc(display);
58 glutReshapeFunc(reshape);
59 glutKeyboardFunc(keyb);
60 glutKeyboardUpFunc(keyb_up);
62 glutMotionFunc(motion);
81 if(!(vox = vox_open("data/height.png", "data/color.png"))) {
84 vox_framebuf(vox, FB_W, FB_H, fb);
85 vox_fog(vox, 260, COLOR_HORIZON);
86 vox_filter(vox, hfilt, cfilt);
88 glfb_setup(FB_W, FB_H, GLFB_RGBA32, FB_W * 4);
97 #define WALK_SPEED 0x40000
98 #define TURN_SPEED 0x100
102 int32_t fwd[2], right[2];
104 if(input & INP_LTURN) theta += TURN_SPEED;
105 if(input & INP_RTURN) theta -= TURN_SPEED;
107 fwd[0] = -SIN(theta);
112 if(input & INP_FWD) {
116 if(input & INP_BACK) {
120 if(input & INP_RIGHT) {
124 if(input & INP_LEFT) {
129 vox_view(vox, pos[0], pos[1], -30, theta, phi);
137 vox_sky_grad(vox, COLOR_HORIZON, COLOR_ZENITH);
143 assert(glGetError() == GL_NO_ERROR);
147 glutWarpPointer(win_width / 2, win_height / 2);
156 void reshape(int x, int y)
158 float aspect = (float)x / y;
160 vox_proj(vox, 140, 40 * aspect, 1, 300);
162 glViewport(0, 0, x, y);
168 void keyb(unsigned char key, int x, int y)
195 printf("filtering: height(%s) color(%s)\n", hfilt ? "linear" : "nearest",
196 cfilt ? "linear" : "nearest");
197 vox_filter(vox, hfilt, cfilt);
202 vox_filter(vox, hfilt, cfilt);
203 printf("filtering: height(%s) color(%s)\n", hfilt ? "linear" : "nearest",
204 cfilt ? "linear" : "nearest");
212 void keyb_up(unsigned char key, int x, int y)
239 void mouse(int bn, int st, int x, int y)
241 int bidx = bn - GLUT_LEFT_BUTTON;
244 mbstate[bidx] = st == GLUT_DOWN;
249 if(st == GLUT_DOWN) {
250 glutSetCursor(GLUT_CURSOR_NONE);
252 glutSetCursor(GLUT_CURSOR_LEFT_ARROW);
256 void motion(int x, int y)
258 int dx = x - mouse_x;
259 int dy = y - mouse_y;
267 if(!(dx | dy)) return;
272 if(phi < -0x18000) phi = -0x18000;
273 if(phi > 0x18000) phi = 0x18000;