shithub: tinygl

Download patch

ref: 441fcdcad62c32e17c72e11ba1e7312aed46b1d1
parent: 850d4c3da6cdb2876d07d780cf36baf42a72e66c
author: David <gek@katherine>
date: Thu Mar 11 09:35:23 EST 2021

Automatic commit.

--- a/src/arrays.c
+++ b/src/arrays.c
@@ -291,7 +291,8 @@
 
 
 
-void glopArrayElement(GLContext* c, GLParam* param) {
+void glopArrayElement(GLParam* param) {
+	GLContext* c = gl_get_context();
 	GLint i;
 	GLint states = c->client_states;
 	GLint idx = param[1].i;
@@ -304,7 +305,7 @@
 		p[2].f = c->color_array[i + 1];
 		p[3].f = c->color_array[i + 2];
 		p[4].f = (size > 3) ? c->color_array[i + 3] : 1.0f;
-		glopColor(c, p);
+		glopColor(p);
 	}
 	if (states & NORMAL_ARRAY) {
 		i = idx * (3 + c->normal_array_stride);
@@ -329,7 +330,7 @@
 		p[2].f = c->vertex_array[i + 1];
 		p[3].f = (size > 2) ? c->vertex_array[i + 2] : 0.0f;
 		p[4].f = (size > 3) ? c->vertex_array[i + 3] : 1.0f;
-		glopVertex(c, p);
+		glopVertex(p);
 	}
 }
 
@@ -353,7 +354,7 @@
 	glEnd();
 }
 
-void glopEnableClientState(GLContext* c, GLParam* p) { c->client_states |= p[1].i; }
+void glopEnableClientState(GLParam* p) { gl_get_context()->client_states |= p[1].i; }
 
 void glEnableClientState(GLenum array) {
 	GLParam p[2];
@@ -379,7 +380,7 @@
 	gl_add_op(p);
 }
 
-void glopDisableClientState(GLContext* c, GLParam* p) { c->client_states &= p[1].i; }
+void glopDisableClientState( GLParam* p) {GLContext* c = gl_get_context(); c->client_states &= p[1].i; }
 
 void glDisableClientState(GLenum array) {
 	GLParam p[2];
@@ -405,7 +406,8 @@
 	gl_add_op(p);
 }
 
