1 #include "backend/video.h"
2 #include "backend/input.h"
3 #include "backend/shapes.h"
11 void terrain_demo(struct terrain
*t
)
14 float *height
= t
->height
;
17 for (i
=0; i
<size
; i
++)
19 for (j
=0; j
<size
; j
++)
21 float z
= (cos(i
*0.5) + sin(j
*0.5)) * 2.0;
23 if (z
> t
->max_height
)
25 if (z
< t
->min_height
)
33 int main(int argc
, char **argv
)
36 v_closable(1); // can close the window when it's running
46 struct terrain
*mesh
= terrain_create(MESH_SIZE
);
55 float zoom_max
= 10.0;
57 float rot
[] = {45.0, -45.0, 0.0};
59 float mouse_sensitivity
= 0.2;
66 mouse
= i_mousestate();
68 if (key
[K_ESCAPE
]) done
= 1;
73 terrain_fractal(mesh
, MESH_SIZE
);
84 terrain_smooth(mesh
, 0.90);
89 mesh
->drawmode
= FLAT
;
95 mesh
->drawmode
= NORMAL
;
100 mesh
->drawmode
= NORMAL_DEBUG
;
104 if (mouse
->button
& M_BUTTON(M_MIDDLE
))
106 zoom
-= mouse
->rel_y
* mouse_sensitivity
* 0.1 * zoom
;
107 if (zoom
< zoom_min
) zoom
= zoom_min
;
108 if (zoom
> zoom_max
) zoom
= zoom_max
;
110 if (mouse
->button
& M_BUTTON(M_RIGHT
))
112 rot
[1] += mouse
->rel_x
* mouse_sensitivity
;
113 rot
[0] += mouse
->rel_y
* mouse_sensitivity
;
116 glMatrixMode(GL_MODELVIEW
);
119 glTranslatef(0.0, 0.0, -1000.0); // remember: this is an ortho projection
120 glScalef(1.0/zoom
, 1.0/zoom
, 1.0/zoom
);
121 glRotatef(rot
[0], 1,0,0);
122 glRotatef(rot
[1], 0,1,0);
123 glRotatef(rot
[2], 0,0,1);
125 glClear(GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
131 glScalef(zoom
, zoom
, zoom
);
133 glDisable(GL_LIGHTING
);
134 glDisable(GL_DEPTH_TEST
);
138 glColor3f(1.0, 0.0, 0.0); // x
139 glVertex3f(0.0, 0.0, 0.0);
140 glVertex3f(1.0, 0.0, 0.0);
142 glColor3f(0.0, 1.0, 0.0); // y
143 glVertex3f(0.0, 0.0, 0.0);
144 glVertex3f(0.0, 1.0, 0.0);
146 glColor3f(0.0, 0.0, 1.0); // z
147 glVertex3f(0.0, 0.0, 0.0);
148 glVertex3f(0.0, 0.0, 1.0);
152 glEnable(GL_DEPTH_TEST
);
153 glEnable(GL_LIGHTING
);
160 terrain_destroy(mesh
);
167 glMatrixMode(GL_PROJECTION
);
170 int width
= v_info()->width
;
171 int height
= v_info()->height
;
173 float ratio
= (float)width
/height
;
176 glOrtho(-scale
*ratio
, scale
*ratio
, -scale
, scale
, -10000.0, 10000.0);
178 glShadeModel(GL_SMOOTH
);
180 glEnable(GL_DEPTH_TEST
);
181 glEnable(GL_NORMALIZE
);
183 glEnable(GL_LIGHTING
);