So in my game, which I’m writing with xcode and compiling a universal
binary of, I have the issue that the colors end up all wrong on a PPC.
The code I’m using to take in image data is just IMG_Load, which I
would expect to work just fine on a PPC (and has before). Anyways,
there is only one function where I do this. It may be a bit long:
void RenderClass::initTextureAndRectangle(GLuint& texture, Rectangle&
image_rect, char* image_path)
{
//set up a surface to use to create our texture, also set up that
rectangle
SDL_Surface* tempSur;
SDL_Surface* sur;
char full_path[1024];
sprintf(full_path, "%s%s", basepath, image_path); //basepath is
#ifdef’d and #define’d depending on the OS
tempSur = IMG_Load(full_path); //this is the line that actually
takes in data…
sur = SDL_DisplayFormatAlpha(tempSur);
SDL_FreeSurface(tempSur);
image_rect.x = 0;
image_rect.y = 0;
image_rect.w = sur->w;
image_rect.h = sur->h;
//use that texture to create out texture
GLenum texture_format;
GLint nOfColors;
// get the number of channels in the SDL surface
nOfColors = sur->format->BytesPerPixel;
if (nOfColors == 4) // contains an alpha channel
{
if (sur->format->Rmask == 0x000000ff)
texture_format = GL_RGBA;
else
texture_format = GL_BGRA;
}
else if (nOfColors == 3) // no alpha channel
{
if (sur->format->Rmask == 0x000000ff)
texture_format = GL_RGB;
else
texture_format = GL_BGR;
}
//create the open gl texture
glEnable( GL_TEXTURE_2D );
glGenTextures( 1, &texture );
// Bind the texture object
glBindTexture( GL_TEXTURE_2D, texture );
// Set the texture's stretching properties
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
// Edit the texture object's image data using the information
SDL_Surface gives us
glTexImage2D( GL_TEXTURE_2D, 0, nOfColors, sur->w, sur->h, 0,
texture_format, GL_UNSIGNED_BYTE, sur->pixels );
glDisable( GL_TEXTURE_2D );
SDL_FreeSurface(sur);
return;
}
Is that code not-endian independent? I haven’t tried, but if I compile
this on a PPC with xcode 2.5, I’m pretty sure it will work.
Thanks,
saturn