shithub: tinygl

Download patch

ref: fba8d05c264d1939b42fa8487425492744f59f74
parent: d27050d3cd1cfafd32a05029e04c91454f607a2c
author: David <gek@katherine>
date: Sun Feb 21 15:54:00 EST 2021

Bug fixes, improvements, and major expansion of glGet

--- a/README.md
+++ b/README.md
@@ -117,6 +117,8 @@
 
 * No edge clamping. S and T are wrapped.
 
+* Display lists can be infinitely nested and doing so will crash TinyGL.
+
 * Lit triangles will use the current material properties, even if they are textured. If the diffuse color is black, then your
 textured triangles will appear black.
 
--- a/include/GL/gl.h
+++ b/include/GL/gl.h
@@ -175,6 +175,14 @@
 	GL_LIGHT5			= 0x4005,
 	GL_LIGHT6			= 0x4006,
 	GL_LIGHT7			= 0x4007,
+	GL_LIGHT8			= 0x4008,
+	GL_LIGHT9			= 0x4009,
+	GL_LIGHT10			= 0x400A,
+	GL_LIGHT11			= 0x400B,
+	GL_LIGHT12			= 0x400C,
+	GL_LIGHT13			= 0x400D,
+	GL_LIGHT14			= 0x400E,
+	GL_LIGHT15			= 0x400F,
 	GL_SPOT_EXPONENT		= 0x1205,
 	GL_SPOT_CUTOFF			= 0x1206,
 	GL_CONSTANT_ATTENUATION		= 0x1207,
@@ -660,7 +668,15 @@
 	GL_TEXT_SIZE48x48 = 6,
 	GL_TEXT_SIZE56x56 = 7,
 	GL_TEXT_SIZE64x64 = 8,
