fixed warnings
[dosdemo] / tools / gltest / src / g3demu.c
1 #include <string.h>
2 #include <GL/gl.h>
3 #include "3dgfx.h"
4
5 void g3d_matrix_mode(int mmode)
6 {
7         switch(mmode) {
8         case G3D_MODELVIEW:
9                 glMatrixMode(GL_MODELVIEW);
10                 break;
11         case G3D_PROJECTION:
12                 glMatrixMode(GL_PROJECTION);
13                 break;
14         }
15 }
16
17 void g3d_push_matrix(void)
18 {
19         glPushMatrix();
20 }
21
22 void g3d_pop_matrix(void)
23 {
24         glPopMatrix();
25 }
26
27 void g3d_load_identity(void)
28 {
29         glLoadIdentity();
30 }
31
32 const float *g3d_get_matrix(int which, float *mret)
33 {
34         static float tmp[16];
35
36         switch(which) {
37         case G3D_MODELVIEW:
38                 glGetFloatv(GL_MODELVIEW_MATRIX, tmp);
39                 break;
40
41         case G3D_PROJECTION:
42                 glGetFloatv(GL_PROJECTION_MATRIX, tmp);
43                 break;
44         }
45
46         if(mret) {
47                 memcpy(mret, tmp, sizeof tmp);
48         }
49         return tmp;
50 }
51
52 void g3d_translate(float x, float y, float z)
53 {
54         glTranslatef(x, y, z);
55 }
56
57 void g3d_rotate(float angle, float x, float y, float z)
58 {
59         glRotatef(angle, x, y, z);
60 }
61
62 void g3d_scale(float x, float y, float z)
63 {
64         glScalef(x, y, z);
65 }
66
67 void g3d_draw(int prim, const struct g3d_vertex *varr, int varr_size)
68 {
69         g3d_draw_indexed(prim, varr, varr_size, 0, 0);
70 }
71
72 void g3d_draw_indexed(int prim, const struct g3d_vertex *varr, int varr_size,
73                 const uint16_t *iarr, int iarr_size)
74 {
75         int i, j, nfaces;
76         int glprim;
77         const struct g3d_vertex *vptr = varr;
78         const uint16_t *iptr = iarr;
79
80         switch(prim) {
81         case G3D_POINTS:
82                 glprim = GL_POINTS;
83                 break;
84         case G3D_LINES:
85                 glprim = GL_LINES;
86                 break;
87         case G3D_TRIANGLES:
88                 glprim = GL_TRIANGLES;
89                 break;
90         case G3D_QUADS:
91                 glprim = GL_QUADS;
92                 break;
93         default:
94                 glprim = GL_POLYGON;
95         }
96
97         nfaces = (iarr ? iarr_size : varr_size) / prim;
98         if(prim <= 4) {
99                 glBegin(glprim);
100         }
101
102         for(i=0; i<nfaces; i++) {
103                 if(glprim == GL_POLYGON) {
104                         glBegin(GL_POLYGON);
105                 }
106
107                 for(j=0; j<prim; j++) {
108                         if(iarr) {
109                                 vptr = varr + *iptr++;
110                         }
111                         glNormal3f(vptr->nx, vptr->ny, vptr->nz);
112                         glColor4b(vptr->r, vptr->g, vptr->b, vptr->a);
113                         glTexCoord2f(vptr->u, vptr->v);
114                         glVertex4f(vptr->x, vptr->y, vptr->z, vptr->w);
115                         ++vptr;
116                 }
117
118                 if(glprim == GL_POLYGON) {
119                         glEnd();
120                 }
121         }
122
123         if(prim <= 4) {
124                 glEnd();
125         }
126 }