-void glopVertexPointer(GLContext* c, GLParam* p) {
+void glopVertexPointer(GLParam* p) {
+	GLContext* c = gl_get_context();
 	c->vertex_array_size = p[1].i;
 	c->vertex_array_stride = p[2].i;
 	c->vertex_array = p[3].p;
@@ -429,7 +431,8 @@
 	gl_add_op(p);
 }
 
-void glopColorPointer(GLContext* c, GLParam* p) {
+void glopColorPointer(GLParam* p) {
+	GLContext* c = gl_get_context();
 	c->color_array_size = p[1].i;
 	c->color_array_stride = p[2].i;
 	c->color_array = p[3].p;
@@ -453,7 +456,8 @@
 	gl_add_op(p);
 }
 
-void glopNormalPointer(GLContext* c, GLParam* p) {
+void glopNormalPointer(GLParam* p) {
+	GLContext* c = gl_get_context();
 	c->normal_array_stride = p[1].i;
 	c->normal_array = p[2].p;
 }
@@ -475,7 +479,8 @@
 	gl_add_op(p);
 }
 
-void glopTexCoordPointer(GLContext* c, GLParam* p) {
+void glopTexCoordPointer(GLParam* p) {
+	GLContext* c = gl_get_context();
 	c->texcoord_array_size = p[1].i;
 	c->texcoord_array_stride = p[2].i;
 	c->texcoord_array = p[3].p;
--- a/src/clear.c
+++ b/src/clear.c
@@ -1,14 +1,15 @@
 #include "zgl.h"
 
-void glopClearColor(GLContext* c, GLParam* p) {
+void glopClearColor(GLParam* p) {
+	GLContext* c = gl_get_context();
 	c->clear_color.v[0] = p[1].f;
 	c->clear_color.v[1] = p[2].f;
 	c->clear_color.v[2] = p[3].f;
 	c->clear_color.v[3] = p[4].f;
 }
-void glopClearDepth(GLContext* c, GLParam* p) { c->clear_depth = p[1].f; }
+void glopClearDepth(GLParam* p) { GLContext* c = gl_get_context(); c->clear_depth = p[1].f; }
 
-void glopClear(GLContext* c, GLParam* p) {
+void glopClear(GLParam* p) {GLContext* c = gl_get_context();
 	GLint mask = p[1].i;
 	GLint z = 0;
 	GLint r = (GLint)(c->clear_color.v[0] * COLOR_MULT_MASK);
--- a/src/clip.c
+++ b/src/clip.c
@@ -10,8 +10,8 @@
 #define CLIP_ZMIN (1 << 4)
 #define CLIP_ZMAX (1 << 5)
 
-static inline void gl_transform_to_viewport_clip_c(GLContext* c, GLVertex* v) { //MARK: NOT_INLINED_IN_OG
-
+static inline void gl_transform_to_viewport_clip_c(GLVertex* v) { //MARK: NOT_INLINED_IN_OG
+	GLContext* c = gl_get_context();
 	/* coordinates */
 	{
 		GLfloat winv = 1.0 / v->pc.W;
@@ -85,7 +85,7 @@
 
 GLfloat (*clip_proc[6])(V4*, V4*, V4*) = {clip_xmin, clip_xmax, clip_ymin, clip_ymax, clip_zmin, clip_zmax};
 /* point */
-static void gl_add_select1(GLContext* c, GLint z1, GLint z2, GLint z3) {
+static void gl_add_select1(GLint z1, GLint z2, GLint z3) {
 	GLint min, max;
 	min = max = z1;
 	if (z2 < min)
@@ -97,14 +97,15 @@
 	if (z3 > max)
 		max = z3;
 
-	gl_add_select(c, 0xffffffff - min, 0xffffffff - max);
+	gl_add_select(0xffffffff - min, 0xffffffff - max);
 }
-void gl_draw_point(GLContext* c, GLVertex* p0) {
+void gl_draw_point(GLVertex* p0) {
+	GLContext* c = gl_get_context();
 	if (p0->clip_code == 0) {
 		if (c->render_mode == GL_SELECT) {
-			gl_add_select(c, p0->zp.z, p0->zp.z);
+			gl_add_select(p0->zp.z, p0->zp.z);
 		}else if (c->render_mode == GL_FEEDBACK){
-			gl_add_feedback(c,GL_POINT_TOKEN,p0,NULL,NULL,0);
+			gl_add_feedback(GL_POINT_TOKEN,p0,NULL,NULL,0);
 		} else {
 			ZB_plot(c->zb, &p0->zp);
 		}
@@ -155,7 +156,7 @@
 		return 0;
 	return 1;
 }
-void gl_draw_line(GLContext* c, GLVertex* p1, GLVertex* p2) {
+void gl_draw_line(GLVertex* p1, GLVertex* p2) {GLContext* c = gl_get_context();
 	GLfloat dx, dy, dz, dw, x1, y1, z1, w1;
 	
 	GLVertex q1, q2;
@@ -166,10 +167,10 @@
 
 	if ((cc1 | cc2) == 0) {
 		if (c->render_mode == GL_SELECT) {
-			gl_add_select1(c, p1->zp.z, p2->zp.z, p2->zp.z);
+			gl_add_select1(p1->zp.z, p2->zp.z, p2->zp.z);
 		}else if (c->render_mode == GL_FEEDBACK){
 			gl_add_feedback(
-				c,	GL_LINE_TOKEN,
+				GL_LINE_TOKEN,
 				p1,
 				p2,
 				NULL,
@@ -200,8 +201,8 @@
 
 			GLinterpolate(&q1, p1, p2, tmin);
 			GLinterpolate(&q2, p1, p2, tmax);
-			gl_transform_to_viewport_clip_c(c, &q1);
-			gl_transform_to_viewport_clip_c(c, &q2);
+			gl_transform_to_viewport_clip_c(&q1);
+			gl_transform_to_viewport_clip_c(&q2);
 
 			if (c->zb->depth_test)
 				ZB_line_z(c->zb, &q1.zp, &q2.zp);
@@ -216,7 +217,8 @@
 
 /*Triangles*/
 
-static inline void updateTmp(GLContext* c, GLVertex* q, GLVertex* p0, GLVertex* p1, GLfloat t) { //MARK: INLINED_IN_OG
+static inline void updateTmp(GLVertex* q, GLVertex* p0, GLVertex* p1, GLfloat t) { //MARK: INLINED_IN_OG
+	GLContext* c = gl_get_context();
 	{
 
 
@@ -232,12 +234,12 @@
 
 	q->clip_code = gl_clipcode(q->pc.X, q->pc.Y, q->pc.Z, q->pc.W);
 	if (q->clip_code == 0)
-		gl_transform_to_viewport_clip_c(c, q);
+		gl_transform_to_viewport_clip_c(q);
 }
 //DO NOT INLINE!!! DO NOT INLINE!!! DO NOT INLINE!!!
-static void gl_draw_triangle_clip(GLContext* c, GLVertex* p0, GLVertex* p1, GLVertex* p2, GLint clip_bit);//MARK: NOT_INLINED_IN_OG
+static void gl_draw_triangle_clip(GLVertex* p0, GLVertex* p1, GLVertex* p2, GLint clip_bit);//MARK: NOT_INLINED_IN_OG
 
-void gl_draw_triangle(GLContext* c, GLVertex* p0, GLVertex* p1, GLVertex* p2) {
+void gl_draw_triangle(GLVertex* p0, GLVertex* p1, GLVertex* p2) {GLContext* c = gl_get_context();
 	GLint co, cc[3], front;
 	
 
@@ -264,11 +266,11 @@
 			if (c->current_cull_face == GL_BACK) {
 				if (front == 0)
 					return;
-				c->draw_triangle_front(c, p0, p1, p2);
+				c->draw_triangle_front(p0, p1, p2);
 			} else if (c->current_cull_face == GL_FRONT) {
 				if (front != 0)
 					return;
-				c->draw_triangle_back(c, p0, p1, p2);
+				c->draw_triangle_back(p0, p1, p2);
 			} else {
 				return;
 			}
@@ -275,21 +277,22 @@
 		} else {
 			/* no culling */
 			if (front) {
-				c->draw_triangle_front(c, p0, p1, p2);
+				c->draw_triangle_front(p0, p1, p2);
 			} else {
-				c->draw_triangle_back(c, p0, p1, p2);
+				c->draw_triangle_back(p0, p1, p2);
 			}
 		}
 	} else {
 		//GLint c_and = cc[0] & cc[1] & cc[2];
 		if ((cc[0] & cc[1] & cc[2]) == 0) { // Don't draw a triangle with no points
-			gl_draw_triangle_clip(c, p0, p1, p2, 0);
+			gl_draw_triangle_clip(p0, p1, p2, 0);
 		}
 	}
 }
 
 
-static void gl_draw_triangle_clip(GLContext* c, GLVertex* p0, GLVertex* p1, GLVertex* p2, GLint clip_bit) {
+static void gl_draw_triangle_clip(GLVertex* p0, GLVertex* p1, GLVertex* p2, GLint clip_bit) {
+	//GLContext* c = gl_get_context();
 	GLint co, c_and, co1, cc[3], edge_flag_tmp, clip_mask;
 	//GLVertex tmp1, tmp2, *q[3];
 	GLVertex *q[3];
@@ -301,7 +304,7 @@
 
 	co = cc[0] | cc[1] | cc[2];
 	if (co == 0) {
-		gl_draw_triangle(c, p0, p1, p2);
+		gl_draw_triangle(p0, p1, p2);
 	} else {
 		
 		c_and = cc[0] & cc[1] & cc[2];
@@ -343,20 +346,20 @@
 			}
 			{GLVertex tmp1, tmp2;GLfloat tt;
 				tt = clip_proc[clip_bit](&tmp1.pc, &q[0]->pc, &q[1]->pc);
-				updateTmp(c, &tmp1, q[0], q[1], tt);
+				updateTmp(&tmp1, q[0], q[1], tt);
 
 				tt = clip_proc[clip_bit](&tmp2.pc, &q[0]->pc, &q[2]->pc);
-				updateTmp(c, &tmp2, q[0], q[2], tt);
+				updateTmp(&tmp2, q[0], q[2], tt);
 
 				tmp1.edge_flag = q[0]->edge_flag;
 				edge_flag_tmp = q[2]->edge_flag;
 				q[2]->edge_flag = 0;
-				gl_draw_triangle_clip(c, &tmp1, q[1], q[2], clip_bit + 1);
+				gl_draw_triangle_clip(&tmp1, q[1], q[2], clip_bit + 1);
 
 				tmp2.edge_flag = 1;
 				tmp1.edge_flag = 0;
 				q[2]->edge_flag = edge_flag_tmp;
-				gl_draw_triangle_clip(c, &tmp2, &tmp1, q[2], clip_bit + 1);
+				gl_draw_triangle_clip(&tmp2, &tmp1, q[2], clip_bit + 1);
 			}
 		} else {
 			/* two points outside */
@@ -376,14 +379,14 @@
 			}
 			{GLVertex tmp1, tmp2;GLfloat tt;
 				tt = clip_proc[clip_bit](&tmp1.pc, &q[0]->pc, &q[1]->pc);
-				updateTmp(c, &tmp1, q[0], q[1], tt);
+				updateTmp(&tmp1, q[0], q[1], tt);
 
 				tt = clip_proc[clip_bit](&tmp2.pc, &q[0]->pc, &q[2]->pc);
-				updateTmp(c, &tmp2, q[0], q[2], tt);
+				updateTmp(&tmp2, q[0], q[2], tt);
 
 				tmp1.edge_flag = 1;
 				tmp2.edge_flag = q[2]->edge_flag;
-				gl_draw_triangle_clip(c, q[0], &tmp1, &tmp2, clip_bit + 1);
+				gl_draw_triangle_clip(q[0], &tmp1, &tmp2, clip_bit + 1);
 			}
 		}
 	}
@@ -396,12 +399,13 @@
 
 
 //see vertex.c to see how the draw functions are assigned.
-void gl_draw_triangle_select(GLContext* c, GLVertex* p0, GLVertex* p1, GLVertex* p2) { 
-	gl_add_select1(c, p0->zp.z, p1->zp.z, p2->zp.z); 
+void gl_draw_triangle_select(GLVertex* p0, GLVertex* p1, GLVertex* p2) { 
+	gl_add_select1(p0->zp.z, p1->zp.z, p2->zp.z); 
 }
-void gl_draw_triangle_feedback(GLContext* c, GLVertex* p0, GLVertex* p1, GLVertex* p2){
+void gl_draw_triangle_feedback(GLVertex* p0, GLVertex* p1, GLVertex* p2){
+	//GLContext* c = gl_get_context();
 	gl_add_feedback(
-					c,	GL_POLYGON_TOKEN,
+					GL_POLYGON_TOKEN,
 					p0,
 					p1,
 					p2,
@@ -415,8 +419,8 @@
 #endif
 
 //see vertex.c to see how the draw functions are assigned.
-void gl_draw_triangle_fill(GLContext* c, GLVertex* p0, GLVertex* p1, GLVertex* p2) { //Must be function pointer!
-
+void gl_draw_triangle_fill( GLVertex* p0, GLVertex* p1, GLVertex* p2) { //Must be function pointer!
+	GLContext* c = gl_get_context();
 	if (c->texture_2d_enabled) {
 		//if(c->current_texture)
 #if TGL_FEATURE_LIT_TEXTURES == 1
@@ -468,7 +472,8 @@
 
 /* Render a clipped triangle in line mode */
 
-void gl_draw_triangle_line(GLContext* c, GLVertex* p0, GLVertex* p1, GLVertex* p2) {
+void gl_draw_triangle_line(GLVertex* p0, GLVertex* p1, GLVertex* p2) {
+	GLContext* c = gl_get_context();
 	if (c->zb->depth_test) {
 		if (p0->edge_flag)
 			ZB_line_z(c->zb, &p0->zp, &p1->zp);
@@ -487,7 +492,8 @@
 }
 
 /* Render a clipped triangle in point mode */
-void gl_draw_triangle_point(GLContext* c, GLVertex* p0, GLVertex* p1, GLVertex* p2) {
+void gl_draw_triangle_point(GLVertex* p0, GLVertex* p1, GLVertex* p2) {
+	GLContext* c = gl_get_context();
 	if (p0->edge_flag)
 		ZB_plot(c->zb, &p0->zp);
 	if (p1->edge_flag)
--- a/src/init.c
+++ b/src/init.c
@@ -14,7 +14,7 @@
 	s->buffers = gl_zalloc(sizeof(GLBuffer*) * MAX_BUFFERS);
 	if(!s->buffers)
 		gl_fatal_error("TINYGL_CANNOT_INIT_OOM");
-	alloc_texture(c, 0);
+	alloc_texture(0);
 #include "error_check.h"
 }
 
--- a/src/light.c
+++ b/src/light.c
@@ -3,7 +3,8 @@
 
 
 
-void glopMaterial(GLContext* c, GLParam* p) {
+void glopMaterial(GLParam* p) {
+	GLContext* c = gl_get_context();
 	GLint mode = p[1].i;
 	GLint type = p[2].i;
 	GLfloat v[4];
@@ -16,7 +17,7 @@
 
 	if (mode == GL_FRONT_AND_BACK) {
 		p[1].i = GL_FRONT;
-		glopMaterial(c, p);
+		glopMaterial(p);
 		mode = GL_BACK;
 	}
 	if (mode == GL_FRONT)
@@ -65,7 +66,8 @@
 	}
 }
 
-void glopColorMaterial(GLContext* c, GLParam* p) {
+void glopColorMaterial(GLParam* p) {
+	GLContext* c = gl_get_context();
 	GLint mode = p[1].i;
 	GLint type = p[2].i;
 
@@ -73,7 +75,8 @@
 	c->current_color_material_type = type;
 }
 
-void glopLight(GLContext* c, GLParam* p) {
+void glopLight(GLParam* p) {
+	GLContext* c = gl_get_context();
 	GLint light = p[1].i;
 	GLint type = p[2].i;
 	V4 v;
@@ -167,7 +170,8 @@
 	}
 }
 
-void glopLightModel(GLContext* c, GLParam* p) {
+void glopLightModel( GLParam* p) {
+	GLContext* c = gl_get_context();
 	GLint pname = p[1].i;
 	GLint* v = &p[2].i;
 	GLint i;
@@ -196,7 +200,8 @@
 
 
 
-void gl_enable_disable_light(GLContext* c, GLint light, GLint v) {
+void gl_enable_disable_light(GLint light, GLint v) {
+	GLContext* c = gl_get_context();
 	GLLight* l = &c->lights[light];
 	if (v && !l->enabled) {
 		l->enabled = 1;
@@ -221,7 +226,8 @@
 	gl_get_context()->zEnableSpecular = s; 
 }
 /* non optimized lightening model */
-void gl_shade_vertex(GLContext* c, GLVertex* v) {
+void gl_shade_vertex(GLVertex* v) {
+	GLContext* c = gl_get_context();
 	GLfloat R, G, B, A;
 	GLMaterial* m;
 	GLLight* l;
--- a/src/list.c
+++ b/src/list.c
@@ -8,7 +8,8 @@
 #include "opinfo.h"
 };
 */
-void (*op_table_func[])(GLContext*, GLParam*) = {
+//void (*op_table_func[])(GLContext*, GLParam*) 
+void (*op_table_func[])(GLParam*) = {
 #define ADD_OP(a, b, c) glop##a,
 
 #include "opinfo.h"
@@ -22,13 +23,14 @@
 
 
 
-static inline GLList* find_list(GLContext* c, GLuint list) { return c->shared_state.lists[list]; }
+static inline GLList* find_list(GLuint list) { return gl_get_context()->shared_state.lists[list]; }
 
-static void delete_list(GLContext* c, GLint list) {
+static void delete_list( GLint list) {
+	GLContext* c = gl_get_context();
 	GLParamBuffer *pb, *pb1;
 	GLList* l;
 
-	l = find_list(c, list);
+	l = find_list(list);
 	if (l == NULL) { //MARK <COST>
 		return;
 	}
@@ -52,10 +54,11 @@
 }
 void glDeleteList(GLuint list) { 
 #include "error_check_no_context.h"
-delete_list(gl_get_context(), list); 
+delete_list( list); 
 }
 
-static GLList* alloc_list(GLContext* c, GLint list) {
+static GLList* alloc_list( GLint list) {
+	GLContext* c = gl_get_context();
 	GLList* l;
 	GLParamBuffer* ob;
 #define RETVAL NULL
@@ -131,7 +134,8 @@
 	for(GLint i = 0; i < n; i++)
 		glCallList(c->listbase + lists[i]);
 }
-void gl_compile_op(GLContext* c, GLParam* p) {
+void gl_compile_op(GLParam* p) {
+	GLContext* c = gl_get_context();
 	GLint op, op_size;
 	GLParamBuffer *ob, *ob1;
 	GLint index, i;
@@ -172,17 +176,18 @@
 	c->current_op_buffer_index = index;
 }
 /* this opcode is never called directly */
-void glopEndList(GLContext* c, GLParam* p) { exit(1); }
+void glopEndList(GLParam* p) { exit(1); }
 
 /* this opcode is never called directly */
-void glopNextBuffer(GLContext* c, GLParam* p) { exit(1); }
+void glopNextBuffer(GLParam* p) { exit(1); }
 
-void glopCallList(GLContext* c, GLParam* p) {
+void glopCallList(GLParam* p) {
+	//GLContext* c = gl_get_context();
 	GLList* l;
 	GLint list;
 #include "error_check.h"
 	list = p[1].ui;
-	l = find_list(c, list);
+	l = find_list(list);
 
 #if TGL_FEATURE_ERROR_CHECK == 1
 	if (l == NULL) {gl_fatal_error("Bad list op, not defined");}
@@ -199,7 +204,7 @@
 		if (op == OP_NextBuffer) {
 			p = (GLParam*)p[1].p;
 		} else {
-			op_table_func[op](c, p);
+			op_table_func[op](p);
 			p += op_table_size[op];
 		}
 	}
@@ -224,9 +229,9 @@
 	//assert(mode == GL_COMPILE || mode == GL_COMPILE_AND_EXECUTE); //MARK <COST>
 	//assert(c->compile_flag == 0); //MARK <COST>
 #endif
-	l = find_list(c, list);
-	if (l != NULL) delete_list(c, list);
-	l = alloc_list(c, list);
+	l = find_list(list);
+	if (l != NULL) delete_list(list);
+	l = alloc_list(list);
 #include "error_check.h"
 #if TGL_FEATURE_ERROR_CHECK == 1
 	if(l==NULL)
@@ -257,7 +262,7 @@
 #endif
 	/* end of list */
 	p[0].op = OP_EndList;
-	gl_compile_op(c, p);
+	gl_compile_op(p);
 
 	c->compile_flag = 0;
 	c->exec_flag = 1;
@@ -264,9 +269,9 @@
 }
 
 GLint glIsList(GLuint list) {
-	GLContext* c = gl_get_context();
+	//GLContext* c = gl_get_context();
 	GLList* l;
-	l = find_list(c, list);
+	l = find_list(list);
 	return (l != NULL);
 }
 
@@ -284,7 +289,7 @@
 			if (count == range) {
 				list = i - range + 1;
 				for (i = 0; i < range; i++) {
-					alloc_list(c, list + i);
+					alloc_list(list + i);
 				}
 				return list;
 			}
--- a/src/matrix.c
+++ b/src/matrix.c
@@ -8,9 +8,10 @@
 	}
 }
 
-static inline void gl_matrix_update(GLContext* c) { c->matrix_model_projection_updated = (c->matrix_mode <= 1); }
+static inline void gl_matrix_update() { GLContext* c = gl_get_context(); c->matrix_model_projection_updated = (c->matrix_mode <= 1); }
 
-void glopMatrixMode(GLContext* c, GLParam* p) {
+void glopMatrixMode( GLParam* p) {
+	GLContext* c = gl_get_context();
 	GLint mode = p[1].i;
 	switch (mode) {
 	case GL_MODELVIEW:
@@ -27,7 +28,8 @@
 	}
 }
 
-void glopLoadMatrix(GLContext* c, GLParam* p) {
+void glopLoadMatrix(GLParam* p) {
+	GLContext* c = gl_get_context();
 	M4* m;
 	GLint i;
 
@@ -47,7 +49,8 @@
 	gl_matrix_update(c);
 }
 
-void glopLoadIdentity(GLContext* c, GLParam* p) {
+void glopLoadIdentity(GLParam* p) {
+	GLContext* c = gl_get_context();
 
 	gl_M4_Id(c->matrix_stack_ptr[c->matrix_mode]);
 
@@ -54,7 +57,8 @@
 	gl_matrix_update(c);
 }
 
-void glopMultMatrix(GLContext* c, GLParam* p) {
+void glopMultMatrix(GLParam* p) {
+	GLContext* c = gl_get_context();
 	M4 m;
 	GLint i;
 
@@ -74,7 +78,8 @@
 	gl_matrix_update(c);
 }
 
-void glopPushMatrix(GLContext* c, GLParam* p) {
+void glopPushMatrix( GLParam* p) {
+	GLContext* c = gl_get_context();
 	GLint n = c->matrix_mode;
 	M4* m;
 
@@ -91,7 +96,8 @@
 	gl_matrix_update(c);
 }
 
-void glopPopMatrix(GLContext* c, GLParam* p) {
+void glopPopMatrix( GLParam* p) {
+	GLContext* c = gl_get_context();
 	GLint n = c->matrix_mode;
 
 	//assert(c->matrix_stack_ptr[n] > c->matrix_stack[n]);
@@ -107,7 +113,8 @@
 
 
 
-void glopRotate(GLContext* c, GLParam* p) {
+void glopRotate(GLParam* p) {
+	GLContext* c = gl_get_context();
 	M4 m;
 	GLfloat u[3];
 	GLfloat angle;
@@ -185,7 +192,8 @@
 	gl_matrix_update(c);
 }
 
-void glopScale(GLContext* c, GLParam* p) {
+void glopScale(GLParam* p) {
+	GLContext* c = gl_get_context();
 	GLfloat* m;
 	GLfloat x = p[1].f, y = p[2].f, z = p[3].f;
 
@@ -206,7 +214,8 @@
 	gl_matrix_update(c);
 }
 
-void glopTranslate(GLContext* c, GLParam* p) {
+void glopTranslate(GLParam* p) {
+	GLContext* c = gl_get_context();
 	GLfloat* m;
 	GLfloat x = p[1].f, y = p[2].f, z = p[3].f;
 
@@ -220,7 +229,8 @@
 	gl_matrix_update(c);
 }
 
-void glopFrustum(GLContext* c, GLParam* p) {
+void glopFrustum(GLParam* p) {
+	GLContext* c = gl_get_context();
 	GLfloat* r;
 	M4 m;
 	GLfloat left = p[1].f;
--- a/src/misc.c
+++ b/src/misc.c
@@ -14,7 +14,8 @@
 #endif
 }
 
-void glopViewport(GLContext* c, GLParam* p) {
+void glopViewport( GLParam* p) {
+	GLContext* c = gl_get_context();
 	GLint xsize, ysize, 
 			xmin, ymin, 
 			xsize_req, ysize_req;
@@ -31,7 +32,7 @@
 		xsize_req = xmin + xsize;
 		ysize_req = ymin + ysize;
 
-		if (c->gl_resize_viewport && c->gl_resize_viewport(c, &xsize_req, &ysize_req) != 0) {
+		if (c->gl_resize_viewport && c->gl_resize_viewport(&xsize_req, &ysize_req) != 0) {
 			gl_fatal_error("glViewport: error while resizing display");
 		}
 		if (xsize <= 0 || ysize <= 0) {
@@ -56,7 +57,8 @@
 	gl_add_op(p);
 	return;
 }
-void glopBlendFunc(GLContext* c, GLParam* p) {
+void glopBlendFunc( GLParam* p) {
+	GLContext* c = gl_get_context();
 	c->zb->sfactor = p[1].i;
 	c->zb->dfactor = p[2].i;
 }
@@ -69,9 +71,10 @@
 	p[1].i = mode;
 	gl_add_op(p);
 }
-void glopBlendEquation(GLContext* c, GLParam* p) { c->zb->blendeq = p[1].i; }
+void glopBlendEquation(GLParam* p) {GLContext* c = gl_get_context(); c->zb->blendeq = p[1].i; }
 
-void glopPointSize(GLContext* c, GLParam* p){
+void glopPointSize(GLParam* p){
+	GLContext* c = gl_get_context();
 	c->zb->pointsize = p[1].f;
 }
 void glPointSize(GLfloat f){
@@ -81,7 +84,8 @@
 	gl_add_op(p);
 }
 
-void glopEnableDisable(GLContext* c, GLParam* p) {
+void glopEnableDisable(GLParam* p) {
+	GLContext* c = gl_get_context();
 	GLint code = p[1].i;
 	GLint v = p[2].i;
 
@@ -132,7 +136,7 @@
 		break;
 	default:
 		if (code >= GL_LIGHT0 && code < GL_LIGHT0 + MAX_LIGHTS) {
-			gl_enable_disable_light(c, code - GL_LIGHT0, v);
+			gl_enable_disable_light(code - GL_LIGHT0, v);
 		} else {
 			tgl_warning("glEnableDisable: 0x%X not supported.\n",code);
 		}
@@ -140,22 +144,26 @@
 	}
 }
 
-void glopShadeModel(GLContext* c, GLParam* p) {
+void glopShadeModel(GLParam* p) {
+	GLContext* c = gl_get_context();
 	GLint code = p[1].i;
 	c->current_shade_model = code;
 }
 
-void glopCullFace(GLContext* c, GLParam* p) {
+void glopCullFace(GLParam* p) {
+	GLContext* c = gl_get_context();
 	GLint code = p[1].i;
 	c->current_cull_face = code;
 }
 
-void glopFrontFace(GLContext* c, GLParam* p) {
+void glopFrontFace(GLParam* p) {
+	GLContext* c = gl_get_context();
 	GLint code = p[1].i;
 	c->current_front_face = code;
 }
 
-void glopPolygonMode(GLContext* c, GLParam* p) {
+void glopPolygonMode(GLParam* p) {
+	GLContext* c = gl_get_context();
 	GLint face = p[1].i;
 	GLint mode = p[2].i;
 
@@ -175,7 +183,8 @@
 }
 
 
-void glopPolygonOffset(GLContext* c, GLParam* p) {
+void glopPolygonOffset( GLParam* p) {
+	GLContext* c = gl_get_context();
 	c->offset_factor = p[1].f;
 	c->offset_units = p[2].f;
 }
@@ -224,7 +233,7 @@
 	c->readbuffer = mode;
 }
 
-//Only ever reads pixels from the depth buffer
+//TODO
 void glReadPixels(	GLint x,
  	GLint y,
  	GLsizei width,
@@ -252,7 +261,7 @@
 		return;
 #endif
 	}
-	
+	//TODO: implement read pixels.
 }
 
 void glFinish(){
--- a/src/select.c
+++ b/src/select.c
@@ -118,12 +118,12 @@
 	c->feedback_type = type;
 }
 
-void gl_add_feedback(GLContext* c, GLfloat token,
+void gl_add_feedback(GLfloat token,
 										GLVertex* v1,
 										GLVertex* v2,
 										GLVertex* v3,
 										GLfloat passthrough_token_value
-){
+){GLContext* c = gl_get_context();
 	if(c->feedback_overflow) return;
 	GLuint feedback_hits_needed = 2;
 	GLuint vertex_feedback_hits_needed = 0;
@@ -237,11 +237,12 @@
 	return;
 }
 void glPassThrough(GLfloat token){
-GLContext* c = gl_get_context();
-#include "error_check.h"
-	gl_add_feedback(c,GL_PASS_THROUGH_TOKEN,NULL,NULL,NULL,token);
+//GLContext* c = gl_get_context(); //needed for error check.
+#include "error_check_no_context.h"
+	gl_add_feedback(GL_PASS_THROUGH_TOKEN,NULL,NULL,NULL,token);
 }
-void glopInitNames(GLContext* c, GLParam* p) {
+void glopInitNames(GLParam* p) {
+	GLContext* c = gl_get_context();
 	if (c->render_mode == GL_SELECT) {
 		c->name_stack_size = 0;
 		c->select_hit = NULL;
@@ -248,7 +249,8 @@
 	}
 }
 
-void glopPushName(GLContext* c, GLParam* p) {
+void glopPushName(GLParam* p) {
+	GLContext* c = gl_get_context();
 	if (c->render_mode == GL_SELECT) {
 		//assert(c->name_stack_size < MAX_NAME_STACK_DEPTH);
 		c->name_stack[c->name_stack_size++] = p[1].i;
@@ -261,7 +263,8 @@
 
 
 
-void glopPopName(GLContext* c, GLParam* p) {
+void glopPopName(GLParam* p) {
+	GLContext* c = gl_get_context();
 	if (c->render_mode == GL_SELECT) {
 		//assert(c->name_stack_size > 0);
 		c->name_stack_size--;
@@ -269,7 +272,8 @@
 	}
 }
 
-void glopLoadName(GLContext* c, GLParam* p) {
+void glopLoadName(GLParam* p) {
+	GLContext* c = gl_get_context();
 	if (c->render_mode == GL_SELECT) {
 		//assert(c->name_stack_size > 0);
 		c->name_stack[c->name_stack_size - 1] = p[1].i;
@@ -277,7 +281,8 @@
 	}
 }
 
-void gl_add_select(GLContext* c, GLuint zmin, GLuint zmax) {
+void gl_add_select(GLuint zmin, GLuint zmax) {
+	GLContext* c = gl_get_context();
 	GLuint* ptr;
 	GLint n, i;
 
--- a/src/texture.c
+++ b/src/texture.c
@@ -4,7 +4,8 @@
 
 #include "zgl.h"
 
-static GLTexture* find_texture(GLContext* c, GLint h) {
+static GLTexture* find_texture(GLint h) {
+	GLContext* c = gl_get_context();
 	GLTexture* t;
 	t = c->shared_state.texture_hash_table[h & TEXTURE_HASH_TABLE_MASK];
 	while (t != NULL) {
@@ -18,12 +19,12 @@
 GLboolean glAreTexturesResident(	GLsizei n,
 								 	const GLuint * textures,
 								 	GLboolean * residences){
-GLContext* c = gl_get_context();
+//GLContext* c = gl_get_context();
 #define RETVAL GL_FALSE
 #include "error_check.h"
 GLboolean retval = GL_TRUE;
 	for(GLint i = 0; i < n; i++)
-		if(find_texture(c, textures[i]))
+		if(find_texture(textures[i]))
 			{residences[i] = GL_TRUE;}
 		else
 			{residences[i] = GL_FALSE;retval = GL_FALSE;}
@@ -33,7 +34,7 @@
 	GLContext* c = gl_get_context();
 #define RETVAL GL_FALSE
 #include "error_check.h"
-	if(find_texture(c, texture))
+	if(find_texture(texture))
 		return GL_TRUE;
 	return GL_FALSE;
 }
@@ -49,7 +50,7 @@
 #else
 	//assert(text >= 0 && level < MAX_TEXTURE_LEVELS);
 #endif
-	tex = find_texture(c, text);
+	tex = find_texture(text);
 	if (!tex)
 #if TGL_FEATURE_ERROR_CHECK == 1
 #define ERROR_FLAG GL_INVALID_ENUM
@@ -66,7 +67,7 @@
 static void free_texture(GLContext* c, GLint h) {
 	GLTexture *t, **ht;
 
-	t = find_texture(c, h);
+	t = find_texture(h);
 	if (t->prev == NULL) {
 		ht = &c->shared_state.texture_hash_table[t->handle & TEXTURE_HASH_TABLE_MASK];
 		*ht = t->next;
@@ -85,7 +86,8 @@
 	gl_free(t);
 }
 
-GLTexture* alloc_texture(GLContext* c, GLint h) {
+GLTexture* alloc_texture(GLint h) {
+	GLContext* c = gl_get_context();
 	GLTexture *t, **ht;
 #define RETVAL NULL
 #include "error_check.h"
@@ -112,11 +114,11 @@
 	return t;
 }
 
-void glInitTextures(GLContext* c) {
+void glInitTextures() {
 	/* textures */
-
+	GLContext* c = gl_get_context();
 	c->texture_2d_enabled = 0;
-	c->current_texture = find_texture(c, 0);
+	c->current_texture = find_texture(0);
 }
 
 void glGenTextures(GLint n, GLuint* textures) {
@@ -145,7 +147,7 @@
 #include "error_check.h"
 	for (i = 0; i < n; i++) {
 
-		t = find_texture(c, textures[i]);
+		t = find_texture(textures[i]);
 		if (t != NULL && t != 0) {
 			if (t == c->current_texture) {
 				glBindTexture(GL_TEXTURE_2D, 0);
@@ -156,7 +158,8 @@
 	}
 }
 
-void glopBindTexture(GLContext* c, GLParam* p) {
+void glopBindTexture(GLParam* p) {
+	GLContext* c = gl_get_context();
 	GLint target = p[1].i;
 	GLint texture = p[2].i;
 	GLTexture* t;
@@ -167,9 +170,9 @@
 #else
 	//assert(target == GL_TEXTURE_2D && target > 0);
 #endif
-	t = find_texture(c, texture);
+	t = find_texture(texture);
 	if (t == NULL) {
-		t = alloc_texture(c, texture);
+		t = alloc_texture(texture);
 #include "error_check.h"
 	}
 	if(t == NULL) { //Failed malloc.
@@ -196,8 +199,8 @@
  	GLsizei height,
  	GLint border)
 {
-	GLContext* c = gl_get_context();
-#include "error_check.h"
+	//GLContext* c = gl_get_context();
+#include "error_check_no_context.h"
 	GLParam p[9];
 	p[0].op = OP_CopyTexImage2D;
 	p[1].i = target;
@@ -210,7 +213,8 @@
 	p[8].i = border;
 	gl_add_op(p);
 }
-void glopCopyTexImage2D(GLContext* c, GLParam* p){
+void glopCopyTexImage2D(GLParam* p){
+	GLContext* c = gl_get_context();
 	GLint target = p[1].i;
 	GLint level = p[2].i;
 	//GLenum internalformat = p[3].i;
@@ -258,7 +262,7 @@
 #endif
 }
 
-void glopTexImage1D(GLContext* c, GLParam* p){
+void glopTexImage1D( GLParam* p){
 	GLint target = p[1].i;
 	GLint level = p[2].i;
 	GLint components = p[3].i;
@@ -272,16 +276,16 @@
 	GLImage* im;
 	GLubyte* pixels1;
 	GLint do_free;
-
+	GLContext* c = gl_get_context();
 	{
 #if TGL_FEATURE_ERROR_CHECK == 1
-	if (!(c->current_texture != NULL && target == GL_TEXTURE_1D && level == 0 && components == 3 && border == 0 && format == GL_RGB && type == GL_UNSIGNED_BYTE))
+		if (!(c->current_texture != NULL && target == GL_TEXTURE_1D && level == 0 && components == 3 && border == 0 && format == GL_RGB && type == GL_UNSIGNED_BYTE))
 #define ERROR_FLAG GL_INVALID_ENUM
 #include "error_check.h"
 
 #else
-	if (!(c->current_texture != NULL && target == GL_TEXTURE_1D && level == 0 && components == 3 && border == 0 && format == GL_RGB && type == GL_UNSIGNED_BYTE))
-		gl_fatal_error("glTexImage2D: combination of parameters not handled!!");
+		if (!(c->current_texture != NULL && target == GL_TEXTURE_1D && level == 0 && components == 3 && border == 0 && format == GL_RGB && type == GL_UNSIGNED_BYTE))
+			gl_fatal_error("glTexImage2D: combination of parameters not handled!!");
 #endif
 	}
 	if (width != TGL_FEATURE_TEXTURE_DIM || height != TGL_FEATURE_TEXTURE_DIM) {
@@ -319,7 +323,7 @@
 	if (do_free)
 		gl_free(pixels1);
 }
-void glopTexImage2D(GLContext* c, GLParam* p) {
+void glopTexImage2D(GLParam* p) {
 	GLint target = p[1].i;
 	GLint level = p[2].i;
 	GLint components = p[3].i;
@@ -332,7 +336,7 @@
 	GLImage* im;
 	GLubyte* pixels1;
 	GLint do_free;
-
+	GLContext* c = gl_get_context();
 	 {
 #if TGL_FEATURE_ERROR_CHECK == 1
 	if (!(c->current_texture != NULL && target == GL_TEXTURE_2D && level == 0 && components == 3 && border == 0 && format == GL_RGB && type == GL_UNSIGNED_BYTE))
--- a/src/vertex.c
+++ b/src/vertex.c
@@ -1,8 +1,8 @@
 #include "zgl.h"
 #include <string.h>
-void glopNormal(GLContext* c, GLParam* p) {
+void glopNormal(GLParam* p) {
 	V3 v;
-
+	GLContext* c = gl_get_context();
 	v.X = p[1].f;
 	v.Y = p[2].f;
 	v.Z = p[3].f;
@@ -13,7 +13,8 @@
 	c->current_normal.W = 0;
 }
 
-void glopTexCoord(GLContext* c, GLParam* p) {
+void glopTexCoord( GLParam* p) {
+	GLContext* c = gl_get_context();
 	c->current_tex_coord.X = p[1].f;
 	c->current_tex_coord.Y = p[2].f;
 	c->current_tex_coord.Z = p[3].f;
@@ -20,10 +21,10 @@
 	c->current_tex_coord.W = p[4].f;
 }
 
-void glopEdgeFlag(GLContext* c, GLParam* p) { c->current_edge_flag = p[1].i; }
+void glopEdgeFlag(GLParam* p) {GLContext* c = gl_get_context(); c->current_edge_flag = p[1].i; }
 
-void glopColor(GLContext* c, GLParam* p) {
-
+void glopColor(GLParam* p) {
+	GLContext* c = gl_get_context();
 	c->current_color.X = p[1].f;
 	c->current_color.Y = p[2].f;
 	c->current_color.Z = p[3].f;
@@ -38,11 +39,12 @@
 		q[4].f = p[2].f;
 		q[5].f = p[3].f;
 		q[6].f = p[4].f;
-		glopMaterial(c, q);
+		glopMaterial(q);
 	}
 }
 
-void gl_eval_viewport(GLContext* c) {
+void gl_eval_viewport() {
+	GLContext* c = gl_get_context();
 	GLViewport* v;
 	GLfloat zsize = (1 << (ZB_Z_BITS + ZB_POINT_Z_FRAC_BITS));
 
@@ -57,7 +59,8 @@
 	v->scale.Z = -((zsize - 0.5) / 2.0);
 }
 
-void glopBegin(GLContext* c, GLParam* p) {
+void glopBegin(GLParam* p) {
+	GLContext* c = gl_get_context();
 	GLint type;
 	M4 tmp;
 #if TGL_FEATURE_ERROR_CHECK == 1
@@ -134,7 +137,8 @@
 	}
 }
 
-static inline void gl_transform_to_viewport_vertex_c(GLContext* c, GLVertex* v) {
+static inline void gl_transform_to_viewport_vertex_c(GLVertex* v) {
+	GLContext* c = gl_get_context();
 
 	
 	{
@@ -156,9 +160,9 @@
 	}
 }
 
-static inline void gl_vertex_transform(GLContext* c, GLVertex* v) {
+static inline void gl_vertex_transform(GLVertex* v) {
 	GLfloat* m;
-	
+	GLContext* c = gl_get_context();
 
 	if (c->lighting_enabled) {
 		/* eye coordinates needed for lighting */
@@ -204,10 +208,10 @@
 	v->clip_code = gl_clipcode(v->pc.X, v->pc.Y, v->pc.Z, v->pc.W);
 }
 
-void glopVertex(GLContext* c, GLParam* p) {
+void glopVertex(GLParam* p) {
 	GLVertex* v;
 	GLint n, i, cnt;
-
+	GLContext* c = gl_get_context();
 #if TGL_FEATURE_ERROR_CHECK == 1
 	if(c->in_begin == 0)
 #define ERROR_FLAG GL_INVALID_OPERATION
@@ -248,12 +252,12 @@
 	v->coord.Z = p[3].f;
 	v->coord.W = p[4].f;
 
-	gl_vertex_transform(c, v);
+	gl_vertex_transform( v);
 
 	/* color */
 
 	if (c->lighting_enabled) {
-		gl_shade_vertex(c, v);
+		gl_shade_vertex(v);
 #include "error_check.h"
 //^ Don't proceed on an OUT OF MEMORY error.
 	} else {
@@ -274,7 +278,7 @@
 	}
 	/* precompute the mapping to the viewport */
 	if (v->clip_code == 0)
-		gl_transform_to_viewport_vertex_c(c, v);
+		gl_transform_to_viewport_vertex_c(v);
 
 	/* edge flag */
 	v->edge_flag = c->current_edge_flag;
@@ -281,13 +285,13 @@
 
 	switch (c->begin_type) {
 		case GL_POINTS:
-			gl_draw_point(c, &c->vertex[0]);
+			gl_draw_point(&c->vertex[0]);
 			n = 0;
 			break;
 
 		case GL_LINES:
 			if (n == 2) {
-				gl_draw_line(c, &c->vertex[0], &c->vertex[1]);
+				gl_draw_line(&c->vertex[0], &c->vertex[1]);
 				n = 0;
 			}
 			break;
@@ -301,7 +305,7 @@
 					break;
 				case 2:
 					{
-						gl_draw_line(c, &c->vertex[0], &c->vertex[1]);
+						gl_draw_line(&c->vertex[0], &c->vertex[1]);
 						c->vertex[0] = c->vertex[1];
 						n = 1;
 					}
@@ -312,7 +316,7 @@
 			break;
 		case GL_TRIANGLES:
 			if (n == 3) {
-				gl_draw_triangle(c, &c->vertex[0], &c->vertex[1], &c->vertex[2]);
+				gl_draw_triangle(&c->vertex[0], &c->vertex[1], &c->vertex[2]);
 				n = 0;
 			}
 			break;
@@ -323,11 +327,11 @@
 				/* needed to respect triangle orientation */
 				switch (cnt & 1) {
 				case 0:
-					gl_draw_triangle(c, &c->vertex[2], &c->vertex[1], &c->vertex[0]);
+					gl_draw_triangle(&c->vertex[2], &c->vertex[1], &c->vertex[0]);
 					break;
 				default:
 				case 1:
-					gl_draw_triangle(c, &c->vertex[0], &c->vertex[1], &c->vertex[2]);
+					gl_draw_triangle(&c->vertex[0], &c->vertex[1], &c->vertex[2]);
 					break;
 				}
 			}
@@ -334,7 +338,7 @@
 			break;
 		case GL_TRIANGLE_FAN:
 			if (n == 3) {
-				gl_draw_triangle(c, &c->vertex[0], &c->vertex[1], &c->vertex[2]);
+				gl_draw_triangle(&c->vertex[0], &c->vertex[1], &c->vertex[2]);
 				c->vertex[1] = c->vertex[2];
 				n = 2;
 			}
@@ -343,10 +347,10 @@
 		case GL_QUADS:
 			if (n == 4) {
 				c->vertex[2].edge_flag = 0;
-				gl_draw_triangle(c, &c->vertex[0], &c->vertex[1], &c->vertex[2]);
+				gl_draw_triangle(&c->vertex[0], &c->vertex[1], &c->vertex[2]);
 				c->vertex[2].edge_flag = 1;
 				c->vertex[0].edge_flag = 0;
-				gl_draw_triangle(c, &c->vertex[0], &c->vertex[2], &c->vertex[3]);
+				gl_draw_triangle(&c->vertex[0], &c->vertex[2], &c->vertex[3]);
 				n = 0;
 			}
 			break;
@@ -353,8 +357,8 @@
 
 		case GL_QUAD_STRIP:
 			if (n == 4) {
-				gl_draw_triangle(c, &c->vertex[0], &c->vertex[1], &c->vertex[2]);
-				gl_draw_triangle(c, &c->vertex[1], &c->vertex[3], &c->vertex[2]);
+				gl_draw_triangle(&c->vertex[0], &c->vertex[1], &c->vertex[2]);
+				gl_draw_triangle(&c->vertex[1], &c->vertex[3], &c->vertex[2]);
 				for (i = 0; i < 2; i++)
 					c->vertex[i] = c->vertex[i + 2];
 				n = 2;
@@ -375,7 +379,8 @@
 	c->vertex_n = n;
 }
 
-void glopEnd(GLContext* c, GLParam* param) {
+void glopEnd(GLParam* param) {
+	GLContext* c = gl_get_context();
 #if TGL_FEATURE_ERROR_CHECK == 1
 	if(c->in_begin != 1)
 #define ERROR_FLAG GL_INVALID_OPERATION
@@ -387,7 +392,7 @@
 //#if TGL_FEATURE_GL_POLYGON == 1
 	if (c->begin_type == GL_LINE_LOOP) {
 		if (c->vertex_cnt >= 3) {
-			gl_draw_line(c, &c->vertex[0], &c->vertex[2]);
+			gl_draw_line(&c->vertex[0], &c->vertex[2]);
 		}
 	}
 //#endif
@@ -396,7 +401,7 @@
 		GLint i = c->vertex_cnt;
 		while (i >= 3) {
 			i--;
-			gl_draw_triangle(c, &c->vertex[i], &c->vertex[0], &c->vertex[i - 1]);
+			gl_draw_triangle(&c->vertex[i], &c->vertex[0], &c->vertex[i - 1]);
 		}
 	}
 #endif 
--- a/src/zgl.h
+++ b/src/zgl.h
@@ -169,7 +169,7 @@
 
 struct GLContext;
 
-typedef void (*gl_draw_triangle_func)(struct GLContext* c, GLVertex* p0, GLVertex* p1, GLVertex* p2);
+typedef void (*gl_draw_triangle_func)(GLVertex* p0, GLVertex* p1, GLVertex* p2);
 
 /* display context */
 
@@ -305,7 +305,7 @@
 	/* opaque structure for user's use */
 	void* opaque;
 	/* resize viewport function */
-	GLint (*gl_resize_viewport)(struct GLContext* c, GLint* xsize, GLint* ysize);
+	GLint (*gl_resize_viewport)(GLint* xsize, GLint* ysize);
 
 	/* depth test */
 	//Moved to Zbuffer.
@@ -330,9 +330,9 @@
 extern GLContext gl_ctx;
 static inline GLContext* gl_get_context(void) { return &gl_ctx; }
 //void gl_add_op(GLParam* p);
-extern void (*op_table_func[])(GLContext*, GLParam*);
+extern void (*op_table_func[])(GLParam*);
 extern GLint op_table_size[];
-extern void gl_compile_op(GLContext* c, GLParam* p);
+extern void gl_compile_op(GLParam* p);
 static inline void gl_add_op(GLParam* p) {
 	GLContext* c = gl_get_context();
 #if TGL_FEATURE_ERROR_CHECK == 1
@@ -341,13 +341,13 @@
 	GLint op;
 	op = p[0].op;
 	if (c->exec_flag) {
-		op_table_func[op](c, p);
+		op_table_func[op](p);
 #if TGL_FEATURE_ERROR_CHECK == 1
 #include "error_check.h"
 #endif
 	}
 	if (c->compile_flag) {
-		gl_compile_op(c, p);
+		gl_compile_op( p);
 #if TGL_FEATURE_ERROR_CHECK == 1
 #include "error_check.h"
 #endif
@@ -358,8 +358,8 @@
 }
 
 /* select.c */
-void gl_add_select(GLContext* c, GLuint zmin, GLuint zmax);
-void gl_add_feedback(GLContext* c, GLfloat token,
+void gl_add_select( GLuint zmin, GLuint zmax);
+void gl_add_feedback( GLfloat token,
 										GLVertex* v1,
 										GLVertex* v2,
 										GLVertex* v3,
@@ -394,8 +394,8 @@
 }
 
 
-//void gl_transform_to_viewport(GLContext* c, GLVertex* v);
-//inline void gl_draw_triangle(GLContext* c, GLVertex* p0, GLVertex* p1, GLVertex* p2);
+//void gl_transform_to_viewport( GLVertex* v);
+//inline void gl_draw_triangle( GLVertex* p0, GLVertex* p1, GLVertex* p2);
 
 /* triangle */
 
@@ -410,33 +410,33 @@
 
 
 
-//inline void gl_draw_triangle_clip(GLContext* c, GLVertex* p0, GLVertex* p1, GLVertex* p2, GLint clip_bit);
+//inline void gl_draw_triangle_clip( GLVertex* p0, GLVertex* p1, GLVertex* p2, GLint clip_bit);
 
-void gl_draw_triangle(GLContext* c, GLVertex* p0, GLVertex* p1, GLVertex* p2);
-void gl_draw_line(GLContext* c, GLVertex* p0, GLVertex* p1);
-void gl_draw_point(GLContext* c, GLVertex* p0);
+void gl_draw_triangle( GLVertex* p0, GLVertex* p1, GLVertex* p2);
+void gl_draw_line( GLVertex* p0, GLVertex* p1);
+void gl_draw_point( GLVertex* p0);
 
 
-void gl_draw_triangle_point(GLContext* c, GLVertex* p0, GLVertex* p1, GLVertex* p2); //MUST BE FUNCTION POINTER
-void gl_draw_triangle_line(GLContext* c, GLVertex* p0, GLVertex* p1, GLVertex* p2); //MUST BE FUNCTION POINTER
-void gl_draw_triangle_fill(GLContext* c, GLVertex* p0, GLVertex* p1, GLVertex* p2); //MUST BE FUNCTION POINTER
-void gl_draw_triangle_select(GLContext* c, GLVertex* p0, GLVertex* p1, GLVertex* p2); //MUST BE FUNCTION POINTER
-void gl_draw_triangle_feedback(GLContext* c, GLVertex* p0, GLVertex* p1, GLVertex* p2); //MUST BE FUNCTION POINTER
+void gl_draw_triangle_point( GLVertex* p0, GLVertex* p1, GLVertex* p2); //MUST BE FUNCTION POINTER
+void gl_draw_triangle_line( GLVertex* p0, GLVertex* p1, GLVertex* p2); //MUST BE FUNCTION POINTER
+void gl_draw_triangle_fill( GLVertex* p0, GLVertex* p1, GLVertex* p2); //MUST BE FUNCTION POINTER
+void gl_draw_triangle_select( GLVertex* p0, GLVertex* p1, GLVertex* p2); //MUST BE FUNCTION POINTER
+void gl_draw_triangle_feedback( GLVertex* p0, GLVertex* p1, GLVertex* p2); //MUST BE FUNCTION POINTER
 /* matrix.c */
 void gl_print_matrix(const GLfloat* m);
 /*
-void glopLoadIdentity(GLContext *c,GLParam *p);
-void glopTranslate(GLContext *c,GLParam *p);*/
+void glopLoadIdentity(GLParam *p);
+void glopTranslate(GLParam *p);*/
 
 
 
 /* light.c */
-void gl_enable_disable_light(GLContext* c, GLint light, GLint v);
-void gl_shade_vertex(GLContext* c, GLVertex* v);
+void gl_enable_disable_light( GLint light, GLint v);
+void gl_shade_vertex(GLVertex* v);
 
-void glInitTextures(GLContext* c);
-void glEndTextures(GLContext* c);
-GLTexture* alloc_texture(GLContext* c, GLint h);
+void glInitTextures();
+void glEndTextures();
+GLTexture* alloc_texture( GLint h);
 
 /* image_util.c */
 void gl_convertRGB_to_5R6G5B(GLushort* pixmap, GLubyte* rgb, GLint xsize, GLint ysize);
@@ -449,7 +449,7 @@
 void gl_fatal_error(char* format, ...);
 
 /* specular buffer "api" */
-GLSpecBuf* specbuf_get_buffer(GLContext* c, const GLint shininess_i, const GLfloat shininess);
+GLSpecBuf* specbuf_get_buffer( const GLint shininess_i, const GLfloat shininess);
 
 #ifdef __BEOS__
 void dprintf(const char*, ...);
@@ -469,7 +469,7 @@
 
 /* glopXXX functions */
 
-#define ADD_OP(a, b, c) void glop##a(GLContext*, GLParam*);
+#define ADD_OP(a, b, c) void glop##a(GLParam*);
 #include "opinfo.h"
 
 /* this clip epsilon is needed to avoid some rounding errors after
--- a/src/zraster.c
+++ b/src/zraster.c
@@ -3,7 +3,8 @@
 #include "zgl.h"
 #include "msghandling.h"
 
-static inline void gl_vertex_transform_raster(GLContext* c, GLVertex* v) {
+static inline void gl_vertex_transform_raster(GLVertex* v) {
+	GLContext* c = gl_get_context();
 	
 	{
 		/* no eye coordinates needed, no normal */
@@ -40,13 +41,14 @@
 	p[4].f = w;
 	gl_add_op(p);
 }
-void glopRasterPos(GLContext* c, GLParam* p){
+void glopRasterPos(GLParam* p){
+	GLContext* c = gl_get_context();
 	GLVertex v;
 	v.coord.X = p[1].f;
 	v.coord.Y = p[2].f;
 	v.coord.Z = p[3].f;
 	v.coord.W = p[4].f;
-	gl_vertex_transform_raster(c, &v);
+	gl_vertex_transform_raster(&v);
 	if (v.clip_code == 0)
 		{
 			{
@@ -107,7 +109,8 @@
 }
 #define ZCMP(z, zpix) (!(zbdt) || z >= (zpix))
 #define CLIPTEST(_x,_y,_w,_h)((0<=_x) && (_w>_x) && (0<=_y) && (_h>_y))
-void glopDrawPixels(GLContext* c, GLParam* p){
+void glopDrawPixels(GLParam* p){
+	GLContext* c = gl_get_context();
 	// p[3]
 	if(!c->rasterposvalid) return;
 	GLint w = p[1].i;
@@ -137,11 +140,11 @@
 #endif
 	//Looping over the source pixels.
 	if(c->render_mode == GL_SELECT){
-		gl_add_select(c, zz, zz);
+		gl_add_select( zz, zz);
 		return;
 	} else if(c->render_mode == GL_FEEDBACK){
 		gl_add_feedback(
-			c,	GL_DRAW_PIXEL_TOKEN,
+			GL_DRAW_PIXEL_TOKEN,
 			&(c->rastervertex),
 			NULL,
 			NULL,
@@ -235,7 +238,8 @@
 	gl_add_op(p);
 }
 
-void glopPixelZoom(GLContext* c, GLParam* p){
+void glopPixelZoom(GLParam* p){
+	GLContext* c = gl_get_context();
 	c->pzoomx = p[1].f;
 	c->pzoomy = p[2].f;
 }
--- a/src/ztext.c
+++ b/src/ztext.c
@@ -21,7 +21,7 @@
 	p[1].ui = mode;
 	gl_add_op(p);
 }
-void glopTextSize(GLContext* c, GLParam* p) { c->textsize = p[1].ui; } // Set text size
+void glopTextSize(GLParam* p) { GLContext* c = gl_get_context(); c->textsize = p[1].ui; } // Set text size
 void renderchar(GLbyte* bitmap, GLint _x, GLint _y, GLuint p) {
 	GLint x, y;
 	GLint set;
@@ -38,7 +38,8 @@
 	}
 }
 
-void glopPlotPixel(GLContext* c, GLParam* p) {
+void glopPlotPixel(GLParam* p) {
+	GLContext* c = gl_get_context();
 	GLint x = p[1].i;
 	PIXEL pix = p[2].ui;;
 /*