nuclear@0: /* nuclear@0: 256-color 3D graphics hack for real-mode DOS. nuclear@0: Copyright (C) 2011 John Tsiombikas nuclear@0: nuclear@0: This program is free software: you can redistribute it and/or modify nuclear@0: it under the terms of the GNU General Public License as published by nuclear@0: the Free Software Foundation, either version 3 of the License, or nuclear@0: (at your option) any later version. nuclear@0: nuclear@0: This program is distributed in the hope that it will be useful, nuclear@0: but WITHOUT ANY WARRANTY; without even the implied warranty of nuclear@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the nuclear@0: GNU General Public License for more details. nuclear@0: nuclear@0: You should have received a copy of the GNU General Public License nuclear@0: along with this program. If not, see . nuclear@0: */ nuclear@0: #ifndef MGL_IMPL_H_ nuclear@0: #define MGL_IMPL_H_ nuclear@0: nuclear@0: #define MATRIX_STACK_SIZE 8 nuclear@0: #define MAX_LIGHTS 4 nuclear@0: nuclear@9: #define ZTILE_SIZE 16384 nuclear@9: #define ZTILE_SHIFT 14 nuclear@9: #define ZTILE_MASK 0x3fff nuclear@9: nuclear@9: #define ZTILE(x) (((x) & ~ZTILE_MASK) >> ZTILE_SHIFT) nuclear@9: #define ZTILE_OFFS(x) ((x) & ZTILE_MASK) nuclear@9: nuclear@0: #define ROUND(x) ((x) >= 0.0 ? (x) + 0.5 : (x) - 0.5) nuclear@0: nuclear@0: typedef struct { nuclear@0: float x, y, z, w; nuclear@0: } vec4_t; nuclear@0: nuclear@0: typedef struct { nuclear@0: float x, y, z; nuclear@0: } vec3_t; nuclear@0: nuclear@0: typedef struct { nuclear@0: float x, y; nuclear@0: } vec2_t; nuclear@0: nuclear@0: typedef float mat4_t[16]; nuclear@0: nuclear@0: struct vertex { nuclear@0: vec4_t pos; nuclear@0: vec3_t norm; nuclear@0: vec2_t tc; nuclear@0: float energy; nuclear@0: int cidx; nuclear@0: }; nuclear@0: nuclear@3: struct texture { nuclear@3: int width, height; nuclear@3: int xshift, yshift; nuclear@3: unsigned int xmask, ymask; nuclear@3: unsigned char *pixels; nuclear@3: }; nuclear@3: nuclear@0: struct state { nuclear@0: unsigned int flags; nuclear@0: int ord, frontface, cullface; nuclear@0: int mmode, mtop[2]; nuclear@0: mat4_t matrix[2][MATRIX_STACK_SIZE]; nuclear@0: int prim; nuclear@0: struct vertex curv, v[4]; nuclear@0: int vidx; nuclear@0: int vp[4]; /* viewport */ nuclear@0: int col_range; /* color interpolation range */ nuclear@0: vec3_t ldir[MAX_LIGHTS]; nuclear@0: float lint[MAX_LIGHTS]; nuclear@3: nuclear@3: struct texture tex; nuclear@0: }; nuclear@0: nuclear@0: struct framebuffer { nuclear@0: int width, height; nuclear@0: unsigned char *pixels; nuclear@9: unsigned short **zbuf; /* zbuffer broken in ZTILE_SIZE tiles */ nuclear@9: int num_ztiles; nuclear@0: }; nuclear@0: nuclear@3: nuclear@0: int mgl_rast_init(struct state *state, struct framebuffer *fbuf); nuclear@0: void mgl_rast_cleanup(void); nuclear@0: void mgl_rast_prepare(void); nuclear@0: void mgl_draw_point(struct vertex *v); nuclear@0: void mgl_draw_line(struct vertex *v0, struct vertex *v1); nuclear@0: void mgl_draw_poly(struct vertex *v, int numv); nuclear@0: nuclear@0: #endif /* MGL_IMPL_H_ */