//=========================================================================== // // Gets the average color of a texture for use as a sky cap color // //=========================================================================== static PalEntry SkyCapColor(FTextureID texno, bool bottom) { PalEntry col; FTexture *tex = TexMan[texno]; if (!tex) return 0; if (!tex->gl_info.bSkyColorDone) { tex->gl_info.bSkyColorDone = true; FGLTexture * gltex = FGLTexture::ValidateTexture(tex); if (tex) { int w; int h; unsigned char * buffer = gltex->CreateTexBuffer(FGLTexture::GLUSE_TEXTURE, CM_DEFAULT, 0, w, h); if (buffer) { tex->gl_info.CeilingSkyColor = averageColor((DWORD *) buffer, w * MIN(30, h), 0); if (h>30) { tex->gl_info.FloorSkyColor = averageColor(((DWORD *) buffer)+(h-30)*w, w * 30, 0); } else tex->gl_info.FloorSkyColor = tex->gl_info.CeilingSkyColor; delete buffer; } } } return bottom? tex->gl_info.FloorSkyColor : tex->gl_info.CeilingSkyColor; }
//=========================================================================== // // Gets the average color of a texture for use as a sky cap color // //=========================================================================== static PalEntry SkyCapColor(unsigned int texno, bool bottom) { PalEntry col; if (!SkyColors) { MaxSkyTexture=TexMan.NumTextures(); SkyColors=new PalEntry[MaxSkyTexture*2]; // once for top cap, once for bottom cap memset(SkyColors, 0, sizeof(PalEntry)*MaxSkyTexture); } if (texno<MaxSkyTexture) { if (SkyColors[texno].a==0) { FGLTexture * tex = FGLTexture::ValidateTexture(texno); if (tex) { int w; int h; unsigned char * buffer = tex->CreateTexBuffer(CM_DEFAULT, 0, NULL, w, h); if (buffer) { SkyColors[texno]=averageColor((unsigned long *) buffer, w * MIN(30, h), false); if (h>30) { SkyColors[texno+MaxSkyTexture]= averageColor(((unsigned long *) buffer)+(h-30)*w, w * 30, false); } else SkyColors[texno+MaxSkyTexture]=SkyColors[texno]; delete buffer; SkyColors[texno].a=1; // mark as processed } } } return SkyColors[texno+MaxSkyTexture*bottom]; } else { return 0; } }