void RenderSoftGlare (CFloatVector *sprite, CFloatVector *vCenter, int nTexture, float fIntensity, int bAdditive, int bColored) { tRgbaColorf color; tTexCoord2f tcGlare [4] = {{{0,0}},{{1,0}},{{1,1}},{{0,1}}}; int i; CBitmap* bmP = NULL; if (gameStates.render.bQueryCoronas) { glDisable (GL_TEXTURE_2D); glBlendFunc (GL_ONE, GL_ZERO); } else { glEnable (GL_TEXTURE_2D); glDepthFunc (GL_ALWAYS); if (bAdditive) glBlendFunc (GL_ONE, GL_ONE); if (!(bmP = bAdditive ? bmpGlare : bmpCorona)) return; } if (gameStates.render.bAmbientColor) color = gameData.render.color.textures [nTexture].color; else color.red = color.green = color.blue = X2F (IsLight (nTexture)) / 2; if (!bColored) color.red = color.green = color.blue = (color.red + color.green + color.blue) / 4; if (gameOptions [0].render.coronas.nStyle == 1) fIntensity = float (sqrt (fIntensity)); if (bAdditive) glColor4f (fIntensity * color.red, fIntensity * color.green, fIntensity * color.blue, 1); else glColor4f (color.red, color.green, color.blue, fIntensity); if (ogl.EnableClientStates (gameStates.render.bQueryCoronas == 0, 0, 0, GL_TEXTURE0)) { if (!gameStates.render.bQueryCoronas) { bmP->Bind (1); OglTexCoordPointer (2, GL_FLOAT, 0, tcGlare); } OglVertexPointer (3, GL_FLOAT, sizeof (CFloatVector), sprite); OglDrawArrays (GL_QUADS, 0, 4); ogl.DisableClientStates (gameStates.render.bQueryCoronas == 0, 0, 0, GL_TEXTURE0); } else { if (gameStates.render.bQueryCoronas == 0) bmP->Bind (1); glBegin (GL_QUADS); for (i = 0; i < 4; i++) { glTexCoord2fv (reinterpret_cast<GLfloat*> (tcGlare + i)); glVertex3fv (reinterpret_cast<GLfloat*> (sprite + i)); } glEnd (); } if (!gameStates.render.bQueryCoronas && bAdditive) glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); RenderCoronaOutline (sprite, vCenter); if (gameStates.render.bQueryCoronas != 2) { glEnable (GL_DEPTH_TEST); if (gameStates.render.bQueryCoronas == 1) glDepthFunc (GL_LEQUAL); } }
void RenderHardGlare (CFloatVector *sprite, CFloatVector *vCenter, int nTexture, float fLight, float fIntensity, tIntervalf *zRangeP, int bAdditive, int bColored) { tTexCoord2f tcGlare [4] = {{{0,0}},{{1,0}},{{1,1}},{{0,1}}}; tRgbaColorf color; CBitmap* bmP; int i; fLight /= 4; if (fLight < 0.01f) return; color.alpha = vCenter->Mag (); if (color.alpha < zRangeP->fRad) fIntensity *= color.alpha / zRangeP->fRad; if (gameStates.render.bAmbientColor) { color = gameData.render.color.textures [nTexture].color; color.alpha = (float) (color.red * 3 + color.green * 5 + color.blue * 2) / 30 * 2; } else { color.alpha = X2F (IsLight (nTexture)); color.red = color.green = color.blue = color.alpha / 2; color.alpha *= 2.0f / 3.0f; } if (!bColored) color.red = color.green = color.blue = (color.red + color.green + color.blue) / 4; color.alpha *= fIntensity * fIntensity; if (color.alpha < 0.01f) return; glEnable (GL_TEXTURE_2D); if (!(bmP = bAdditive ? bmpGlare : bmpCorona)) return; bmP->SetTranspType (-1); if (bmP->Bind (1)) return; bmP->Texture ()->Wrap (GL_CLAMP); glDisable (GL_CULL_FACE); if (bAdditive) { fLight *= color.alpha; glBlendFunc (GL_ONE, GL_ONE); } glColor4fv (reinterpret_cast<GLfloat*> (&color)); glBegin (GL_QUADS); for (i = 0; i < 4; i++) { glTexCoord2fv (reinterpret_cast<GLfloat*> (tcGlare + i)); glVertex3fv (reinterpret_cast<GLfloat*> (sprite + i)); } glEnd (); if (bAdditive) glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable (GL_CULL_FACE); RenderCoronaOutline (sprite, vCenter); }
void RenderShadowTexture (void) { if (!(shadowProg || (CreateShaderProg (&shadowProg) && CreateShaderFunc (&shadowProg, &shadowFS, &shadowVS, pszShadowFS, pszShadowVS, 1) && LinkShaderProg (&shadowProg)))) return; glMatrixMode (GL_MODELVIEW); glPushMatrix (); glLoadIdentity (); glMatrixMode (GL_PROJECTION); glPushMatrix (); glLoadIdentity (); glOrtho (0, 1, 1, 0, 0, 1); glDisable (GL_DEPTH_TEST); glDepthMask (0); #if 1 glDisable (GL_BLEND); #else glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); #endif glEnable (GL_TEXTURE_2D); ogl.SelectTMU (GL_TEXTURE0); shadowBuf.SetTranspType (0); if (shadowBuf.Bind (0)) return; glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); #if 0 glUseProgramObject (shadowProg); glUniform1i (glGetUniformLocation (shadowProg, "shadowTex"), 0); #endif glBegin (GL_QUADS); glTexCoord2d (0,0); glVertex2d (0,0); glTexCoord2d (1,0); glVertex2d (0.5,0); glTexCoord2d (1,-1); glVertex2d (0.5,0.5); glTexCoord2d (0,-1); glVertex2d (0,0.5); glEnd (); if (ogl.m_states.bShadersOk) glUseProgramObject (0); glEnable (GL_DEPTH_TEST); glDepthMask (1); glPopMatrix (); glMatrixMode (GL_MODELVIEW); glPopMatrix (); }
int LoadAddonBitmap (CBitmap **bmPP, const char *pszName, int *bHaveP) { if (!*bHaveP) { char szFilename [FILENAME_LEN]; CFile cf; sprintf (szFilename, "%s/d2x-xl/%s", gameFolders.szTextureDir [2], pszName); if (!cf.Exist (szFilename, "", 0)) sprintf (szFilename, "%s/d2x-xl/%s", gameFolders.szTextureDir [0], pszName); CBitmap *bmP = CreateAndReadTGA (szFilename); if (!bmP) *bHaveP = -1; else { *bHaveP = 1; bmP->SetFrameCount (); bmP->SetTranspType (-1); bmP->Bind (1); } *bmPP = bmP; } return *bHaveP > 0; }
CBitmap* CBackgroundManager::LoadBackground (char* filename) { int width, height; if (PCXGetDimensions (filename, &width, &height) != PCX_ERROR_NONE) { Error ("Could not open menu background file <%s>\n", filename); return NULL; } CBitmap* bmP; if (!(bmP = CBitmap::Create (0, width, height, 1))) { Error ("Not enough memory for menu backgroun\n"); return NULL; } if (PCXReadBitmap (filename, bmP, bmP->Mode (), 0) != PCX_ERROR_NONE) { Error ("Could not read menu background file <%s>\n", filename); return NULL; } bmP->SetName (filename); bmP->SetTranspType (3); bmP->Bind (0); return bmP; }
int CParticle::Render (float brightness) { CFixVector hp; GLfloat d, u, v; CBitmap* bmP; tRgbaColorf pc; tParticleVertex* pb; CFloatVector vOffset, vCenter; int i, nFrame, nType = m_nType, bEmissive = m_bEmissive; float decay = (nType == BUBBLE_PARTICLES) ? 1.0f : (float) m_nLife / (float) m_nTTL; static int nFrames = 1; static float deltaUV = 1.0f; static tSinCosf sinCosPart [PARTICLE_POSITIONS]; static int bInitSinCos = 1; static CFloatMatrix mRot; if (m_nDelay > 0) return 0; if ((nType < 0) || (nType >= PARTICLE_TYPES)) return 0; if (!(bmP = bmpParticle [0][nType])) return 0; if (bmP->CurFrame ()) bmP = bmP->CurFrame (); if (gameOpts->render.bDepthSort > 0) { hp = m_vTransPos; if ((particleManager.LastType () != nType) || (brightness != bufferBrightness) || (bBufferEmissive != bEmissive)) { particleManager.FlushBuffer (brightness); particleManager.SetLastType (nType); bBufferEmissive = bEmissive; ogl.SelectTMU (GL_TEXTURE0, true); if (bmP->Bind (0)) return 0; nFrames = nParticleFrames [0][nType]; deltaUV = 1.0f / (float) nFrames; if (m_bEmissive) //glBlendFunc (GL_ONE, GL_ONE); glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_COLOR); else glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } } else if (gameOpts->render.particles.bSort) { hp = m_vTransPos; if ((particleManager.LastType () != nType) || (brightness != bufferBrightness)) { particleManager.FlushBuffer (brightness); particleManager.SetLastType (nType); if (bmP->Bind (0)) return 0; nFrames = nParticleFrames [0][nType]; deltaUV = 1.0f / (float) nFrames; if (m_bEmissive) glBlendFunc (GL_ONE, GL_ONE); else glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } } else transformation.Transform(hp, m_vPos, 0); if (m_bBright) brightness = (float) sqrt (brightness); if (nType == SMOKE_PARTICLES) { if (m_nFade > 0) { if (m_color [0].green < m_color [1].green) { #if SMOKE_SLOWMO m_color [0].green += 1.0f / 20.0f / (float) gameStates.gameplay.slowmo [0].fSpeed; #else m_color [0].green += 1.0f / 20.0f; #endif if (m_color [0].green > m_color [1].green) { m_color [0].green = m_color [1].green; m_nFade--; } } if (m_color [0].blue < m_color [1].blue) { #if SMOKE_SLOWMO m_color [0].blue += 1.0f / 10.0f / (float) gameStates.gameplay.slowmo [0].fSpeed; #else m_color [0].blue += 1.0f / 10.0f; #endif if (m_color [0].blue > m_color [1].blue) { m_color [0].blue = m_color [1].blue; m_nFade--; } } } else if (m_nFade == 0) { m_color [0].red = m_color [1].red * RANDOM_FADE; m_color [0].green = m_color [1].green * RANDOM_FADE; m_color [0].blue = m_color [1].blue * RANDOM_FADE; m_nFade = -1; } } pc = m_color [0]; //pc.alpha *= /*gameOpts->render.particles.bDisperse ? decay2 :*/ decay; if ((nType == SMOKE_PARTICLES) || (nType == BUBBLE_PARTICLES)) { char nFrame = ((nType == BUBBLE_PARTICLES) && !gameOpts->render.particles.bWobbleBubbles) ? 0 : m_nFrame; u = (float) (nFrame % nFrames) * deltaUV; v = (float) (nFrame / nFrames) * deltaUV; d = deltaUV; } else { u = v = 0.0f; d = 1.0f; } if (nType == SMOKE_PARTICLES) { #if 0 if (SHOW_DYN_LIGHT) { tFaceColor *psc = AvgSgmColor (m_nSegment, NULL); pc.red *= (float) psc->color.red; pc.green *= (float) psc->color.green; pc.blue *= (float) psc->color.blue; } #endif brightness *= 0.9f + (float) (rand () % 1000) / 5000.0f; pc.red *= brightness; pc.green *= brightness; pc.blue *= brightness; } vCenter.Assign (hp); i = m_nOrient; if (bEmissive) { //scale light trail particle color to reduce saturation pc.red /= 50.0f; pc.green /= 50.0f; pc.blue /= 50.0f; } else if (m_nType != BUBBLE_PARTICLES) { #if 0 pc.alpha = (pc.alpha - 0.005f) * decay + 0.005f; # if 1 pc.alpha = (float) pow (pc.alpha * pc.alpha, 1.0 / 3.0); # endif #else float fFade = (float) cos ((double) sqr (1 - decay) * Pi) / 2.0f + 0.5f; pc.alpha *= fFade; #endif pc.alpha *= 0.6f; //alphaScale [gameOpts->render.particles.nAlpha [gameOpts->render.particles.bSyncSizes ? 0 : m_nClass]]; } if (pc.alpha < 1.0 / 255.0) { m_nLife = 0; return 0; } #if 0 if (!lightManager.Headlights ().nLights && (pc.red + pc.green + pc.blue < 0.001)) { m_nLife = 0; return 0; } #endif if ((nType == SMOKE_PARTICLES) && gameOpts->render.particles.bDisperse) { #if 0 decay = (float) sqrt (decay); #else decay = (float) pow (decay * decay * decay, 1.0f / 5.0f); #endif vOffset [X] = X2F (m_nWidth) / decay; vOffset [Y] = X2F (m_nHeight) / decay; } else { vOffset [X] = X2F (m_nWidth) * decay; vOffset [Y] = X2F (m_nHeight) * decay; } vOffset [Z] = 0; pb = particleBuffer + iBuffer; pb [i].texCoord.v.u = pb [(i + 3) % 4].texCoord.v.u = u; pb [i].texCoord.v.v = pb [(i + 1) % 4].texCoord.v.v = v; pb [(i + 1) % 4].texCoord.v.u = pb [(i + 2) % 4].texCoord.v.u = u + d; pb [(i + 2) % 4].texCoord.v.v = pb [(i + 3) % 4].texCoord.v.v = v + d; pb [0].color = pb [1].color = pb [2].color = pb [3].color = pc; if ((nType == BUBBLE_PARTICLES) && gameOpts->render.particles.bWiggleBubbles) vCenter [X] += (float) sin (m_nFrame / 4.0f * Pi) / (10 + rand () % 6); if (!nType && gameOpts->render.particles.bRotate) { if (bInitSinCos) { ComputeSinCosTable (sizeofa (sinCosPart), sinCosPart); bInitSinCos = 0; mRot.RVec ()[Z] = mRot.UVec ()[Z] = mRot.FVec ()[X] = mRot.FVec ()[Y] = 0; mRot.FVec ()[Z] = 1; } nFrame = (m_nOrient & 1) ? 63 - m_nRotFrame : m_nRotFrame; mRot.RVec ()[X] = mRot.UVec ()[Y] = sinCosPart [nFrame].fCos; mRot.UVec ()[X] = sinCosPart [nFrame].fSin; mRot.RVec ()[Y] = -mRot.UVec ()[X]; vOffset = mRot * vOffset; pb [0].vertex [X] = vCenter [X] - vOffset [X]; pb [0].vertex [Y] = vCenter [Y] + vOffset [Y]; pb [1].vertex [X] = vCenter [X] + vOffset [Y]; pb [1].vertex [Y] = vCenter [Y] + vOffset [X]; pb [2].vertex [X] = vCenter [X] + vOffset [X]; pb [2].vertex [Y] = vCenter [Y] - vOffset [Y]; pb [3].vertex [X] = vCenter [X] - vOffset [Y]; pb [3].vertex [Y] = vCenter [Y] - vOffset [X]; pb [0].vertex [Z] = pb [1].vertex [Z] = pb [2].vertex [Z] = pb [3].vertex [Z] = vCenter [Z]; } else { pb [0].vertex [X] = pb [3].vertex [X] = vCenter [X] - vOffset [X]; pb [1].vertex [X] = pb [2].vertex [X] = vCenter [X] + vOffset [X]; pb [0].vertex [Y] = pb [1].vertex [Y] = vCenter [Y] + vOffset [Y]; pb [2].vertex [Y] = pb [3].vertex [Y] = vCenter [Y] - vOffset [Y]; pb [0].vertex [Z] = pb [1].vertex [Z] = pb [2].vertex [Z] = pb [3].vertex [Z] = vCenter [Z]; } iBuffer += 4; if (iBuffer >= VERT_BUF_SIZE) particleManager.FlushBuffer (brightness); if (particleManager.Animate ()) { m_nFrame = (m_nFrame + 1) % (nFrames * nFrames); if (!(nType || (m_nFrame & 1))) m_nRotFrame = (m_nRotFrame + 1) % 64; } if (gameOpts->render.bDepthSort > 0) glEnd (); return 1; }
int CSubModel::Draw (CObject *objP, CModel *po, float *fLight) { CFace* pf; CFaceVert* pfv; CFloatVector* pv, * pvn, * phv; tFaceColor* pvc, vc, sc = {{1,1,1,1}}; CBitmap *bmP; int h, i, j; int bBright = EGI_FLAG (bBrightObjects, 0, 1, 0); int bDynLighting = gameStates.render.bApplyDynLight; float fl, r, g, b, fAlpha = po->m_fAlpha; #if DBG_SHADOWS if (bShadowTest && (bShadowTest < 4)) return 1; #endif pv = m_rotVerts.Buffer (); pvn = m_normals.Buffer (); pvc = m_vertColors.Buffer (); //memset (pvc, 0, m_nVerts * sizeof (tFaceColor)); glEnable (GL_CULL_FACE); OglCullFace (0); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (!bDynLighting) { sc = *lightManager.AvgSgmColor (objP->info.nSegment, &objP->info.position.vPos); if (sc.index != gameStates.render.nFrameFlipFlop + 1) sc.color.red = sc.color.green = sc.color.blue = 1; } for (i = m_faces.m_nFaces, pf = m_faces.m_list.Buffer (); i; i--, pf++) { if (pf->m_bReverse) glFrontFace (GL_CCW); pfv = pf->m_verts; #if 0 if (!(gameStates.ogl.bUseTransform || OOF_FrontFace (pso, pf))) continue; #endif if (pf->m_bTextured) { #if DBG fl = pf->m_vNormal * mView.FVec(); fl = 0.75f + 0.25f * fl; fl = fl * *fLight; #else fl = *fLight * (0.75f - 0.25f * (pf->m_vNormal * mView.FVec ())); #endif if (fl > 1) fl = 1; // fl = 1.0f; bmP = po->m_textures.m_bitmaps + pf->m_texProps.nTexId; if (bmP->Texture () && ((int) bmP->Texture ()->Handle () < 0)) bmP->Texture ()->SetHandle (0); bmP->SetTranspType (0); if (bmP->Bind (1)) return 0; bmP->Texture ()->Wrap (GL_REPEAT); if (m_nFlags & (bDynLighting ? OOF_SOF_THRUSTER : (OOF_SOF_GLOW | OOF_SOF_THRUSTER))) { glColor4f (fl * m_glowInfo.m_color.red, fl * m_glowInfo.m_color.green, fl * m_glowInfo.m_color.blue, m_pfAlpha [pfv->m_nIndex] * fAlpha); } else if (!bDynLighting) { #if 0 fl = (float) sqrt (fl); #endif if (bBright) #if 1 fl += (1 - fl) / 2; #else fl = (float) sqrt (fl); #endif glColor4f (sc.color.red * fl, sc.color.green * fl, sc.color.blue * fl, m_pfAlpha [pfv->m_nIndex] * fAlpha); } glBegin (GL_TRIANGLE_FAN); for (j = pf->m_nVerts; j; j--, pfv++) { phv = pv + (h = pfv->m_nIndex); if (bDynLighting) { if (pvc [h].index != gameStates.render.nFrameFlipFlop + 1) G3VertexColor (reinterpret_cast<CFloatVector3*> (pvn + h), reinterpret_cast<CFloatVector3*> (phv), -1, pvc + h, NULL, 1, 0, 0); vc.color.red = (float) sqrt (pvc [h].color.red); vc.color.green = (float) sqrt (pvc [h].color.green); vc.color.blue = (float) sqrt (pvc [h].color.blue); if (bBright) { #if 1 vc.color.red += (1 - vc.color.red) / 2; vc.color.green += (1 - vc.color.green) / 2; vc.color.blue += (1 - vc.color.blue) / 2; #else vc.color.red = (float) sqrt (vc.color.red); vc.color.green = (float) sqrt (vc.color.green); vc.color.blue = (float) sqrt (vc.color.blue); #endif } OglColor4sf (vc.color.red, vc.color.green, vc.color.blue, m_pfAlpha [pfv->m_nIndex] * fAlpha); } glTexCoord2f (pfv->m_fu, pfv->m_fv); glVertex3fv (reinterpret_cast<GLfloat*> (phv)); //glVertex4f (phv->m_x, phv->m_y, phv->m_z, 0.5); } glEnd (); #if DBG_SHADOWS if (pf->m_bFacingLight && (bShadowTest > 3)) { CFloatVector fv0; glLineWidth (3); glColor4f (1.0f, 0.0f, 0.5f, 1.0f); glBegin (GL_LINES); fv0 = pf->m_vRotCenter; glVertex3fv (reinterpret_cast<GLfloat*> (&fv0)); fv0 += pf->m_vRotNormal; glVertex3fv (reinterpret_cast<GLfloat*> (&fv0)); glEnd (); glColor4f (0.0f, 1.0f, 0.5f, 1.0f); glBegin (GL_LINES); fv0 = pf->m_vRotCenter; glVertex3fv (reinterpret_cast<GLfloat*> (&fv0)); fv0 = vrLightPos; glVertex3fv (reinterpret_cast<GLfloat*> (&fv0)); glEnd (); glLineWidth (1); } #endif } else { fl = fLight [1]; r = fl * (float) pf->m_texProps.color.red / 255.0f; g = fl * (float) pf->m_texProps.color.green / 255.0f; b = fl * (float) pf->m_texProps.color.blue / 255.0f; glColor4f (r, g, b, m_pfAlpha [pfv->m_nIndex] * fAlpha); glBegin (GL_TRIANGLE_FAN); for (j = pf->m_nVerts, pfv = pf->m_verts; j; j--, pfv++) { glVertex3fv (reinterpret_cast<GLfloat*> (pv + pfv->m_nIndex)); } glEnd (); } if (pf->m_bReverse) glFrontFace (GL_CW); } return 1; }