force backgrond images to power of 2
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@1943 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: f0231441216b74521a7d7e64221e7fec10547f7a Former-commit-id: dd20c660149fec47e5787e855120fa300a27fce1
This commit is contained in:
parent
574576aae0
commit
ce67238949
3 changed files with 75 additions and 5 deletions
|
@ -203,6 +203,7 @@ GfuiDisplay(void)
|
|||
glColor3f(GfuiColor[GFUI_BASECOLORBGIMAGE][0],GfuiColor[GFUI_BASECOLORBGIMAGE][1],GfuiColor[GFUI_BASECOLORBGIMAGE][2]);
|
||||
glBindTexture(GL_TEXTURE_2D, GfuiScreen->bgImage);
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
glTexCoord2f(tx1, ty1); glVertex3f(0.0, 0.0, 0.0);
|
||||
glTexCoord2f(tx1, ty2); glVertex3f(0.0, GfuiScreen->height, 0.0);
|
||||
glTexCoord2f(tx2, ty2); glVertex3f(GfuiScreen->width, GfuiScreen->height, 0.0);
|
||||
|
@ -997,12 +998,10 @@ GfuiScreenAddBgImg(void *scr, const char *filename)
|
|||
return;
|
||||
}
|
||||
|
||||
glGenTextures(1, &screen->bgImage);
|
||||
glBindTexture(GL_TEXTURE_2D, screen->bgImage);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *)(tex));
|
||||
//Force Background image to power of 2
|
||||
GfScaleImagePowerof2((unsigned char*)tex,w,h,GL_RGBA,screen->bgImage);
|
||||
free(tex);
|
||||
|
||||
GfParmReleaseHandle(handle);
|
||||
}
|
||||
|
||||
|
|
|
@ -36,11 +36,81 @@
|
|||
#ifdef WIN32
|
||||
#include <direct.h>
|
||||
#endif
|
||||
#include "GL/Glu.h"
|
||||
|
||||
static char buf[1024];
|
||||
|
||||
#define PNG_BYTES_TO_CHECK 4
|
||||
|
||||
|
||||
|
||||
unsigned char *
|
||||
GfScaleImage(unsigned char *pSrcImg,int srcW,int srcH,int destW,int destH,GLenum format)
|
||||
{
|
||||
unsigned char *pData = NULL;
|
||||
gluScaleImage(format, srcW,srcH,GL_BYTE,pSrcImg,destW,destH,GL_BYTE,pData);
|
||||
|
||||
return pData;
|
||||
}
|
||||
|
||||
int GetClosestPowerof2(int Size)
|
||||
{
|
||||
int sizes[8] = {2,4,16,128,256,512,1024,2048 };
|
||||
|
||||
for (int i=0;i<8;i++)
|
||||
{
|
||||
if (Size<=sizes[i])
|
||||
return sizes[i];
|
||||
}
|
||||
|
||||
//Do not allow textures larger then this for memory usage reasons
|
||||
return 2048;
|
||||
}
|
||||
|
||||
void
|
||||
GfScaleImagePowerof2(unsigned char *pSrcImg,int srcW,int srcH,GLenum format,GLuint &texId)
|
||||
{
|
||||
int destH = 128;
|
||||
int destW = 128;
|
||||
|
||||
destH = GetClosestPowerof2(srcH);
|
||||
destW = GetClosestPowerof2(srcW);
|
||||
|
||||
if ((destH!=srcH)||(destW!=srcW))
|
||||
{
|
||||
|
||||
unsigned char *texData = NULL;
|
||||
if (format == GL_RGB)
|
||||
{
|
||||
texData = new unsigned char[destW*destH*3];
|
||||
}
|
||||
else if(format == GL_RGBA)
|
||||
{
|
||||
texData = new unsigned char[destW*destH*4];
|
||||
|
||||
}
|
||||
|
||||
int r = gluScaleImage( format, srcW,srcH,GL_UNSIGNED_BYTE,(void*)pSrcImg,destW,destH,GL_UNSIGNED_BYTE,(void*)texData);
|
||||
if (r!=0)
|
||||
printf("Error trying to scale image\n");
|
||||
|
||||
glGenTextures(1, &texId);
|
||||
glBindTexture(GL_TEXTURE_2D, texId);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, destW, destH, 0, format, GL_UNSIGNED_BYTE, (GLvoid *)(texData));
|
||||
delete [] texData;
|
||||
}
|
||||
else
|
||||
{
|
||||
glGenTextures(1, &texId);
|
||||
glBindTexture(GL_TEXTURE_2D, texId);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, format, destW, destH, 0, format, GL_UNSIGNED_BYTE, (GLvoid *)(pSrcImg));
|
||||
}
|
||||
}
|
||||
|
||||
/** Load an image from disk to a buffer in RGBA mode.
|
||||
@ingroup img
|
||||
@param filename name of the image to load
|
||||
|
|
|
@ -49,6 +49,7 @@ extern int GfImgWritePng(unsigned char *img, const char *filename, int width, in
|
|||
extern void GfImgFreeTex(GLuint tex);
|
||||
extern GLuint GfImgReadTex(const char *filename);
|
||||
extern GLuint GfImgReadTex(const char *filename,int &height,int &width);
|
||||
extern void GfScaleImagePowerof2(unsigned char *pSrcImg,int srcW,int srcH,GLenum format,GLuint &texId);
|
||||
|
||||
extern void GfScrInit(int argc, char *argv[]);
|
||||
extern void GfScrShutdown(void);
|
||||
|
|
Loading…
Reference in a new issue