deepstone

view src/mglimpl.h @ 0:f04884489bad

dos3d initial import
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 21 Nov 2011 06:14:01 +0200
parents
children 0e781cc43178
line source
1 /*
2 256-color 3D graphics hack for real-mode DOS.
3 Copyright (C) 2011 John Tsiombikas <nuclear@member.fsf.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef MGL_IMPL_H_
19 #define MGL_IMPL_H_
21 #define MATRIX_STACK_SIZE 8
22 #define MAX_LIGHTS 4
24 #define ROUND(x) ((x) >= 0.0 ? (x) + 0.5 : (x) - 0.5)
26 typedef struct {
27 float x, y, z, w;
28 } vec4_t;
30 typedef struct {
31 float x, y, z;
32 } vec3_t;
34 typedef struct {
35 float x, y;
36 } vec2_t;
38 typedef float mat4_t[16];
40 struct vertex {
41 vec4_t pos;
42 vec3_t norm;
43 vec2_t tc;
44 float energy;
45 int cidx;
46 };
48 struct state {
49 unsigned int flags;
50 int ord, frontface, cullface;
51 int mmode, mtop[2];
52 mat4_t matrix[2][MATRIX_STACK_SIZE];
53 int prim;
54 struct vertex curv, v[4];
55 int vidx;
56 int vp[4]; /* viewport */
57 int col_range; /* color interpolation range */
58 vec3_t ldir[MAX_LIGHTS];
59 float lint[MAX_LIGHTS];
60 };
62 struct framebuffer {
63 int width, height;
64 unsigned char *pixels;
65 unsigned short **zbuf; /* zbuffer broken in 64k tiles */
66 };
68 int mgl_rast_init(struct state *state, struct framebuffer *fbuf);
69 void mgl_rast_cleanup(void);
70 void mgl_rast_prepare(void);
71 void mgl_draw_point(struct vertex *v);
72 void mgl_draw_line(struct vertex *v0, struct vertex *v1);
73 void mgl_draw_poly(struct vertex *v, int numv);
75 #endif /* MGL_IMPL_H_ */