/*!*************************************************************************** @Function GenerateBackgroundTexture @Input uiScreenWidth @Input uiScreenHeight @Description Generates a simple background texture procedurally. *****************************************************************************/ void OGLES2IntroducingPrint3D::GenerateBackgroundTexture(unsigned int uiScreenWidth, unsigned int uiScreenHeight) { // Generate star texture unsigned int uiStarW = PVRTGetPOTHigher(uiScreenWidth, 1); unsigned int uiStarH = PVRTGetPOTHigher(uiScreenHeight, 1); glGenTextures(1, &m_uiStarTex); glBindTexture(GL_TEXTURE_2D, m_uiStarTex); PVRTuint8* pTexData = new PVRTuint8[uiStarW*uiStarH]; memset(pTexData, 0, uiStarW*uiStarH); for (unsigned int uiY = 0; uiY < uiStarH; uiY++) { for (unsigned int uiX = 0; uiX < uiStarW; uiX++) { unsigned int uiIdx = (uiY*uiStarW+uiX); if(rand() % 200 == 1) { pTexData[uiIdx] = rand() % 255; } } } glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, uiStarW, uiStarH, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, pTexData); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); delete [] pTexData; bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen); m_BG.Init(NULL, bRotate, NULL); }
// NOTE: This function should be optimised unsigned int PVRTGetPOTLower(unsigned int uiOriginalValue, int iTimesLower) { if(uiOriginalValue == 0 || iTimesLower < 0) { return 0; } unsigned int uiSize = PVRTGetPOTHigher(uiOriginalValue,1); uiSize >>= 1;//uiSize /=2; for(int i = 1; i < iTimesLower; ++i) { uiSize >>= 1;//uiSize /=2; if(uiSize == 1) { // Lowest possible value has been reached, so break break; } } return uiSize; }