deepstone

view src/mglimpl.h @ 10:059bb38506b3

fixed stuff
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 28 Nov 2011 01:37:04 +0200
parents 0e781cc43178
children 0909996838ff
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 ZTILE_SIZE 16384
25 #define ZTILE_SHIFT 14
26 #define ZTILE_MASK 0x3fff
28 #define ZTILE(x) (((x) & ~ZTILE_MASK) >> ZTILE_SHIFT)
29 #define ZTILE_OFFS(x) ((x) & ZTILE_MASK)
31 #define ROUND(x) ((x) >= 0.0 ? (x) + 0.5 : (x) - 0.5)
33 typedef struct {
34 float x, y, z, w;
35 } vec4_t;
37 typedef struct {
38 float x, y, z;
39 } vec3_t;
41 typedef struct {
42 float x, y;
43 } vec2_t;
45 typedef float mat4_t[16];
47 struct vertex {
48 vec4_t pos;
49 vec3_t norm;
50 vec2_t tc;
51 float energy;
52 int cidx;
53 };
55 struct texture {
56 int width, height;
57 int xshift, yshift;
58 unsigned int xmask, ymask;
59 unsigned char *pixels;
60 };
62 struct state {
63 unsigned int flags;
64 int ord, frontface, cullface;
65 int mmode, mtop[2];
66 mat4_t matrix[2][MATRIX_STACK_SIZE];
67 int prim;
68 struct vertex curv, v[4];
69 int vidx;
70 int vp[4]; /* viewport */
71 int col_range; /* color interpolation range */
72 vec3_t ldir[MAX_LIGHTS];
73 float lint[MAX_LIGHTS];
75 struct texture tex;
76 };
78 struct framebuffer {
79 int width, height;
80 unsigned char *pixels;
81 unsigned short **zbuf; /* zbuffer broken in ZTILE_SIZE tiles */
82 int num_ztiles;
83 };
86 int mgl_rast_init(struct state *state, struct framebuffer *fbuf);
87 void mgl_rast_cleanup(void);
88 void mgl_rast_prepare(void);
89 void mgl_draw_point(struct vertex *v);
90 void mgl_draw_line(struct vertex *v0, struct vertex *v1);
91 void mgl_draw_poly(struct vertex *v, int numv);
93 #endif /* MGL_IMPL_H_ */