///---------------------------------------------------------------------------- ///We need texture coordinates as if the light source were the eye point; ///this matrix takes us from eye space to the light's clip space ///by concatenating the following matrices: T = P.V.Ci ///where T = Texture matrix /// P = Light's position projection matrix /// V = Light's position modelview matrix /// Ci= Camera's "Inverse" view matrix ///The tricky part is to compute the inverse camera view matrix but OpenGL ///will do that for us when the eye planes are specified ///---------------------------------------------------------------------------- void GLApp::CreateTextureMatrix() { GLdouble tmpMatrix[16]; glMatrixMode(GL_TEXTURE); glPushMatrix(); { glLoadIdentity(); glTranslated(0.5, 0.5, 0.5); glScaled(0.5, 0.5, 0.5); glMultMatrixd(m_LightProjectionMatrix); glMultMatrixd(m_LightViewMatrix); glGetDoublev(GL_TEXTURE_MATRIX, tmpMatrix); } glPopMatrix(); //We have the plane equation values but not in contiguos memory //transposing the matrix will solve this m_Geometry.Transpose4x4Matrix(tmpMatrix); //Specify the texture coordinate plane equations glTexGendv(GL_S, GL_EYE_PLANE, &tmpMatrix[0]); glTexGendv(GL_T, GL_EYE_PLANE, &tmpMatrix[4]); glTexGendv(GL_R, GL_EYE_PLANE, &tmpMatrix[8]); glTexGendv(GL_Q, GL_EYE_PLANE, &tmpMatrix[12]); }
void OpenGlRenderState::EnableProjectiveTexturing() const { #ifndef HAVE_GLES const pangolin::OpenGlMatrix projmattrans = GetProjectiveTextureMatrix().Transpose(); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glEnable(GL_TEXTURE_GEN_R); glEnable(GL_TEXTURE_GEN_Q); glTexGendv(GL_S, GL_EYE_PLANE, projmattrans.m); glTexGendv(GL_T, GL_EYE_PLANE, projmattrans.m+4); glTexGendv(GL_R, GL_EYE_PLANE, projmattrans.m+8); glTexGendv(GL_Q, GL_EYE_PLANE, projmattrans.m+12); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); #endif }
void make_stripes(void) { int i, j; static GLubyte data[16*8]; static GLubyte data1[16*8]; static GLubyte data2[16*8]; double d[] = { 0.f, 1.f, 0.f, 1.f}; for(i = 0; i < 8; i++) { for(j = 0; j < 16; j++) { float f = 1.; if (i < 2 || j < 4 ) f = 0.f; data[j*8+i] = f*255; f = 0.f; if (i < 4) f = 1.f; data1[j*8+i] = f*255; f = 0.f; if (j < 8) f = 1.f; data2[j*8+i] = f*255; } } glBindTexture(GL_TEXTURE_2D, 1); glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 8, 16, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glBindTexture(GL_TEXTURE_2D, 2); glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 8, 16, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, data1); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glBindTexture(GL_TEXTURE_2D, 3); glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 8, 16, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, data2); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); #if 0 glMatrixMode(GL_TEXTURE); glScalef(50.f, 1.f, 1.f); glScalef(.5f, .5f, 1.f); glMatrixMode(GL_MODELVIEW); #endif glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGendv(GL_T, GL_OBJECT_PLANE, d); CHECK_ERROR("make_stripes()"); }
void __glXDisp_TexGendv(GLbyte *pc) { #ifdef __GLX_ALIGN64 GLenum pname; GLint cmdlen; GLint compsize; pname = *(GLenum *)(pc + 4); compsize = __glTexGendv_size(pname); if (compsize < 0) compsize = 0; cmdlen = __GLX_PAD(8+compsize*8); if ((unsigned long)(pc) & 7) { __GLX_MEM_COPY(pc-4, pc, cmdlen); pc -= 4; } #endif glTexGendv( *(GLenum *)(pc + 0), *(GLenum *)(pc + 4), (GLdouble *)(pc + 8) ); }
void Scarry::draw(wardraw_t *wd){ Scarry *const p = this; static int init = 0; static suftex_t *pst; static suf_t *sufbase = NULL; if(!w) return; /* cull object */ /* if(beamer_cull(this, wd)) return;*/ // wd->lightdraws++; draw_healthbar(this, wd, health / getMaxHealth(), getHitRadius(), -1., capacitor / maxenergy()); if(wd->vw->gc->cullFrustum(pos, getHitRadius())) return; #if 0 if(init == 0) do{ init = 1; sufbase = CallLoadSUF("models/spacecarrier.bin"); if(!sufbase) break; CallCacheBitmap("bridge.bmp", "bridge.bmp", NULL, NULL); CallCacheBitmap("beamer_panel.bmp", "beamer_panel.bmp", NULL, NULL); CallCacheBitmap("bricks.bmp", "bricks.bmp", NULL, NULL); CallCacheBitmap("runway.bmp", "runway.bmp", NULL, NULL); suftexparam_t stp; stp.flags = STP_MAGFIL | STP_MINFIL | STP_ENV; stp.magfil = GL_LINEAR; stp.minfil = GL_LINEAR; stp.env = GL_ADD; stp.mipmap = 0; CallCacheBitmap5("engine2.bmp", "engine2br.bmp", &stp, "engine2.bmp", NULL); pst = AllocSUFTex(sufbase); extern GLuint screentex; glNewList(pst->a[0].list, GL_COMPILE); glBindTexture(GL_TEXTURE_2D, screentex); glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE); glDisable(GL_LIGHTING); glEndList(); } while(0); if(sufbase){ static const double normal[3] = {0., 1., 0.}; double scale = SCARRY_SCALE; static const GLdouble rotaxis[16] = { -1,0,0,0, 0,1,0,0, 0,0,-1,0, 0,0,0,1, }; Mat4d mat; glPushAttrib(GL_TEXTURE_BIT | GL_LIGHTING_BIT | GL_CURRENT_BIT | GL_ENABLE_BIT); glPushMatrix(); transform(mat); glMultMatrixd(mat); #if 1 for(int i = 0; i < nhitboxes; i++){ Mat4d rot; glPushMatrix(); gldTranslate3dv(hitboxes[i].org); rot = hitboxes[i].rot.tomat4(); glMultMatrixd(rot); hitbox_draw(this, hitboxes[i].sc); glPopMatrix(); } #endif Mat4d modelview, proj; glGetDoublev(GL_MODELVIEW_MATRIX, modelview); glGetDoublev(GL_PROJECTION_MATRIX, proj); Mat4d trans = proj * modelview; texture((glPushMatrix(), glScaled(1./2., 1./2., 1.), glTranslated(1, 1, 0), glMultMatrixd(trans) )); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGendv(GL_S, GL_EYE_PLANE, Vec4d(1,0,0,0)); glEnable(GL_TEXTURE_GEN_S); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGendv(GL_T, GL_EYE_PLANE, Vec4d(0,1,0,0)); glEnable(GL_TEXTURE_GEN_T); glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGeniv(GL_R, GL_EYE_PLANE, Vec4<int>(0,0,1,0)); glEnable(GL_TEXTURE_GEN_R); glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGeniv(GL_Q, GL_EYE_PLANE, Vec4<int>(0,0,0,1)); glEnable(GL_TEXTURE_GEN_Q); glPushMatrix(); glScaled(scale, scale, scale); glMultMatrixd(rotaxis); DecalDrawSUF(sufbase, SUF_ATR, NULL, pst, NULL, NULL); glPopMatrix(); texture((glPopMatrix())); glPopMatrix(); glPopAttrib(); } #endif }
void Scarry::drawtra(wardraw_t *wd){ st::drawtra(wd); Scarry *p = this; Scarry *pt = this; Mat4d mat; Vec3d pa, pb, pa0(.01, 0, 0), pb0(-.01, 0, 0); double scale; /* if(scarry_cull(pt, wd)) return;*/ if(wd->vw->gc->cullFrustum(pos, getHitRadius())) return; scale = fabs(wd->vw->gc->scale(this->pos)); transform(mat); const double blastscale = .04; drawCapitalBlast(wd, Vec3d(0, 0, .55), blastscale); drawCapitalBlast(wd, Vec3d(.08, .08, .55), blastscale); drawCapitalBlast(wd, Vec3d(-.08, .08, .55), blastscale); drawCapitalBlast(wd, Vec3d(-.08, -.08, .55), blastscale); drawCapitalBlast(wd, Vec3d(.08, -.08, .55), blastscale); pa = pt->rot.trans(pa0); pa += pt->pos; pb = pt->rot.trans(pb0); pb += pt->pos; glColor4ub(255,255,9,255); glBegin(GL_LINES); glVertex3dv(pa); glVertex3dv(pb); glEnd(); { int i; static const avec3_t lights[] = { {0, 520 * SCARRY_SCALE, 220 * SCARRY_SCALE}, {0, -520 * SCARRY_SCALE, 220 * SCARRY_SCALE}, {140 * SCARRY_SCALE, 370 * SCARRY_SCALE, 220 * SCARRY_SCALE}, {-140 * SCARRY_SCALE, 370 * SCARRY_SCALE, 220 * SCARRY_SCALE}, {140 * SCARRY_SCALE, -370 * SCARRY_SCALE, 220 * SCARRY_SCALE}, {-140 * SCARRY_SCALE, -370 * SCARRY_SCALE, 220 * SCARRY_SCALE}, {100 * SCARRY_SCALE, -360 * SCARRY_SCALE, -600 * SCARRY_SCALE}, {100 * SCARRY_SCALE, 360 * SCARRY_SCALE, -600 * SCARRY_SCALE}, { 280 * SCARRY_SCALE, 20 * SCARRY_SCALE, 520 * SCARRY_SCALE}, { 280 * SCARRY_SCALE, -20 * SCARRY_SCALE, 520 * SCARRY_SCALE}, {-280 * SCARRY_SCALE, 20 * SCARRY_SCALE, 520 * SCARRY_SCALE}, {-280 * SCARRY_SCALE, -20 * SCARRY_SCALE, 520 * SCARRY_SCALE}, {-280 * SCARRY_SCALE, 20 * SCARRY_SCALE, -300 * SCARRY_SCALE}, {-280 * SCARRY_SCALE, -20 * SCARRY_SCALE, -300 * SCARRY_SCALE}, { 280 * SCARRY_SCALE, 20 * SCARRY_SCALE, -480 * SCARRY_SCALE}, { 280 * SCARRY_SCALE, -20 * SCARRY_SCALE, -480 * SCARRY_SCALE}, }; avec3_t pos; double rad = .01; double t; GLubyte col[4] = {255, 31, 31, 255}; random_sequence rs; init_rseq(&rs, (unsigned long)this); /* color calculation of static navlights */ t = fmod(wd->vw->viewtime + drseq(&rs) * 2., 2.); if(t < 1.){ rad *= (t + 1.) / 2.; col[3] *= t; } else{ rad *= (2. - t + 1.) / 2.; col[3] *= 2. - t; } for(i = 0 ; i < numof(lights); i++){ mat4vp3(pos, mat, lights[i]); gldSpriteGlow(pos, rad, col, wd->vw->irot); } /* runway lights */ if(1 < scale * .01){ col[0] = 0; col[1] = 191; col[2] = 255; for(i = 0 ; i <= 10; i++){ avec3_t pos0; pos0[0] = -160 * SCARRY_SCALE; pos0[1] = 20 * SCARRY_SCALE + .0025; pos0[2] = (i * -460 + (10 - i) * -960) * SCARRY_SCALE / 10; rad = .005 * (1. - fmod(i / 10. + t / 2., 1.)); col[3] = 255/*rad * 255 / .01*/; mat4vp3(pos, mat, pos0); gldSpriteGlow(pos, rad, col, wd->vw->irot); pos0[0] = -40 * SCARRY_SCALE; mat4vp3(pos, mat, pos0); gldSpriteGlow(pos, rad, col, wd->vw->irot); pos0[1] = -20 * SCARRY_SCALE - .0025; mat4vp3(pos, mat, pos0); gldSpriteGlow(pos, rad, col, wd->vw->irot); pos0[0] = -160 * SCARRY_SCALE; mat4vp3(pos, mat, pos0); gldSpriteGlow(pos, rad, col, wd->vw->irot); } } /* for(i = 0; i < numof(p->turrets); i++) mturret_drawtra(&p->turrets[i], pt, wd);*/ } static int init = 0; static suftex_t *pst; static suf_t *sufbase = NULL; if(init == 0) do{ init = 1; sufbase = CallLoadSUF("models/spacecarrier.bin"); } while(0); if(sufbase){ static const double normal[3] = {0., 1., 0.}; double scale = SCARRY_SCALE; static const GLdouble rotaxis[16] = { -1,0,0,0, 0,1,0,0, 0,0,-1,0, 0,0,0,1, }; Mat4d mat; glPushAttrib(GL_TEXTURE_BIT | GL_LIGHTING_BIT | GL_CURRENT_BIT | GL_ENABLE_BIT); glEnable(GL_CULL_FACE); glPushMatrix(); transform(mat); glMultMatrixd(mat); extern GLuint screentex; glBindTexture(GL_TEXTURE_2D, screentex); glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE); glColor4f(1.,1.,1.,1.); glDisable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); Mat4d modelview, proj; glGetDoublev(GL_MODELVIEW_MATRIX, modelview); glGetDoublev(GL_PROJECTION_MATRIX, proj); Mat4d trans = proj * modelview; texture((glPushMatrix(), glScaled(1./2., 1./2., 1.), glTranslated(1, 1, 0), glMultMatrixd(trans) )); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGendv(GL_S, GL_EYE_PLANE, Vec4d(.9,0,0,0)); glEnable(GL_TEXTURE_GEN_S); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGendv(GL_T, GL_EYE_PLANE, Vec4d(0,.9,0,0)); glEnable(GL_TEXTURE_GEN_T); glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGendv(GL_R, GL_EYE_PLANE, Vec4d(0,0,.9,0)); glEnable(GL_TEXTURE_GEN_R); glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGeniv(GL_Q, GL_EYE_PLANE, Vec4<int>(0,0,0,1)); glEnable(GL_TEXTURE_GEN_Q); glPushMatrix(); glScaled(-scale, scale, -scale); DrawSUF(sufbase, 0, NULL); glPopMatrix(); texture((glPopMatrix())); glPopMatrix(); glPopAttrib(); } }
M(void, glTexGendv, jint coord, jint pname, jobject params) { glTexGendv(coord, pname, BUFF(GLdouble, params)); }
/* Render::initializeShadowMap: initialize OpenGL for shadow mapping */ void Render::initializeShadowMap(int textureSize) { static const GLdouble genfunc[][4] = { { 1.0, 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0, 0.0 }, { 0.0, 0.0, 1.0, 0.0 }, { 0.0, 0.0, 0.0, 1.0 }, }; /* initialize model view matrix */ glPushMatrix(); glLoadIdentity(); /* use 4th texture unit for depth texture, make it current */ glActiveTextureARB(GL_TEXTURE3_ARB); /* prepare a texture object for depth texture rendering in frame buffer object */ glGenTextures(1, &m_depthTextureID); glBindTexture(GL_TEXTURE_2D, m_depthTextureID); /* assign depth component to the texture */ glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, textureSize, textureSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0); /* set texture parameters for shadow mapping */ #ifdef RENDER_SHADOWPCF /* use hardware PCF */ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); #else glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); #endif /* RENDER_SHADOWPCF */ /* tell OpenGL to compare the R texture coordinates to the (depth) texture value */ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); /* also tell OpenGL to get the compasiron result as alpha value */ glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_ALPHA); /* set texture coordinates generation mode to use the raw texture coordinates (S, T, R, Q) in eye view */ glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGendv(GL_S, GL_EYE_PLANE, genfunc[0]); glTexGendv(GL_T, GL_EYE_PLANE, genfunc[1]); glTexGendv(GL_R, GL_EYE_PLANE, genfunc[2]); glTexGendv(GL_Q, GL_EYE_PLANE, genfunc[3]); /* finished configuration of depth texture: unbind the texture */ glBindTexture(GL_TEXTURE_2D, 0); /* allocate a frame buffer object (FBO) for depth buffer rendering */ glGenFramebuffersEXT(1, &m_fboID); /* switch to the newly allocated FBO */ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fboID); /* bind the texture to the FBO, telling that it should render the depth information to the texture */ glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, m_depthTextureID, 0); /* also tell OpenGL not to draw and read the color buffers */ glDrawBuffer(GL_NONE); glReadBuffer(GL_NONE); /* check FBO status */ if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT) { /* cannot use FBO */ } /* finished configuration of FBO, now switch to default frame buffer */ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); /* reset the current texture unit to default */ glActiveTextureARB(GL_TEXTURE0_ARB); /* restore the model view matrix */ glPopMatrix(); }
void gl4es_glMultiTexGendv(GLenum texunit, GLenum coord, GLenum pname, const GLdouble *params) { text(glTexGendv(coord, pname, params)); }
void ApronProc::DrawToScene(double dAlt,const std::vector<GLuint> texlist){ //static const GLdouble xcoord[]={0.001,0.0,0.0,0.0}; //static const GLdouble ycoord[]={0.0,0.001,0.0,0.0}; //glBindTexture(GL_TEXTURE_2D,texlist[(int)Textures::TextureEnum::APRON]); //glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); //glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR); //glTexGendv(GL_S,GL_OBJECT_PLANE,xcoord); //glEnable(GL_TEXTURE_GEN_S); //glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR); //glTexGendv(GL_T,GL_OBJECT_PLANE,ycoord); //glEnable(GL_TEXTURE_GEN_T); //glEnable(GL_TEXTURE_2D); // //glColor3d(1.0,1.0,1.0); //GLdouble buf[256][3]; //GLUtesselatorObj *tess=gluNewTess(); // //gluTessCallback(tess, GLU_TESS_BEGIN, (GLvoid (__stdcall *) ( )) &glBegin); //gluTessCallback(tess, GLU_TESS_END, (GLvoid (__stdcall *) ( )) &glEnd); //gluTessCallback(tess, GLU_TESS_VERTEX, (GLvoid (__stdcall *) ( )) &glVertex3dv); //gluTessCallback(tess, GLU_TESS_EDGE_FLAG, (GLvoid (__stdcall *) ( )) &glEdgeFlag); //gluTessCallback(tess, GLU_TESS_COMBINE, (GLvoid (__stdcall *) ( )) &combineCallback); //gluTessCallback(tess, GLU_TESS_ERROR, (GLvoid (__stdcall *) ( )) &errorCallback); //gluTessProperty(tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_NONZERO); //gluTessBeginPolygon(tess,NULL); //gluTessBeginContour(tess); //Path * pApronway=this->serviceLocationPath(); //for( int i=0;i<pApronway->getCount();i++){ // Point & _p=pApronway->getPoint(i); // buf[i][0]=_p.getX(); // buf[i][1]=_p.getY(); // buf[i][2]=0.0; // gluTessVertex(tess,buf[i],buf[i]); //} //gluTessEndContour(tess); //gluTessEndPolygon(tess); //gluDeleteTess(tess); // //glDisable(GL_TEXTURE_2D); //glDisable(GL_TEXTURE_GEN_S); //glDisable(GL_TEXTURE_GEN_T); static const GLdouble xcoord[]={0.001,0.0,0.0,0.0}; static const GLdouble ycoord[]={0.0,0.001,0.0,0.0}; glBindTexture(GL_TEXTURE_2D,texlist[(int)Textures::APRON]); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR); glTexGendv(GL_S,GL_OBJECT_PLANE,xcoord); glEnable(GL_TEXTURE_GEN_S); glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR); glTexGendv(GL_T,GL_OBJECT_PLANE,ycoord); glEnable(GL_TEXTURE_GEN_T); glEnable(GL_TEXTURE_2D); GLdouble buf[256][3]; CTessellationManager* pTM = CTessellationManager::GetInstance(); pTM->Init(CTessellationManager::Render); pTM->BeginPolygon(); pTM->BeginContour(); Path * pApronway=this->serviceLocationPath(); for( int i=0;i<pApronway->getCount();i++){ Point _p=pApronway->getPoint(i); buf[i][0]=_p.getX(); buf[i][1]=_p.getY(); buf[i][2]=dAlt; pTM->ContourVertex(buf[i]); } pTM->EndContour(); pTM->EndPolygon(); pTM->End(); glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); }
void ApplyShadowMap() { // Now comes the juice of this tutorial. What this function will do is: // // 1) Turn on texture mapping // 2) Bind our shadow texture that holds the depth values // 3) Set our texture mode and function for shadow mapping // 4) Turn on and set OpenGL texture generation by GL_EYE_LINEAR // 5) Load the light's matrices into the texture matrix // 6) Render the world that will be shadowed // 7) Restore and turn everything off again // // Turn on our texture unit for shadow mapping and bind our depth texture glActiveTextureARB(GL_TEXTURE0_ARB); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, g_Texture[SHADOW_ID]); // Here is where we set the mode and function for shadow-mapping in fixed functionality. // The mode we use is GL_TEXTURE_COMPARE_MODE_ARB, with GL_COMPARE_R_TO_TEXTURE_ARB, which // tells OpenGL that we want to compare the depth value in our world to the current // texture's depth value. We then set the compare function to GL_LEQUAL, which says that // we will not shadow the current pixel if the depth value is less than or equal to // the texture's depth value. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL); // Let's explain really fast about why we need a "bias" matrix. Well, when we multiply // our world data by the projection and modelview matrix it converts it to clip space, // which is a box that is measured in -1 to 1. Then this is later converted to screen // coordinates. Now, our texture coordinates are clamped from 0 to 1 right? We are // working in the light's clip space and we want to convert the -1 to 1 ratio to a // 0 to 1 ratio, which will measure up with our texture coordinates. To do this we // need a "bias" matrix that will convert from -1 to 1 to a 0 to 1 ratio. We first // load the bias matrix into our texture matrix and then multiply the projection and // modelview matrix by the bias matrix. The bias matrix that will do this is below. // It's the same thing as doing this to every coordinate: newCoord = (oldCoord + 1) / 2; const float mBias[] = {0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0 }; // Now comes the complicated part to grasp at first. If you have never used the // texture generation functionality in OpenGL for sphere mapping or something else, // I will give a basic explanation of what it does. So that we don't have to // do the work ourselves of calculating every UV coordinate, we can have the UV // coordinates generated by OpenGL for us, given a bunch of different inputs to work from. // We can use OpenGL's texture generation functionality to project our camera depth values // into the light's clip space. Since our matrices are 4x4, we need to do our // projection in 4D. Thus, we use texture coordinates S, T, R and Q. // We first create planes for each axis (x, y, z, w). This will be used // with our projection of our camera's view to the light's clip space and // make sure the texture coordinates don't move when our camera moves, but // are the same no matter where our camera is looking. The equation for // doing projected texturing is: // // mProjectedTexture = mLightProjection * mLightModelview * mCameraInverse; // // We say the "camera inverse", but really it is the modelview matrix's inverse // that has the camera's view applied to it. So this is what we mean when we say that. // Usually we will need to multiply the inverse of our camera matrix by the projection // and modelview matrix of the light; however, when using these planes for our camera // OpenGL will calculate the inverse of our camera for us. In the GLSL version of // shadow mapping we calculate the camera inverse ourselves. // Create the eye planes for generating texture coordinates const double xPlane[] = {1.0, 0.0, 0.0, 0.0}; const double yPlane[] = {0.0, 1.0, 0.0, 0.0}; const double zPlane[] = {0.0, 0.0, 1.0, 0.0}; const double wPlane[] = {0.0, 0.0, 0.0, 1.0}; // Enable texture generation for S, T, R, and Q glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glEnable(GL_TEXTURE_GEN_R); glEnable(GL_TEXTURE_GEN_Q); // Set each texture coordinate's texture gen mode to use the camera. // This will have OpenGL incorporate the camera's inverse for us. glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); // Set our planes for each coordinate in order to project the texture appropriatly. glTexGendv(GL_S, GL_EYE_PLANE, xPlane ); glTexGendv(GL_T, GL_EYE_PLANE, yPlane ); glTexGendv(GL_R, GL_EYE_PLANE, zPlane ); glTexGendv(GL_Q, GL_EYE_PLANE, wPlane ); // Now we actually do the matrix multiplication. First we switch to texture // mode. That way we aren't effecting the modelview matrix. Then we load in // the bias matrix, multiply that by the light's projection matrix, then multiply // that result by the light's modelview matrix. This, in conjunction with our // camera inverse matrix calculated by OpenGL for us, gives us the right matrix // for projecting everything that needs to be projected. That is, the camera's // depth values into the light's clip space, then the generated shadow map onto // the geometry of the world. glMatrixMode(GL_TEXTURE); glLoadMatrixf(mBias); // The bias matrix to convert to a 0 to 1 ratio glMultMatrixf(g_mProjection); // The light's projection matrix glMultMatrixf(g_mModelView); // The light's modelview matrix glMatrixMode(GL_MODELVIEW); // Switch back to normal modelview mode RenderWorld(); // Render the world that needs to be shadowed // Now that the world is shadowed and we are done with the texture generation, // let's set everything back to normal by resetting the texture matrix. glMatrixMode(GL_TEXTURE); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); // Turn off texture generation for our S, T, R and Q coordinates glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); glDisable(GL_TEXTURE_GEN_R); glDisable(GL_TEXTURE_GEN_Q); // Turn the first multi-texture pass off glActiveTextureARB(GL_TEXTURE0_ARB); glDisable(GL_TEXTURE_2D); }