2a82284b7a3dfcccebf1d33f6f4b725870c3ac7c
[dosrtxon] / src / 3dgfx.h
1 #ifndef THREEDGFX_H_
2 #define THREEDGFX_H_
3
4 #include "inttypes.h"
5
6 struct g3d_vertex {
7         float x, y, z, w;
8         float nx, ny, nz;
9         float u, v;
10         unsigned char r, g, b, a;
11 };
12
13 enum {
14         G3D_POINTS = 1,
15         G3D_LINES = 2,
16         G3D_TRIANGLES = 3,
17         G3D_QUADS = 4
18 };
19
20 /* g3d_enable/g3d_disable bits */
21 enum {
22         G3D_CULL_FACE   = 0x0001,
23         G3D_DEPTH_TEST  = 0x0002,       /* XXX not implemented */
24         G3D_LIGHTING    = 0x0004,
25         G3D_LIGHT0              = 0x0008,
26         G3D_LIGHT1              = 0x0010,
27         G3D_LIGHT2              = 0x0020,
28         G3D_LIGHT3              = 0x0040,
29         G3D_TEXTURE             = 0x0080,
30         G3D_BLEND               = 0x0100,
31         G3D_TEXTURE_GEN = 0x0200,
32
33         G3D_ALL = 0x7fffffff
34 };
35
36 /* arg to g3d_front_face */
37 enum { G3D_CCW, G3D_CW };
38
39 /* arg to g3d_polygon_mode */
40 enum {
41         G3D_WIRE,
42         G3D_FLAT,
43         G3D_GOURAUD,
44         G3D_TEX,
45         G3D_TEX_GOURAUD
46 };
47
48 /* matrix stacks */
49 enum {
50         G3D_MODELVIEW,
51         G3D_PROJECTION,
52
53         G3D_NUM_MATRICES
54 };
55
56 int g3d_init(void);
57 void g3d_destroy(void);
58
59 void g3d_framebuffer(int width, int height, void *pixels);
60 void g3d_viewport(int x, int y, int w, int h);
61
62 void g3d_enable(unsigned int opt);
63 void g3d_disable(unsigned int opt);
64 void g3d_setopt(unsigned int opt, unsigned int mask);
65 unsigned int g3d_getopt(unsigned int mask);
66
67 void g3d_front_face(unsigned int order);
68 void g3d_polygon_mode(int pmode);
69
70 void g3d_matrix_mode(int mmode);
71
72 void g3d_load_identity(void);
73 void g3d_load_matrix(const float *m);
74 void g3d_mult_matrix(const float *m);
75 void g3d_push_matrix(void);
76 void g3d_pop_matrix(void);
77
78 void g3d_translate(float x, float y, float z);
79 void g3d_rotate(float angle, float x, float y, float z);
80 void g3d_scale(float x, float y, float z);
81 void g3d_ortho(float left, float right, float bottom, float top, float znear, float zfar);
82 void g3d_frustum(float left, float right, float bottom, float top, float znear, float zfar);
83 void g3d_perspective(float vfov, float aspect, float znear, float zfar);
84
85 /* returns pointer to the *internal* matrix, and if argument m is not null,
86  * also copies the internal matrix there. */
87 const float *g3d_get_matrix(int which, float *m);
88
89 void g3d_light_pos(int idx, float x, float y, float z);
90 void g3d_light_color(int idx, float r, float g, float b);
91
92 void g3d_light_ambient(float r, float g, float b);
93
94 void g3d_mtl_diffuse(float r, float g, float b);
95 void g3d_mtl_specular(float r, float g, float b);
96 void g3d_mtl_shininess(float shin);
97
98 void g3d_set_texture(int xsz, int ysz, void *pixels);
99
100 void g3d_draw(int prim, const struct g3d_vertex *varr, int varr_size);
101 void g3d_draw_indexed(int prim, const struct g3d_vertex *varr, int varr_size,
102                 const uint16_t *iarr, int iarr_size);
103
104 void g3d_begin(int prim);
105 void g3d_end(void);
106 void g3d_vertex(float x, float y, float z);
107 void g3d_normal(float x, float y, float z);
108 void g3d_color3b(unsigned char r, unsigned char g, unsigned char b);
109 void g3d_color4b(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
110 void g3d_color3f(float r, float g, float b);
111 void g3d_color4f(float r, float g, float b, float a);
112 void g3d_texcoord(float u, float v);
113
114 #endif  /* THREEDGFX_H_ */