#ifdef _WIN32 #include #include #include "glext.h" #else // _WIN32 #include "../winlnxdefs.h" #endif // _WIN32 #include "glide.h" #include "main.h" #define Z_MAX 65536.0f static int xy_off; static int xy_en; static int z_en; static int z_off; static int q_off; static int q_en; static int pargb_off; static int pargb_en; static int st0_off; static int st0_en; static int st1_off; static int st1_en; static int fog_ext_off; static int fog_ext_en; int w_buffer_mode; int inverted_culling; void init_geometry() { xy_en = q_en = pargb_en = st0_en = st1_en = z_en = 0; w_buffer_mode = 0; inverted_culling = 0; glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); } FX_ENTRY void FX_CALL grCoordinateSpace( GrCoordinateSpaceMode_t mode ) { switch(mode) { case GR_WINDOW_COORDS: break; default: display_warning((unsigned char*)"unknwown coordinate space : %x", mode); } } FX_ENTRY void FX_CALL grVertexLayout(FxU32 param, FxI32 offset, FxU32 mode) { switch(param) { case GR_PARAM_XY: xy_en = mode; xy_off = offset; break; case GR_PARAM_Z: z_en = mode; z_off = offset; break; case GR_PARAM_Q: q_en = mode; q_off = offset; break; case GR_PARAM_FOG_EXT: fog_ext_en = mode; fog_ext_off = offset; break; case GR_PARAM_PARGB: pargb_en = mode; pargb_off = offset; break; case GR_PARAM_ST0: st0_en = mode; st0_off = offset; break; case GR_PARAM_ST1: st1_en = mode; st1_off = offset; break; default: display_warning((unsigned char*)"unknown grVertexLayout parameter : %x", param); } } FX_ENTRY void FX_CALL grCullMode( GrCullMode_t mode ) { switch(mode) { case GR_CULL_DISABLE: glDisable(GL_CULL_FACE); break; case GR_CULL_NEGATIVE: if (!inverted_culling) glCullFace(GL_FRONT); else glCullFace(GL_BACK); glEnable(GL_CULL_FACE); break; case GR_CULL_POSITIVE: if (!inverted_culling) glCullFace(GL_BACK); else glCullFace(GL_FRONT); glEnable(GL_CULL_FACE); break; default: display_warning((unsigned char*)"unknown cull mode : %x", mode); } } // Depth buffer FX_ENTRY void FX_CALL grDepthBufferMode( GrDepthBufferMode_t mode ) { switch(mode) { case GR_DEPTHBUFFER_WBUFFER: glEnable(GL_DEPTH_TEST); w_buffer_mode = 1; break; case GR_DEPTHBUFFER_ZBUFFER: glEnable(GL_DEPTH_TEST); w_buffer_mode = 0; break; default: display_warning((unsigned char*)"unknown depth buffer mode : %x", mode); } } FX_ENTRY void FX_CALL grDepthBufferFunction( GrCmpFnc_t function ) { switch(function) { case GR_CMP_LEQUAL: if (w_buffer_mode) glDepthFunc(GL_GEQUAL); else glDepthFunc(GL_LEQUAL); break; case GR_CMP_LESS: if (w_buffer_mode) glDepthFunc(GL_GREATER); else glDepthFunc(GL_LESS); break; case GR_CMP_ALWAYS: glDepthFunc(GL_ALWAYS); break; default: display_warning((unsigned char*)"unknown depth buffer function : %x", function); } } FX_ENTRY void FX_CALL grDepthMask( FxBool mask ) { glDepthMask(mask); } FX_ENTRY void FX_CALL grDepthBiasLevel( FxI32 level ) { if (level) { if(w_buffer_mode) glPolygonOffset(1.0f, -(float)level/255.0f); else glPolygonOffset(1.0f, (float)level*128.0f); glEnable(GL_POLYGON_OFFSET_FILL); } else { glPolygonOffset(0,0); glDisable(GL_POLYGON_OFFSET_FILL); } } // draw FX_ENTRY void FX_CALL grDrawTriangle( const void *a, const void *b, const void *c ) { float *a_x = (float*)a + xy_off/sizeof(float); float *a_y = (float*)a + xy_off/sizeof(float) + 1; float *a_z = (float*)a + z_off/sizeof(float); float *a_q = (float*)a + q_off/sizeof(float); unsigned char *a_pargb = (unsigned char*)a + pargb_off; float *a_s0 = (float*)a + st0_off/sizeof(float); float *a_t0 = (float*)a + st0_off/sizeof(float) + 1; float *a_s1 = (float*)a + st1_off/sizeof(float); float *a_t1 = (float*)a + st1_off/sizeof(float) + 1; float *a_fog = (float*)a + fog_ext_off/sizeof(float); float *b_x = (float*)b + xy_off/sizeof(float); float *b_y = (float*)b + xy_off/sizeof(float) + 1; float *b_z = (float*)b + z_off/sizeof(float); float *b_q = (float*)b + q_off/sizeof(float); unsigned char *b_pargb = (unsigned char*)b + pargb_off; float *b_s0 = (float*)b + st0_off/sizeof(float); float *b_t0 = (float*)b + st0_off/sizeof(float) + 1; float *b_s1 = (float*)b + st1_off/sizeof(float); float *b_t1 = (float*)b + st1_off/sizeof(float) + 1; float *b_fog = (float*)b + fog_ext_off/sizeof(float); float *c_x = (float*)c + xy_off/sizeof(float); float *c_y = (float*)c + xy_off/sizeof(float) + 1; float *c_z = (float*)c + z_off/sizeof(float); float *c_q = (float*)c + q_off/sizeof(float); unsigned char *c_pargb = (unsigned char*)c + pargb_off; float *c_s0 = (float*)c + st0_off/sizeof(float); float *c_t0 = (float*)c + st0_off/sizeof(float) + 1; float *c_s1 = (float*)c + st1_off/sizeof(float); float *c_t1 = (float*)c + st1_off/sizeof(float) + 1; float *c_fog = (float*)c + fog_ext_off/sizeof(float); //if(*a_fog == 0.0f) *a_fog = 1.0f; //if(*b_fog == 0.0f) *b_fog = 1.0f; //if(*c_fog == 0.0f) *c_fog = 1.0f; // ugly ? i know but nvidia drivers are losing the viewport otherwise if(viewport_width) { glViewport(0, viewport_offset, viewport_width, viewport_height); viewport_width=0; } if(glsl_support && need_to_compile) compile_shader(); glBegin(GL_TRIANGLES); if (nbTextureUnits > 2) { if (st0_en) glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *a_s0 / *a_q / (float)tex1_width, *a_t0 / *a_q / (float)tex1_height); if (st1_en) glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *a_s1 / *a_q / (float)tex0_width, *a_t1 / *a_q / (float)tex0_height); } else { if (st0_en) glTexCoord2f(*a_s0 / *a_q / (float)tex0_width, *a_t0 / *a_q / (float)tex0_height); } if (pargb_en) glColor4f(a_pargb[2]/255.0f, a_pargb[1]/255.0f, a_pargb[0]/255.0f, a_pargb[3]/255.0f); if (fog_enabled && fog_coord_support) { if(!glsl_support) { if(!fog_ext_en || fog_enabled != 2) glFogCoordfEXT((1.0f / *a_q)/**100.0f*/); else glFogCoordfEXT((1.0f / *a_fog)/**100.0f*/); } else { if(!fog_ext_en || fog_enabled != 2) glSecondaryColor3f((1.0f / *a_q) / 256.0f, 0.0f, 0.0f); else glSecondaryColor3f((1.0f / *a_fog) / 256.0f, 0.0f, 0.0f); } } glVertex4f((*a_x - (float)widtho) / (float)(width/2) / *a_q, -(*a_y - (float)heighto) / (float)(height/2) / *a_q, z_en ? (*a_z / Z_MAX) / *a_q : 1.0f, 1.0f / *a_q); if (nbTextureUnits > 2) { if (st0_en) glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *b_s0 / *b_q / (float)tex1_width, *b_t0 / *b_q / (float)tex1_height); if (st1_en) glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *b_s1 / *b_q / (float)tex0_width, *b_t1 / *b_q / (float)tex0_height); } else { if (st0_en) glTexCoord2f(*b_s0 / *b_q / (float)tex0_width, *b_t0 / *b_q / (float)tex0_height); } if (pargb_en) glColor4f(b_pargb[2]/255.0f, b_pargb[1]/255.0f, b_pargb[0]/255.0f, b_pargb[3]/255.0f); if (fog_enabled && fog_coord_support) { if(!fog_ext_en || fog_enabled != 2) glFogCoordfEXT((1.0f / *b_q)/**100.0f*/); else glFogCoordfEXT((1.0f / *b_fog)/**100.0f*/); } glVertex4f((*b_x - (float)widtho) / (float)(width/2) / *b_q, -(*b_y - (float)heighto) / (float)(height/2) / *b_q, z_en ? (*b_z / Z_MAX) / *b_q : 1.0f, 1.0f / *b_q); if (nbTextureUnits > 2) { if (st0_en) glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *c_s0 / *c_q / (float)tex1_width, *c_t0 / *c_q / (float)tex1_height); if (st1_en) glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *c_s1 / *c_q / (float)tex0_width, *c_t1 / *c_q / (float)tex0_height); } else { if (st0_en) glTexCoord2f(*c_s0 / *c_q / (float)tex0_width, *c_t0 / *c_q / (float)tex0_height); } if (pargb_en) glColor4f(c_pargb[2]/255.0f, c_pargb[1]/255.0f, c_pargb[0]/255.0f, c_pargb[3]/255.0f); if (fog_enabled && fog_coord_support) { if(!glsl_support) { if(!fog_ext_en || fog_enabled != 2) glFogCoordfEXT((1.0f / *c_q)/**100.0f*/); else glFogCoordfEXT((1.0f / *c_fog)/**100.0f*/); } else { if(!fog_ext_en || fog_enabled != 2) glSecondaryColor3f((1.0f / *c_q) / 256.0f, 0.0f, 0.0f); else glSecondaryColor3f((1.0f / *c_fog) / 256.0f, 0.0f, 0.0f); } } glVertex4f((*c_x - (float)widtho) / (float)(width/2) / *c_q, -(*c_y - (float)heighto) / (float)(height/2) / *c_q, z_en ? (*c_z / Z_MAX) / *c_q : 1.0f, 1.0f / *c_q); glEnd(); } FX_ENTRY void FX_CALL grDrawLine( const void *a, const void *b ) { float *a_x = (float*)a + xy_off/sizeof(float); float *a_y = (float*)a + xy_off/sizeof(float) + 1; float *a_z = (float*)a + z_off/sizeof(float); float *a_q = (float*)a + q_off/sizeof(float); unsigned char *a_pargb = (unsigned char*)a + pargb_off; float *a_s0 = (float*)a + st0_off/sizeof(float); float *a_t0 = (float*)a + st0_off/sizeof(float) + 1; float *a_s1 = (float*)a + st1_off/sizeof(float); float *a_t1 = (float*)a + st1_off/sizeof(float) + 1; float *a_fog = (float*)a + fog_ext_off/sizeof(float); float *b_x = (float*)b + xy_off/sizeof(float); float *b_y = (float*)b + xy_off/sizeof(float) + 1; float *b_z = (float*)b + z_off/sizeof(float); float *b_q = (float*)b + q_off/sizeof(float); unsigned char *b_pargb = (unsigned char*)b + pargb_off; float *b_s0 = (float*)b + st0_off/sizeof(float); float *b_t0 = (float*)b + st0_off/sizeof(float) + 1; float *b_s1 = (float*)b + st1_off/sizeof(float); float *b_t1 = (float*)b + st1_off/sizeof(float) + 1; float *b_fog = (float*)b + fog_ext_off/sizeof(float); //if(*a_fog == 0.0f) *a_fog = 1.0f; //if(*b_fog == 0.0f) *b_fog = 1.0f; if(glsl_support && need_to_compile) compile_shader(); glBegin(GL_LINES); if (nbTextureUnits > 2) { if (st0_en) glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *a_s0 / *a_q / (float)tex1_width, *a_t0 / *a_q / (float)tex1_height); if (st1_en) glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *a_s1 / *a_q / (float)tex0_width, *a_t1 / *a_q / (float)tex0_height); } else { if (st0_en) glTexCoord2f(*a_s0 / *a_q / (float)tex0_width, *a_t0 / *a_q / (float)tex0_height); } if (pargb_en) glColor4f(a_pargb[2]/255.0f, a_pargb[1]/255.0f, a_pargb[0]/255.0f, a_pargb[3]/255.0f); if (fog_enabled && fog_coord_support) { if(!glsl_support) { if(!fog_ext_en || fog_enabled != 2) glFogCoordfEXT((1.0f / *a_q)/**100.0f*/); else glFogCoordfEXT((1.0f / *a_fog)/**100.0f*/); } else { if(!fog_ext_en || fog_enabled != 2) glSecondaryColor3f((1.0f / *a_q) / 256.0f, 0.0f, 0.0f); else glSecondaryColor3f((1.0f / *a_fog) / 256.0f, 0.0f, 0.0f); } } glVertex4f((*a_x - (float)widtho) / (float)(width/2) / *a_q, -(*a_y - (float)heighto) / (float)(height/2) / *a_q, z_en ? (*a_z / Z_MAX) / *a_q : 1.0f, 1.0f / *a_q); if (nbTextureUnits > 2) { if (st0_en) glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *b_s0 / *b_q / (float)tex1_width, *b_t0 / *b_q / (float)tex1_height); if (st1_en) glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *b_s1 / *b_q / (float)tex0_width, *b_t1 / *b_q / (float)tex0_height); } else { if (st0_en) glTexCoord2f(*b_s0 / *b_q / (float)tex0_width, *b_t0 / *b_q / (float)tex0_height); } if (pargb_en) glColor4f(b_pargb[2]/255.0f, b_pargb[1]/255.0f, b_pargb[0]/255.0f, b_pargb[3]/255.0f); if (fog_enabled && fog_coord_support) { if(!glsl_support) { if(!fog_ext_en || fog_enabled != 2) glFogCoordfEXT((1.0f / *b_q)/**100.0f*/); else glFogCoordfEXT((1.0f / *b_fog)/**100.0f*/); } else { if(!fog_ext_en || fog_enabled != 2) glSecondaryColor3f((1.0f / *b_q) / 256.0f, 0.0f, 0.0f); else glSecondaryColor3f((1.0f / *b_fog) / 256.0f, 0.0f, 0.0f); } } glVertex4f((*b_x - (float)widtho) / (float)(width/2) / *b_q, -(*b_y - (float)heighto) / (float)(height/2) / *b_q, z_en ? (*b_z / Z_MAX) / *b_q : 1.0f, 1.0f / *b_q); glEnd(); } FX_ENTRY void FX_CALL grDrawVertexArray(FxU32 mode, FxU32 Count, void *pointers2) { unsigned int i; float *x, *y, *q, *s0, *t0, *s1, *t1, *z, *fog; unsigned char *pargb; void **pointers = (void**)pointers2; if(glsl_support && need_to_compile) compile_shader(); switch(mode) { case GR_TRIANGLE_FAN: glBegin(GL_TRIANGLE_FAN); break; default: display_warning((unsigned char*)"grDrawVertexArray : unknown mode : %x", mode); } for (i=0; i 2) { if (st0_en) glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *s0 / *q / (float)tex1_width, *t0 / *q / (float)tex1_height); if (st1_en) glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *s1 / *q / (float)tex0_width, *t1 / *q / (float)tex0_height); } else { if (st0_en) glTexCoord2f(*s0 / *q / (float)tex0_width, *t0 / *q / (float)tex0_height); } if (pargb_en) glColor4f(pargb[2]/255.0f, pargb[1]/255.0f, pargb[0]/255.0f, pargb[3]/255.0f); if (fog_enabled && fog_coord_support) { if(!glsl_support) { if(!fog_ext_en || fog_enabled != 2) glFogCoordfEXT((1.0f / *q)/**100.0f*/); else glFogCoordfEXT((1.0f / *fog)/**100.0f*/); } else { if(!fog_ext_en || fog_enabled != 2) glSecondaryColor3f((1.0f / *q) / 256.0f, 0.0f, 0.0f); else glSecondaryColor3f((1.0f / *fog) / 256.0f, 0.0f, 0.0f); } } //glFogCoordfEXT(192.0f); //glSecondaryColor3f(192.0f / 256.0f,0,0); //if((1.0f / *fog)/256.0f < 0.0f || (1.0f / *fog)/256.0f > 1.0f) glVertex4f((*x - (float)widtho) / (float)(width/2) / *q, -(*y - (float)heighto) / (float)(height/2) / *q, z_en ? (*z / Z_MAX) / *q : 1.0f, 1.0f / *q); } glEnd(); } FX_ENTRY void FX_CALL grDrawVertexArrayContiguous(FxU32 mode, FxU32 Count, void *pointers, FxU32 stride) { unsigned int i; float *x, *y, *q, *s0, *t0, *s1, *t1, *z, *fog; unsigned char *pargb; if(glsl_support && need_to_compile) compile_shader(); switch(mode) { case GR_TRIANGLE_STRIP: glBegin(GL_TRIANGLE_STRIP); break; case GR_TRIANGLE_FAN: glBegin(GL_TRIANGLE_FAN); break; default: display_warning((unsigned char*)"grDrawVertexArrayContiguous : unknown mode : %x", mode); } for (i=0; i 2) { if (st0_en) glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *s0 / *q / (float)tex1_width, *t0 / *q / (float)tex1_height); if (st1_en) glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *s1 / *q / (float)tex0_width, *t1 / *q / (float)tex0_height); } else { if (st0_en) glTexCoord2f(*s0 / *q / (float)tex0_width, *t0 / *q / (float)tex0_height); } if (pargb_en) glColor4f(pargb[2]/255.0f, pargb[1]/255.0f, pargb[0]/255.0f, pargb[3]/255.0f); if (fog_enabled && fog_coord_support) { if(!glsl_support) { if(!fog_ext_en || fog_enabled != 2) glFogCoordfEXT((1.0f / *q)/**100.0f*/); else glFogCoordfEXT((1.0f / *fog)/**100.0f*/); } else { if(!fog_ext_en || fog_enabled != 2) glSecondaryColor3f((1.0f / *q) / 256.0f, 0.0f, 0.0f); else glSecondaryColor3f((1.0f / *fog) / 256.0f, 0.0f, 0.0f); } } glVertex4f((*x - (float)widtho) / (float)(width/2) / *q, -(*y - (float)heighto) / (float)(height/2) / *q, z_en ? (*z / Z_MAX) / *q : 1.0f, 1.0f / *q); } glEnd(); }