-	GL_MAX_TEXT_SIZE = 8
+	GL_TEXT_SIZE72x72 = 9,
+	GL_TEXT_SIZE80x80 = 10,
+	GL_TEXT_SIZE88x88 = 11,
+	GL_TEXT_SIZE96x96 = 12,
+	GL_TEXT_SIZE104x104 = 13,
+	GL_TEXT_SIZE112x112 = 14,
+	GL_TEXT_SIZE120x120 = 15,
+	GL_TEXT_SIZE128x128 = 16,
+	GL_MAX_TEXT_SIZE = 16
 } GLTEXTSIZE;
 enum {
 	GL_CURRENT_BIT		= 0x00000001,
@@ -754,8 +770,8 @@
 
 void glBegin(GLint type);
 void glEnd(void);
-
-
+void glDrawBuffer(GLenum mode);
+void glReadBuffer(GLenum mode);
 void glDrawArrays(	GLenum mode,
  					GLint first,
  					GLsizei count);
@@ -827,6 +843,10 @@
 void glNewList(GLuint list,GLint mode);
 void glEndList(void);
 void glCallList(GLuint list);
+void glCallLists(	GLsizei n,
+				 	GLenum type,
+				 	const GLuint* lists);
+void glListBase(GLint n);
 void glDeleteList(GLuint list);
 void glDeleteLists(GLuint list, GLuint range);
 /* clear */
@@ -857,7 +877,10 @@
 void glTexEnvi(GLint target,GLint pname,GLint param);
 void glTexParameteri(GLint target,GLint pname,GLint param);
 void glPixelStorei(GLint pname,GLint param);
-
+GLboolean glAreTexturesResident(	GLsizei n,
+								 	const GLuint * textures,
+								 	GLboolean * residences);
+GLboolean glIsTexture(	GLuint texture);
 /* lighting */
 
 void glMaterialfv(GLint mode,GLint type,GLfloat *v);
--- a/src/Makefile
+++ b/src/Makefile
@@ -4,13 +4,8 @@
       misc.o clear.o light.o clip.o select.o get.o \
       zbuffer.o zline.o ztriangle.o \
       zmath.o image_util.o msghandling.o \
-      arrays.o specbuf.o memory.o ztext.o zraster.o
-ifdef TINYGL_USE_GLX
-#OBJS += glx.o
-endif
-ifdef TINYGL_USE_NANOX
-OBJS += nglx.o
-endif
+      arrays.o specbuf.o memory.o ztext.o zraster.o accum.o
+
 
 INCLUDES = -I./include
 LIB = libTinyGL.a
--- /dev/null
+++ b/src/accum.c
@@ -1,0 +1,2 @@
+#include "zgl.h"
+//TODO: Write the accumulation buffer
--- a/src/api.c
+++ b/src/api.c
@@ -164,8 +164,7 @@
 #define ERROR_FLAG GL_INVALID_ENUM
 #include "error_check.h"
 #else
-	//assert(mode == GL_CCW || mode == GL_CW);
-	//It's alright. No error checking!
+	//if(!(mode == GL_CCW || mode == GL_CW)) return;
 #endif
 	mode = (mode != GL_CCW);
 
--- a/src/arrays.c
+++ b/src/arrays.c
@@ -2,10 +2,7 @@
 #include <assert.h>
 //#include <stdio.h>
 
-#define VERTEX_ARRAY 0x0001
-#define COLOR_ARRAY 0x0002
-#define NORMAL_ARRAY 0x0004
-#define TEXCOORD_ARRAY 0x0008
+
 
 //Code for buffers is here too!
 
--- a/src/clip.c
+++ b/src/clip.c
@@ -239,7 +239,7 @@
 			return;
 
 		front = norm < 0.0;
-		front = front ^ c->current_front_face;
+		front = front ^ c->current_front_face; //I don't know how this works, but it does, GL_CCW is 0x901 and CW is 900.
 
 		/* back face culling */
 		if (c->cull_face_enabled) {
--- a/src/get.c
+++ b/src/get.c
@@ -1,58 +1,7 @@
 #include "msghandling.h"
 #include "zgl.h"
 #define TINYGL_VERSION 0.8
-void glGetIntegerv(GLint pname, GLint* params) {
-	GLContext* c = gl_get_context();
-#include "error_check.h"
-	switch (pname) {
-	case GL_BLEND:
-		*params = c->zb->enable_blend;
-		break;
-	case GL_BLEND_DST:
-		*params = c->zb->dfactor;
-		break;
-	case GL_BLEND_SRC:
-		*params = c->zb->sfactor;
-		break;
-	case GL_BLEND_EQUATION:
-		*params = c->zb->blendeq;
-		break;
-	case GL_VIEWPORT:
-		params[0] = c->viewport.xmin;
-		params[1] = c->viewport.ymin;
-		params[2] = c->viewport.xsize;
-		params[3] = c->viewport.ysize;
-		break;
-	case GL_MAX_MODELVIEW_STACK_DEPTH:
-		*params = MAX_MODELVIEW_STACK_DEPTH;
-		break;
-	case GL_MAX_PROJECTION_STACK_DEPTH:
-		*params = MAX_PROJECTION_STACK_DEPTH;
-		break;
-	
-	case GL_CULL_FACE_MODE:
-		*params = c->current_cull_face;
-		break;
-	case GL_MAX_LIGHTS:
-		*params = MAX_LIGHTS;
-		break;
-	case GL_MAX_TEXTURE_SIZE:
-		*params = TGL_FEATURE_TEXTURE_DIM; /* not completely true, but... */
-		break;
-	case GL_CULL_FACE:
-		*params = c->cull_face_enabled;
-		break;
-	case GL_MAX_TEXTURE_STACK_DEPTH:
-		*params = MAX_TEXTURE_STACK_DEPTH;
-		break;
-	case GL_CURRENT_RASTER_POSITION_VALID:
-		*params = c->rasterposvalid;
-		break;
-	default:
-		tgl_warning("glGet: option not implemented");
-		break;
-	}
-}
+
 #define xstr(s) str(s)
 #define str(s) #s
 
@@ -185,12 +134,393 @@
 	return NULL;
 }
 
+//NOTE: You should never be prevented from retrieving values from the GL state, even in GL_OUT_OF_MEMORY
+
+void glGetIntegerv(GLint pname, GLint* params) {
+	GLContext* c = gl_get_context();
+	GLint i = 0;
+	switch (pname) {
+	case GL_LIGHT15:
+		i++;
+	case GL_LIGHT14:
+		i++;
+	case GL_LIGHT13:
+		i++;
+	case GL_LIGHT12:
+		i++;
+	case GL_LIGHT11:
+		i++;
+	case GL_LIGHT10:
+		i++;
+	case GL_LIGHT9:
+		i++;
+	case GL_LIGHT8:
+		i++;
+	case GL_LIGHT7:
+		i++;
+	case GL_LIGHT6:
+		i++;
+	case GL_LIGHT5:
+		i++;
+	case GL_LIGHT4:
+		i++;
+	case GL_LIGHT3:
+		i++;
+	case GL_LIGHT2:
+		i++;
+	case GL_LIGHT1:
+		i++;
+	case GL_LIGHT0:
+		*params = c->lights[i].enabled;
+		break;
+	case GL_COLOR_ARRAY:
+		*params = ((c->client_states & COLOR_ARRAY)!=0);
+		break;
+	case GL_COLOR_ARRAY_SIZE:
+		*params = (c->color_array_size);
+		break;
+	case GL_COLOR_ARRAY_STRIDE:
+		*params = c->color_array_stride;
+		break;
+	case GL_VERTEX_ARRAY:
+		*params = ((c->client_states & VERTEX_ARRAY)!=0);
+		break;
+	case GL_VERTEX_ARRAY_SIZE:
+		*params = c->vertex_array_size;
+		break;
+	case GL_VERTEX_ARRAY_STRIDE:
+		*params = c->vertex_array_stride;
+		break;
+	case GL_TEXTURE_COORD_ARRAY:
+		*params = ((c->client_states & TEXCOORD_ARRAY)!=0);
+		break;
+	case GL_TEXTURE_COORD_ARRAY_SIZE:
+		*params = c->texcoord_array_size;
+		break;
+	case GL_TEXTURE_COORD_ARRAY_STRIDE:
+		*params = c->texcoord_array_stride;
+		break;
+	case GL_NORMAL_ARRAY:
+		*params = ((c->client_states & NORMAL_ARRAY)!=0);
+		break;
+	case GL_NORMAL_ARRAY_STRIDE:
+		*params = c->normal_array_stride;
+		break;
+	case GL_BLEND:
+		*params = c->zb->enable_blend;
+		break;
+	case GL_SHADE_MODEL:
+		*params = c->current_shade_model;
+		break;
+	case GL_BLEND_DST:
+		*params = c->zb->dfactor;
+		break;
+	case GL_BLEND_SRC:
+		*params = c->zb->sfactor;
+		break;
+	case GL_POLYGON_MODE:
+		params[0] = c->polygon_mode_front;
+		params[1] = c->polygon_mode_back;
+		break;
+	case GL_LIST_MODE:
+		params[0] = c->compile_flag;
+		break;
+	case GL_LIST_BASE:
+		*params = c->listbase;
+	break;
+	case GL_LIST_INDEX:
+		params[0] = 0;
+		break;
+	case GL_TEXTURE_2D:
+		params[0] = c->texture_2d_enabled;
+		break;
+	case GL_POLYGON_STIPPLE:
+#if TGL_FEATURE_POLYGON_STIPPLE == 1
+		params[0] = c->zb->GLuint dostipple;
+#else
+		params[0] = GL_FALSE;
+#endif
+		break;
+	case GL_LIGHT_MODEL_LOCAL_VIEWER:
+		*params = c->local_light_model;
+		break;
+	case GL_FOG_INDEX:
+		*params = 0;
+		break;
+	case GL_FOG_COLOR:
+		params[0] = 0;
+		params[1] = 0;
+		params[2] = 0;
+		params[3] = 0;
+		break;
+	case GL_FOG_MODE:
+		*params = GL_EXP;
+		break;
+	case GL_LIGHTING:
+		*params = (c->lighting_enabled != 0);
+		break;
+	case GL_LIGHT_MODEL_TWO_SIDE:
+		*params = (c->light_model_two_side != 0);
+		break;
+	case GL_LINE_STIPPLE_REPEAT:
+		*params = 1;
+	break;
+	case GL_LINE_STIPPLE:
+		*params = 0;
+	break;
+	case GL_LINE_STIPPLE_PATTERN:
+		*params = (GLushort)(~0);
+	break;
+	case GL_NORMALIZE:
+		params[0] = c->normalize_enabled;
+		break;
+	case GL_POINT_SMOOTH_HINT:
+	case GL_FOG_HINT:
+	case GL_LINE_SMOOTH_HINT:
+	case GL_PERSPECTIVE_CORRECTION_HINT:
+	case GL_POLYGON_SMOOTH_HINT:
+		*params = GL_FASTEST;
+		break;
+	case GL_BLUE_SCALE:
+	case GL_RED_SCALE:
+	case GL_GREEN_SCALE:
+	case GL_ALPHA_SCALE:
+		*params = 1;
+		break;
+	case GL_SUBPIXEL_BITS:
+		*params = 6;
+		break;
+	case GL_MATRIX_MODE:
+		if(c->matrix_mode == 0)
+			*params = GL_MODELVIEW;
+		else if (c->matrix_mode == 1)
+			*params = GL_PROJECTION;
+		else if (c->matrix_mode == 2)
+			*params = GL_TEXTURE;
+		break;
+	case GL_BLUE_BIAS:
+	case GL_RED_BIAS:
+	case GL_GREEN_BIAS:
+	case GL_ALPHA_BIAS:
+	case GL_CLIP_PLANE0: //TODO
+	case GL_CLIP_PLANE1:
+	case GL_CLIP_PLANE2:
+	case GL_CLIP_PLANE3:
+	case GL_CLIP_PLANE4:
+	case GL_CLIP_PLANE5:
+	case GL_SCISSOR_TEST:
+	case GL_UNPACK_SWAP_BYTES:
+	case GL_UNPACK_SKIP_ROWS:
+	case GL_UNPACK_SKIP_PIXELS:
+	case GL_UNPACK_ROW_LENGTH:
+	case GL_UNPACK_LSB_FIRST:
+	case GL_TEXTURE_GEN_T:
+	case GL_TEXTURE_GEN_S:
+	case GL_TEXTURE_GEN_R:
+	case GL_TEXTURE_GEN_Q:
+	case GL_TEXTURE_1D: //TODO
+	case GL_STEREO:
+	case GL_PACK_SWAP_BYTES:
+	case GL_PACK_SKIP_ROWS:
+	case GL_PACK_SKIP_PIXELS:
+	case GL_PACK_ROW_LENGTH:
+	case GL_PACK_LSB_FIRST:
+	case GL_STENCIL_TEST:
+	case GL_MAX_PIXEL_MAP_TABLE:
+	case GL_MAX_EVAL_ORDER:
+	case GL_MAX_CLIENT_ATTRIB_STACK_DEPTH:
+		params[0] = 0;
+		break;
+	case GL_MAX_VIEWPORT_DIMS:
+		params[0] = 4096;
+		params[1] = 4096;
+		break;
+	case GL_MAX_LIST_NESTING:
+		*params = 2147483647; //No checking is done, indicate it to the user!
+		break;
+	case GL_STENCIL_FUNC:
+		*params = GL_ALWAYS;
+		break;
+	case GL_STENCIL_CLEAR_VALUE:
+		*params = 0;
+		break;
+	case GL_STENCIL_BITS:
+	case GL_MAP_STENCIL:
+	case GL_MAP_COLOR:
+	case GL_INDEX_SHIFT:
+	case GL_INDEX_OFFSET:
+	case GL_INDEX_MODE:
+	case GL_INDEX_CLEAR_VALUE:
+	case GL_INDEX_BITS:
+	case GL_INDEX_ARRAY:
+		*params = 0;
+		break;
+	case GL_FRONT_FACE:
+		*params = c->current_front_face;
+		break;
+	case GL_STENCIL_PASS_DEPTH_PASS:
+	case GL_STENCIL_PASS_DEPTH_FAIL:
+		*params = GL_KEEP;
+		break;
+	case GL_STENCIL_VALUE_MASK:
+	case GL_INDEX_WRITEMASK:
+		*params = ~0;
+		break;
+	case GL_UNPACK_ALIGNMENT:
+	case GL_PACK_ALIGNMENT:
+		*params = 4;
+		break;
+	case GL_COLOR_ARRAY_TYPE:
+	case GL_NORMAL_ARRAY_TYPE:
+	case GL_TEXTURE_COORD_ARRAY_TYPE:
+	case GL_VERTEX_ARRAY_TYPE:
+		*params = GL_FLOAT;
+		break;
+	case GL_RENDER_MODE:
+		*params = c->render_mode;
+		break;
+	case GL_BLEND_EQUATION:
+		*params = c->zb->blendeq;
+		break;
+	case GL_DRAW_BUFFER:
+		*params = c->drawbuffer;
+		break;
+	case GL_READ_BUFFER:
+		*params = c->readbuffer;
+		break;
+	case GL_AUX_BUFFERS:
+		*params = 0;
+		break;
+	case GL_PIXEL_MAP_S_TO_S_SIZE:
+	case GL_PIXEL_MAP_I_TO_I_SIZE:
+	case GL_PIXEL_MAP_I_TO_R_SIZE:
+	case GL_PIXEL_MAP_I_TO_G_SIZE:
+	case GL_PIXEL_MAP_I_TO_B_SIZE:
+	case GL_PIXEL_MAP_I_TO_A_SIZE:
+	case GL_PIXEL_MAP_R_TO_R_SIZE:
+	case GL_PIXEL_MAP_G_TO_G_SIZE:
+	case GL_PIXEL_MAP_B_TO_B_SIZE:
+	case GL_PIXEL_MAP_A_TO_A_SIZE:
+		*params = 0; 
+		break;
+	case GL_RGBA_MODE:
+		*params = 1; //yes, even in 565 (it's what the spec says)
+		break;
+	case GL_VIEWPORT:
+		params[0] = c->viewport.xmin;
+		params[1] = c->viewport.ymin;
+		params[2] = c->viewport.xsize;
+		params[3] = c->viewport.ysize;
+		break;
+	case GL_MAX_MODELVIEW_STACK_DEPTH:
+		*params = MAX_MODELVIEW_STACK_DEPTH;
+		break;
+	case GL_MAX_NAME_STACK_DEPTH:
+		*params = MAX_NAME_STACK_DEPTH;
+		break;
+	case GL_MAX_PROJECTION_STACK_DEPTH:
+		*params = MAX_PROJECTION_STACK_DEPTH;
+		break;
+	case GL_MAX_TEXTURE_STACK_DEPTH:
+		*params = MAX_TEXTURE_STACK_DEPTH;
+		break;
+	case GL_GREEN_BITS:
+#if TGL_FEATURE_RENDER_BITS == 16
+		*params = 6;
+#elif TGL_FEATURE_RENDER_BITS == 32
+		*params = 8;
+#endif
+		break;	
+	case GL_BLUE_BITS:
+	case GL_RED_BITS:
+#if TGL_FEATURE_RENDER_BITS == 16
+		*params = 5;
+#elif TGL_FEATURE_RENDER_BITS == 32
+		*params = 8;
+#endif
+		break;
+	case GL_POLYGON_OFFSET_FILL:
+		*params = ((c->offset_states & TGL_OFFSET_FILL) != 0);
+		break;
+	case GL_POLYGON_OFFSET_LINE:
+		*params = ((c->offset_states & TGL_OFFSET_LINE) != 0);
+		break;
+	case GL_DEPTH_BITS:
+		*params = 16;
+		break;
+	case GL_POLYGON_OFFSET_POINT:
+		*params = ((c->offset_states & TGL_OFFSET_POINT) != 0);
+		break;
+	case GL_POLYGON_SMOOTH:
+		*params = GL_FALSE;
+	break;
+	case GL_CULL_FACE_MODE:
+		*params = c->current_cull_face;
+		break;
+	case GL_MAX_LIGHTS:
+		*params = MAX_LIGHTS;
+		break;
+	case GL_MAX_TEXTURE_SIZE:
+		*params = TGL_FEATURE_TEXTURE_DIM; /* not completely true, but... */
+		break;
+	case GL_CULL_FACE:
+		*params = c->cull_face_enabled;
+		break;
+	case GL_CURRENT_RASTER_POSITION_VALID:
+		*params = c->rasterposvalid;
+		break;
+	case GL_FOG:
+		*params = GL_FALSE;
+		break;
+	case GL_EDGE_FLAG:
+		*params = c->current_edge_flag;
+		break;
+	case GL_DOUBLEBUFFER: 
+	case GL_DITHER: 
+		*params = GL_FALSE; 
+		break;
+	case GL_DEPTH_TEST:
+		*params = (c->zb->depth_test == 1);
+		break;
+	case GL_DEPTH_FUNC:
+		*params = GL_LESS;
+		break;
+	
+	default:
+		tgl_warning("glGet: option not implemented");
+#if TGL_FEATURE_ERROR_CHECK == 1
+#define ERROR_FLAG GL_INVALID_ENUM
+#include "error_check.h"
+#endif
+		break;
+	}
+}
+
+
+
 void glGetFloatv(GLint pname, GLfloat* v) {
 	GLint i;
 	GLint mnr = 0; /* just a trick to return the correct matrix */
 	GLContext* c = gl_get_context();
-#include "error_check.h"
 	switch (pname) {
+		case GL_BLUE_SCALE:
+		case GL_RED_SCALE:
+		case GL_GREEN_SCALE:
+		case GL_ALPHA_SCALE:
+		case GL_FOG_END:
+		case GL_FOG_DENSITY:
+			*v = 1;
+			break;
+		case GL_BLUE_BIAS:
+		case GL_RED_BIAS:
+		case GL_GREEN_BIAS:
+		case GL_ALPHA_BIAS:
+		case GL_FOG_START:
+			*v = 0;
+			break;
+		case GL_DEPTH_SCALE:
+			*v = 1;
+			break;
 		case GL_TEXTURE_MATRIX:
 			mnr++;
 		case GL_PROJECTION_MATRIX:
@@ -197,7 +527,6 @@
 			mnr++;
 		case GL_MODELVIEW_MATRIX: {
 			GLfloat* p = &c->matrix_stack_ptr[mnr]->m[0][0];
-			;
 			for (i = 0; i < 4; i++) {
 				*v++ = p[0];
 				*v++ = p[4];
@@ -209,12 +538,58 @@
 		case GL_LINE_WIDTH:
 			*v = 1.0f;
 			break;
+		case GL_DEPTH_CLEAR_VALUE:
+			*v = 1; //This is not entirely true, but... good enough?
+			break;
+		case GL_DEPTH_RANGE:
+			v[0] = 0;
+			v[1] = 1;
+			break;
+		case GL_DEPTH_BIAS:
+			*v = 0;
+			break;
+		case GL_CURRENT_TEXTURE_COORDS:
+			v[0] = c->current_tex_coord.X;
+			v[1] = c->current_tex_coord.Y;
+			v[2] = c->current_tex_coord.Z;
+			v[3] = c->current_tex_coord.W;
+			break;
+		case GL_CURRENT_RASTER_POSITION:
+			v[0] = c->rastervertex.pc.X;
+			v[1] = c->rastervertex.pc.Y;
+			v[2] = c->rastervertex.pc.Z;
+			v[3] = c->rastervertex.pc.W;
+			break;
+		case GL_CURRENT_RASTER_DISTANCE:
+			*v = c->rastervertex.ec.Z;
+			break;
 		case GL_LINE_WIDTH_RANGE:
 			v[0] = v[1] = 1.0f;
 			break;
 		case GL_POINT_SIZE:
+		//case GL_POINT_SIZE_MIN:
+		//case GL_POINT_SIZE_MAX:
 			*v = c->zb->pointsize;
 			break;
+		case GL_FOG_COLOR:
+			v[0] = 0;
+			v[1] = 0;
+			v[2] = 0;
+			v[3] = 0;
+		break;
+		case GL_POINT_SIZE_GRANULARITY:
+			*v = 1.0f; //if we ever implement AA'd points...
+			break;
+		case GL_POLYGON_OFFSET_FACTOR:
+			*v = 0;
+			break;
+		case GL_POLYGON_OFFSET_UNITS:
+			*v = 0;
+			break;
+		case GL_LIGHT_MODEL_AMBIENT:
+			for (i = 0; i < 4; i++)
+				v[i] = c->ambient_light_model.v[i];
+		break;
 		case GL_ZOOM_X:
 			*v = c->pzoomx;
 			break;
@@ -222,7 +597,9 @@
 			*v = c->pzoomy;
 			break;
 		case GL_POINT_SIZE_RANGE:
-			v[0] = v[1] = 1.0f;
+			v[0] = c->zb->pointsize;
+			v[1] = c->zb->pointsize;
+			break;
 		default:
 			tgl_warning("warning: unknown pname in glGetFloatv()\n");
 			break;
--- a/src/init.c
+++ b/src/init.c
@@ -130,7 +130,9 @@
 	v->xsize = zbuffer->xsize;
 	v->ysize = zbuffer->ysize;
 	v->updated = 1;
-
+	/* buffer stuff GL 1.1 */
+	c->drawbuffer = GL_FRONT;
+	c->readbuffer = GL_FRONT;
 	/* shared state */
 	initSharedState(c);
 	/* ztext */
@@ -146,7 +148,7 @@
 	c->exec_flag = 1;
 	c->compile_flag = 0;
 	c->print_flag = 0;
-
+	c->listbase = 0;
 	c->in_begin = 0;
 
 	/* lights */
@@ -282,7 +284,7 @@
 	c->specbuf_first = NULL;
 	c->specbuf_used_counter = 0;
 	c->specbuf_num_buffers = 0;
-
+	c->zEnableSpecular = 0;
 	/* depth test */
 	c->zb->depth_test = 0;
 	c->zb->depth_write = 1;
@@ -289,9 +291,15 @@
 	c->zb->pointsize = 1;
 
 	/* raster position */
-	c->rasterpos.v[0] = 0;
-	c->rasterpos.v[1] = 0;
-	c->rasterpos.v[2] = 0;
+	c->rasterpos.X = 0;
+	c->rasterpos.Y = 0;
+	c->rasterpos.Z = 0;
+	c->rasterpos.W = 1;
+
+	c->rastervertex.pc.X = 0;
+	c->rastervertex.pc.Y = 0;
+	c->rastervertex.pc.Z = 0;
+	c->rastervertex.pc.W = 1;
 	c->rasterposvalid = 0;
 	c->pzoomx = 1;
 	c->pzoomy = 1;
--- a/src/light.c
+++ b/src/light.c
@@ -176,7 +176,7 @@
 
 void glopLightModel(GLContext* c, GLParam* p) {
 	GLint pname = p[1].i;
-	GLfloat* v = &p[2].f;
+	GLint* v = &p[2].i;
 	GLint i;
 
 	switch (pname) {
@@ -229,10 +229,10 @@
 }
 
 // FEATURES
-int zEnableSpecular = 1; // Enable specular lighting
+
 void glSetEnableSpecular(GLint s) { 
 #include "error_check_no_context.h"
-	zEnableSpecular = s; 
+	gl_get_context()->zEnableSpecular = s; 
 }
 /* non optimized lightening model */
 void gl_shade_vertex(GLContext* c, GLVertex* v) {
@@ -322,7 +322,7 @@
 			}
 
 			/* specular light */
-			if (zEnableSpecular) {
+			if (c->zEnableSpecular) {
 				if (c->local_light_model) {
 					V3 vcoord;
 					vcoord.X = v->ec.X;
--- a/src/list.c
+++ b/src/list.c
@@ -110,6 +110,25 @@
 	tgl_warning(f, "\n");
 }
 */
+void glListBase(GLint n){
+	GLContext* c = gl_get_context();
+#include "error_check.h"
+	c->listbase = n;
+}
+void glCallLists(	GLsizei n,
+				 	GLenum type,
+				 	const GLuint* lists){
+	GLContext* c = gl_get_context();
+#include "error_check.h"
+#if TGL_FEATURE_ERROR_CHECK == 1
+	if(type != GL_UNSIGNED_INT &&
+		type != GL_INT)
+#define ERROR_FLAG GL_INVALID_ENUM
+#include "error_check.h"
+#endif
+	for(GLint i = 0; i < n; i++)
+		glCallList(c->listbase + lists[i]);
+}
 void gl_compile_op(GLContext* c, GLParam* p) {
 	GLint op, op_size;
 	GLParamBuffer *ob, *ob1;
@@ -247,7 +266,8 @@
 #define ERROR_FLAG GL_INVALID_OPERATION
 #include "error_check.h"
 #else
-	//assert(c->compile_flag == 1); //MARK <COST>
+	if(c->compile_flag != 1)
+		return;
 #endif
 	/* end of list */
 	p[0].op = OP_EndList;
--- a/src/misc.c
+++ b/src/misc.c
@@ -15,7 +15,9 @@
 }
 
 void glopViewport(GLContext* c, GLParam* p) {
-	GLint xsize, ysize, xmin, ymin, xsize_req, ysize_req;
+	GLint xsize, ysize, 
+			xmin, ymin, 
+			xsize_req, ysize_req;
 
 	xmin = p[1].i;
 	ymin = p[2].i;
@@ -32,14 +34,11 @@
 		if (c->gl_resize_viewport && c->gl_resize_viewport(c, &xsize_req, &ysize_req) != 0) {
 			gl_fatal_error("glViewport: error while resizing display");
 		}
-
-		xsize = xsize_req - xmin;
-		ysize = ysize_req - ymin;
 		if (xsize <= 0 || ysize <= 0) {
 			gl_fatal_error("glViewport: size too small");
 		}
 
-		tgl_trace("glViewport: %d %d %d %d\n", xmin, ymin, xsize, ysize);
+		//tgl_trace("glViewport: %d %d %d %d\n", xmin, ymin, xsize, ysize);
 		c->viewport.xmin = xmin;
 		c->viewport.ymin = ymin;
 		c->viewport.xsize = xsize;
@@ -202,6 +201,37 @@
 #endif
 }
 
+void glDrawBuffer(GLenum mode){
+	GLContext* c = gl_get_context();
+#include "error_check.h"
+	if((mode != GL_FRONT &&
+		mode != GL_NONE) || c->in_begin)
+	{
+#if TGL_FEATURE_ERROR_CHECK == 1
+#define ERROR_FLAG GL_INVALID_OPERATION
+#include "error_check.h"
+#else
+		return;
+#endif
+	}
+	c->drawbuffer = mode;
+}
+
+void glReadBuffer(GLenum mode){
+	GLContext* c = gl_get_context();
+#include "error_check.h"
+	if((mode != GL_FRONT &&
+		mode != GL_NONE) || c->in_begin)
+	{
+#if TGL_FEATURE_ERROR_CHECK == 1
+#define ERROR_FLAG GL_INVALID_OPERATION
+#include "error_check.h"
+#else
+		return;
+#endif
+	}
+	c->readbuffer = mode;
+}
 
 void glFinish(){
 	return;
--- a/src/texture.c
+++ b/src/texture.c
@@ -15,6 +15,27 @@
 	return NULL;
 }
 
+GLboolean glAreTexturesResident(	GLsizei n,
+								 	const GLuint * textures,
+								 	GLboolean * residences){
+GLContext* c = gl_get_context();
+#define RETVAL GL_FALSE
+#include "error_check.h"
+	for(GLint i = 0; i < n; i++)
+		if(find_texture(c, textures[i]))
+			residences[i] = GL_TRUE;
+		else
+			residences[i] = GL_FALSE;
+}
+GLboolean glIsTexture(	GLuint texture){
+	GLContext* c = gl_get_context();
+#define RETVAL GL_FALSE
+#include "error_check.h"
+	if(find_texture(c, texture))
+		return GL_TRUE;
+	return GL_FALSE;
+}
+
 void* glGetTexturePixmap(GLint text, GLint level, GLint* xsize, GLint* ysize) {
 	GLTexture* tex;
 	GLContext* c = gl_get_context();
--- a/src/vertex.c
+++ b/src/vertex.c
@@ -117,6 +117,7 @@
 		case GL_LINE:
 			c->draw_triangle_front = gl_draw_triangle_line;
 			break;
+		//case GL_FILL:
 		default:
 			c->draw_triangle_front = gl_draw_triangle_fill;
 			break;
--- a/src/zgl.h
+++ b/src/zgl.h
@@ -1,8 +1,8 @@
 #ifndef _tgl_zgl_h_
 #define _tgl_zgl_h_
 #include "../include/GL/gl.h"
-#include "../include/zbuffer.h"
 #include "../include/zfeatures.h"
+#include "../include/zbuffer.h"
 #include "zmath.h"
 #include <assert.h>
 #include <math.h>
@@ -43,6 +43,11 @@
 #define MAX_TEXTURE_LEVELS 1
 #define MAX_LIGHTS 16
 
+
+#define VERTEX_ARRAY 0x0001
+#define COLOR_ARRAY 0x0002
+#define NORMAL_ARRAY 0x0004
+#define TEXCOORD_ARRAY 0x0008
 //#define VERTEX_HASH_SIZE 1031
 
 #define MAX_DISPLAY_LISTS 1024
@@ -195,7 +200,7 @@
 	GLParamBuffer* current_op_buffer;
 	GLint current_op_buffer_index;
 	GLint exec_flag, compile_flag, print_flag;
-
+	GLuint listbase;
 	/* matrix */
 
 	GLint matrix_mode;
@@ -230,7 +235,9 @@
 	GLuint *select_ptr, *select_hit;
 	GLint select_overflow;
 	GLint select_hits;
-
+	/* glDrawBuffer, glRenderBuffer */
+	GLenum drawbuffer;
+	GLenum readbuffer;
 	/* feedback */
 	//render_mode as seen above
 	GLfloat* feedback_buffer;
@@ -287,7 +294,7 @@
 	GLSpecBuf* specbuf_first;
 	GLint specbuf_used_counter;
 	GLint specbuf_num_buffers;
-
+	GLint zEnableSpecular; // Enable specular lighting
 	/* opaque structure for user's use */
 	void* opaque;
 	/* resize viewport function */
@@ -297,7 +304,7 @@
 	//Moved to Zbuffer.
 
 	/* raster position */
-	V3 rasterpos;
+	V4 rasterpos;
 	GLint rasterpos_zz;
 	GLubyte rasterposvalid;
 	GLfloat pzoomx, pzoomy;
--- a/src/zraster.c
+++ b/src/zraster.c
@@ -13,11 +13,18 @@
 		v->pc.X = (v->coord.X * m[0] + v->coord.Y * m[1] + v->coord.Z * m[2] + m[3]);
 		v->pc.Y = (v->coord.X * m[4] + v->coord.Y * m[5] + v->coord.Z * m[6] + m[7]);
 		v->pc.Z = (v->coord.X * m[8] + v->coord.Y * m[9] + v->coord.Z * m[10] + m[11]);
+
+		
 		if (c->matrix_model_projection_no_w_transform) {
 			v->pc.W = m[15];
 		} else {
 			v->pc.W = (v->coord.X * m[12] + v->coord.Y * m[13] + v->coord.Z * m[14] + m[15]);
 		}
+		m = &c->matrix_stack_ptr[0]->m[0][0];
+		v->ec.X = (v->coord.X * m[0] + v->coord.Y * m[1] + v->coord.Z * m[2] + m[3]);
+		v->ec.Y = (v->coord.X * m[4] + v->coord.Y * m[5] + v->coord.Z * m[6] + m[7]);
+		v->ec.Z = (v->coord.X * m[8] + v->coord.Y * m[9] + v->coord.Z * m[10] + m[11]);
+		v->ec.W = (v->coord.X * m[12] + v->coord.Y * m[13] + v->coord.Z * m[14] + m[15]);
 	}
 
 	v->clip_code = gl_clipcode(v->pc.X, v->pc.Y, v->pc.Z, v->pc.W);
@@ -51,6 +58,8 @@
 			}
 			c->rasterpos.v[0] = v.zp.x;
 			c->rasterpos.v[1] = v.zp.y;
+			//c->rasterpos.v[2] = v.pc.Z;
+			//c->rasterpos.v[3] = v.pc.W;
 			c->rastervertex = v;
 			//c->rasterpos.v[2] = v.zp.z;
 			c->rasterpos_zz = v.zp.z >> ZB_POINT_Z_FRAC_BITS; //I believe this is it?
@@ -105,7 +114,7 @@
 	if(!c->rasterposvalid) return;
 	GLint w = p[1].i;
 	GLint h = p[2].i;
-	V3 rastpos = c->rasterpos;
+	V4 rastpos = c->rasterpos;
 	ZBuffer* zb = c->zb;
 	PIXEL* d = p[3].p;
 	PIXEL* pbuf = zb->pbuf;