version 2.8
misc.c
1 #include "zgl.h"
2 #include "msghandling.h"
3 
4 void glopViewport(GLContext *c,GLParam *p)
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 
45 void glopEnableDisable(GLContext *c,GLParam *p)
46 {
47  int code=p[1].i;
48  int v=p[2].i;
49 
50  switch(code) {
51  case GL_CULL_FACE:
52  c->cull_face_enabled=v;
53  break;
54  case GL_LIGHTING:
55  c->lighting_enabled=v;
56  break;
57  case GL_COLOR_MATERIAL:
58  c->color_material_enabled=v;
59  break;
60  case GL_TEXTURE_2D:
61  c->texture_2d_enabled=v;
62  break;
63  case GL_NORMALIZE:
64  c->normalize_enabled=v;
65  break;
66  case GL_DEPTH_TEST:
67  c->depth_test = v;
68  break;
69  case GL_POLYGON_OFFSET_FILL:
70  if (v) c->offset_states |= TGL_OFFSET_FILL;
71  else c->offset_states &= ~TGL_OFFSET_FILL;
72  break;
73  case GL_POLYGON_OFFSET_POINT:
74  if (v) c->offset_states |= TGL_OFFSET_POINT;
75  else c->offset_states &= ~TGL_OFFSET_POINT;
76  break;
77  case GL_POLYGON_OFFSET_LINE:
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) {
83  gl_enable_disable_light(c,code - GL_LIGHT0, v);
84  } else {
85  /*
86  fprintf(stderr,"glEnableDisable: 0x%X not supported.\n",code);
87  */
88  }
89  break;
90  }
91 }
92 
93 void glopShadeModel(GLContext *c,GLParam *p)
94 {
95  int code=p[1].i;
96  c->current_shade_model=code;
97 }
98 
99 void glopCullFace(GLContext *c,GLParam *p)
100 {
101  int code=p[1].i;
102  c->current_cull_face=code;
103 }
104 
105 void glopFrontFace(GLContext *c,GLParam *p)
106 {
107  int code=p[1].i;
108  c->current_front_face=code;
109 }
110 
111 void glopPolygonMode(GLContext *c,GLParam *p)
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;
123  case GL_FRONT_AND_BACK:
124  c->polygon_mode_front=mode;
125  c->polygon_mode_back=mode;
126  break;
127  default:
128  gl_assert(0);
129  }
130 }
131 
132 void glopHint(GLContext *c,GLParam *p)
133 {
134  (void)c;
135  (void)p;
136 #if 0
137  int target=p[1].i;
138  int mode=p[2].i;
139 
140  /* do nothing */
141 #endif
142 }
143 
144 void
145 glopPolygonOffset(GLContext *c, GLParam *p)
146 {
147  c->offset_factor = p[1].f;
148  c->offset_units = p[2].f;
149 }