1 /************************************************************************
3 * voxelands - 3d voxel world sandbox game
4 * Copyright (C) Lisa 'darkrose' Milne 2016 <lisa@ltmnet.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>
18 ************************************************************************/
41 /* get client-side frame time */
44 return render_data
.dtime
;
47 /* get the current projection matrix */
48 matrix_t
*render_get_projection_matrix()
50 return &render_data
.projection
;
53 void render_set_projection_matrix(matrix_t
*m
)
64 render_data
.projection
= *m
;
72 fov
= math_degrees_to_radians(fov
/2.0);
74 ratio
= (float)wm_data
.size
.width
/(float)wm_data
.size
.height
;
77 z
= far_plane
-near_plane
;
79 matrix_init(&render_data
.projection
);
81 render_data
.projection
.data
[0] = x
;
82 render_data
.projection
.data
[5] = y
;
83 render_data
.projection
.data
[10] = -((far_plane
+near_plane
)/z
);
84 render_data
.projection
.data
[11] = -1;
85 render_data
.projection
.data
[14] = -((2.0*near_plane
*far_plane
)/z
);
86 render_data
.projection
.data
[15] = 0;
92 if (!render_data
.ticks
)
93 render_data
.ticks
= time_ticks();
103 if (wm_data
.cursor
.mat
) {
105 events_get_mouse(mouse
);
106 render2d_quad_mat(wm_data
.cursor
.mat
,mouse
[0]+wm_data
.cursor
.x
,mouse
[1]+wm_data
.cursor
.y
,wm_data
.cursor
.w
,wm_data
.cursor
.h
);
111 /* should get this from sky when in-game */
112 glClearColor(0.0, 0.0, 0.0, 1.0);
113 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
114 glEnable(GL_DEPTH_TEST
);
116 water_prerender(cam);
118 render_map(cam
,NULL
);
126 glDisable(GL_DEPTH_TEST
);
132 /* calculate a scale factor for smooth animations */
133 render_data
.tticks
= interval_delay(render_data
.ticks
,wm_data
.frame_cap
);
135 if (wm_data
.lfps_i
> 3)
137 wm_data
.lfps
[wm_data
.lfps_i
] = calc_fps(render_data
.ticks
,render_data
.tticks
);
138 wm_data
.fps
= (wm_data
.lfps
[0]+wm_data
.lfps
[1]+wm_data
.lfps
[2]+wm_data
.lfps
[3])/4;
139 render_data
.dtime
= time_dtime(render_data
.ticks
);
140 render_data
.ticks
= render_data
.tticks
;