TinyGL 0.4.1 for MinGW
misc.c
Go to the documentation of this file.
1#include "zgl.h"
2#include "msghandling.h"
3
5{
6 int xsize,ysize,xmin,ymin,xsize_req,ysize_req;
7
8 xmin=p[1].i;
9 ymin=p[2].i;
10 xsize=p[3].i;
11 ysize=p[4].i;
12
13 /* we may need to resize the zbuffer */
14
15 if (c->viewport.xmin != xmin ||
16 c->viewport.ymin != ymin ||
17 c->viewport.xsize != xsize ||
18 c->viewport.ysize != ysize) {
19
20 xsize_req=xmin+xsize;
21 ysize_req=ymin+ysize;
22
23 if (c->gl_resize_viewport &&
24 c->gl_resize_viewport(c,&xsize_req,&ysize_req) != 0) {
25 gl_fatal_error("glViewport: error while resizing display");
26 }
27
28 xsize=xsize_req-xmin;
29 ysize=ysize_req-ymin;
30 if (xsize <= 0 || ysize <= 0) {
31 gl_fatal_error("glViewport: size too small");
32 }
33
34 tgl_trace("glViewport: %d %d %d %d\n",
35 xmin, ymin, xsize, ysize);
36 c->viewport.xmin=xmin;
37 c->viewport.ymin=ymin;
38 c->viewport.xsize=xsize;
39 c->viewport.ysize=ysize;
40
41 c->viewport.updated=1;
42 }
43}
44
46{
47 int code=p[1].i;
48 int v=p[2].i;
49
50 switch(code) {
51 case GL_CULL_FACE:
53 break;
54 case GL_LIGHTING:
56 break;
59 break;
60 case GL_TEXTURE_2D:
62 break;
63 case GL_NORMALIZE:
65 break;
66 case GL_DEPTH_TEST:
67 c->depth_test = v;
68 break;
70 if (v) c->offset_states |= TGL_OFFSET_FILL;
71 else c->offset_states &= ~TGL_OFFSET_FILL;
72 break;
75 else c->offset_states &= ~TGL_OFFSET_POINT;
76 break;
78 if (v) c->offset_states |= TGL_OFFSET_LINE;
79 else c->offset_states &= ~TGL_OFFSET_LINE;
80 break;
81 default:
82 if (code>=GL_LIGHT0 && code<GL_LIGHT0+MAX_LIGHTS) {
84 } else {
85 /*
86 fprintf(stderr,"glEnableDisable: 0x%X not supported.\n",code);
87 */
88 }
89 break;
90 }
91}
92
94{
95 int code=p[1].i;
96 c->current_shade_model=code;
97}
98
100{
101 int code=p[1].i;
102 c->current_cull_face=code;
103}
104
106{
107 int code=p[1].i;
108 c->current_front_face=code;
109}
110
112{
113 int face=p[1].i;
114 int mode=p[2].i;
115
116 switch(face) {
117 case GL_BACK:
118 c->polygon_mode_back=mode;
119 break;
120 case GL_FRONT:
121 c->polygon_mode_front=mode;
122 break;
124 c->polygon_mode_front=mode;
125 c->polygon_mode_back=mode;
126 break;
127 default:
128 assert(0);
129 }
130}
131
133{
134#if 0
135 int target=p[1].i;
136 int mode=p[2].i;
137
138 /* do nothing */
139#endif
140}
141
142void
144{
145 c->offset_factor = p[1].f;
146 c->offset_units = p[2].f;
147}
void gl_fatal_error(char *format,...)
Definition: error.c:4
@ GL_BACK
Definition: gl.h:120
@ GL_NORMALIZE
Definition: gl.h:191
@ GL_FRONT_AND_BACK
Definition: gl.h:184
@ GL_CULL_FACE
Definition: gl.h:121
@ GL_TEXTURE_2D
Definition: gl.h:488
@ GL_COLOR_MATERIAL
Definition: gl.h:188
@ GL_LIGHT0
Definition: gl.h:159
@ GL_DEPTH_TEST
Definition: gl.h:149
@ GL_LIGHTING
Definition: gl.h:158
@ GL_POLYGON_OFFSET_POINT
Definition: gl.h:129
@ GL_FRONT
Definition: gl.h:119
@ GL_POLYGON_OFFSET_FILL
Definition: gl.h:131
@ GL_POLYGON_OFFSET_LINE
Definition: gl.h:130
void gl_enable_disable_light(GLContext *c, int light, int v)
Definition: light.c:164
void glopEnableDisable(GLContext *c, GLParam *p)
Definition: misc.c:45
void glopShadeModel(GLContext *c, GLParam *p)
Definition: misc.c:93
void glopPolygonOffset(GLContext *c, GLParam *p)
Definition: misc.c:143
void glopHint(GLContext *c, GLParam *p)
Definition: misc.c:132
void glopFrontFace(GLContext *c, GLParam *p)
Definition: misc.c:105
void glopViewport(GLContext *c, GLParam *p)
Definition: misc.c:4
void glopPolygonMode(GLContext *c, GLParam *p)
Definition: misc.c:111
void glopCullFace(GLContext *c, GLParam *p)
Definition: misc.c:99
void tgl_trace(const char *format,...)
Definition: msghandling.c:28
Definition: zgl.h:159
float offset_units
Definition: zgl.h:262
float offset_factor
Definition: zgl.h:261
int cull_face_enabled
Definition: zgl.h:212
int polygon_mode_back
Definition: zgl.h:206
int color_material_enabled
Definition: zgl.h:173
int current_front_face
Definition: zgl.h:209
int depth_test
Definition: zgl.h:277
int normalize_enabled
Definition: zgl.h:213
GLViewport viewport
Definition: zgl.h:203
int lighting_enabled
Definition: zgl.h:168
int current_shade_model
Definition: zgl.h:210
int texture_2d_enabled
Definition: zgl.h:179
int polygon_mode_front
Definition: zgl.h:207
int offset_states
Definition: zgl.h:263
int current_cull_face
Definition: zgl.h:211
int(* gl_resize_viewport)(struct GLContext *c, int *xsize, int *ysize)
Definition: zgl.h:274
int xmin
Definition: zgl.h:91
int ymin
Definition: zgl.h:91
int ysize
Definition: zgl.h:91
int updated
Definition: zgl.h:94
int xsize
Definition: zgl.h:91
Definition: zgl.h:97
int i
Definition: zgl.h:100
float f
Definition: zgl.h:99
#define TGL_OFFSET_POINT
Definition: zgl.h:50
#define MAX_LIGHTS
Definition: zgl.h:41
#define TGL_OFFSET_LINE
Definition: zgl.h:49
#define TGL_OFFSET_FILL
Definition: zgl.h:48