[1.2+OpenGL]-Color Problems-Windows/Linux/OS X

[1.2+OpenGL]-Color Problems-Windows/Linux/OS X…

Hi,

Trying to have one set of source code for:
Windows®
Linux
Mac OS X®
but am having troubles.

Project correctly displays PNG images using SDL_image
on both Windows® and Linux,
but on Mac OS X® the colors of the PNG images are wrong.
(source is build on an Intel® Mac)

Here is relevant sources:-----------------------------------------------------------------------------------------------

// Below is done at beginning of program…
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
R_Mask = 0xff000000;
G_Mask = 0x00ff0000;
B_Mask = 0x0000ff00;
A_Mask = 0x000000ff;
ColorIsRGBA = false;
#else
R_Mask = 0x000000ff;
G_Mask = 0x0000ff00;
B_Mask = 0x00ff0000;
A_Mask = 0xff000000;
ColorIsRGBA = true;
#endif

// Below is done when PNG images are loaded into OpenGL textures…
numberOfColors = tempSurface->format->BytesPerPixel;
if (numberOfColors == 4)
{
if (ColorIsRGBA == true) textureFormat = GL_RGBA;
else textureFormat = GL_BGRA;
}
else if (numberOfColors == 3)
{
if (ColorIsRGBA == true) textureFormat = GL_RGB;
else textureFormat = GL_BGR;
}
else
{
printf(“ERROR: The image is not truecolor\n”);
imageToTextureOK = false;
}

// . . .

glTexImage2D( GL_TEXTURE_2D, 0, numberOfColors, tempSurface->w,
tempSurface->h, 0,
textureFormat, GL_UNSIGNED_BYTE,
tempSurface->pixels );

Above works OK on Windows® and Linux,
but on my Intel® Mac with OS X® the color of the PNG images is wrong?

Again, I want one set of source for all three OS’s.
Any help would be appreciated!
Thanks!

Jesse

[1.2+OpenGL]-Color Problems-Windows/Linux/OS X…

Hi,

Trying to have one set of source code for:
Windows®
Linux
Mac OS X®
but am having troubles.

Project correctly displays PNG images using SDL_image
on both Windows® and Linux,
but on Mac OS X® the colors of the PNG images are wrong.
(source is build on an Intel® Mac)

Here is relevant sources:

// Below is done at beginning of program…
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
? ?R_Mask ?= 0xff000000;
? ?G_Mask ?= 0x00ff0000;
? ?B_Mask ?= 0x0000ff00;
? ?A_Mask ?= 0x000000ff;
? ?ColorIsRGBA = false;
#else
? ?R_Mask ?= 0x000000ff;
? ?G_Mask ?= 0x0000ff00;
? ?B_Mask ?= 0x00ff0000;
? ?A_Mask ?= 0xff000000;
? ?ColorIsRGBA = true;
#endif

This part looks fine, though I don’t think you need the ColorIsRGBA variable.


// Below is done when PNG images are loaded into OpenGL textures…
numberOfColors = tempSurface->format->BytesPerPixel;
if (numberOfColors == 4)
? ?{
? ? ? ?if (ColorIsRGBA == true) textureFormat = GL_RGBA;
? ? ? ?else ?textureFormat = GL_BGRA;
? ?}
? ?else if (numberOfColors == 3)
? ?{
? ? ? ?if (ColorIsRGBA == true) ?textureFormat = GL_RGB;
? ? ? ?else ?textureFormat = GL_BGR;
? ?}
? ?else
? ?{
? ? ? ?printf(“ERROR: The image is not truecolor\n”);
? ? ? ?imageToTextureOK = false;
? ?}

I think this whole section can go away (or maybe just one case for
GL_RGBA vs GL_RGB).

// . . .

glTexImage2D( GL_TEXTURE_2D, 0, numberOfColors, tempSurface->w,
tempSurface->h, 0,
? ? ? ? ? ? ? ? ? ? ? ? textureFormat, GL_UNSIGNED_BYTE, tempSurface->pixels
);

In my game I always pass in GL_RGBA here (I guess I assume all my
images are 32-bit? I don’t remember).

Here’s the condensed version of what I do:

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
#define RMASK 0xff000000
#define GMASK 0x00ff0000
#define BMASK 0x0000ff00
#define AMASK 0x000000ff
#else
#define RMASK 0x000000ff
#define GMASK 0x0000ff00
#define BMASK 0x00ff0000
#define AMASK 0xff000000
#endif
#define MASKS RMASK, GMASK, BMASK, AMASK

entry->surface = SDL_CreateRGBSurface(0, entry->width, entry->height,
32, MASKS);

glTexImage2D(GL_TEXTURE_2D, 0, 4, entry->width, entry->height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, entry->surface->pixels);

So I think only SDL cares about the endianness in SDL_CreateRGBSurface
(the man page claims it treats a pixel as an integer, which is why
that would matter). The data you pass into glTexImage2D is the same
format regardless of the machine, so you don’t have to switch between
GL_RGBA and GL_BRGA.

You’ll probably have to read carefully through the man pages or source
if you want a more accurate explanation of why it matters in one and
not the other, but I think you’ll be fine if you just remove the
ColorIsRGBA flag :slight_smile:

-MikeOn Tue, Sep 14, 2010 at 12:00 PM, Jesse Palser wrote:

Something interesting from
http://w3.impa.br/~italo/out/apple_stuff/OpenGLProg_MacOSX.pdf

The combination GL_RGBA and GL_UNSIGNED_BYTE needs to be swizzled by
many cards when the data is
loaded, so it’s not recommended.

Your call

glTexImage2D( GL_TEXTURE_2D, 0, numberOfColors, tempSurface->w,
tempSurface->h, 0,
textureFormat, GL_UNSIGNED_BYTE, tempSurface->pixels );

http://www.opengl.org/registry/specs/ARB/texture_swizzle.txtOn Tue, Sep 14, 2010 at 12:23 PM, Mike Shal wrote:

On Tue, Sep 14, 2010 at 12:00 PM, Jesse Palser wrote:

[1.2+OpenGL]-Color Problems-Windows/Linux/OS X…

Hi,

Trying to have one set of source code for:
Windows®
Linux
Mac OS X®
but am having troubles.

Project correctly displays PNG images using SDL_image
on both Windows® and Linux,
but on Mac OS X® the colors of the PNG images are wrong.
(source is build on an Intel® Mac)

Here is relevant sources:

// Below is done at beginning of program…
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
? ?R_Mask ?= 0xff000000;
? ?G_Mask ?= 0x00ff0000;
? ?B_Mask ?= 0x0000ff00;
? ?A_Mask ?= 0x000000ff;
? ?ColorIsRGBA = false;
#else
? ?R_Mask ?= 0x000000ff;
? ?G_Mask ?= 0x0000ff00;
? ?B_Mask ?= 0x00ff0000;
? ?A_Mask ?= 0xff000000;
? ?ColorIsRGBA = true;
#endif

This part looks fine, though I don’t think you need the ColorIsRGBA variable.


// Below is done when PNG images are loaded into OpenGL textures…
numberOfColors = tempSurface->format->BytesPerPixel;
if (numberOfColors == 4)
? ?{
? ? ? ?if (ColorIsRGBA == true) textureFormat = GL_RGBA;
? ? ? ?else ?textureFormat = GL_BGRA;
? ?}
? ?else if (numberOfColors == 3)
? ?{
? ? ? ?if (ColorIsRGBA == true) ?textureFormat = GL_RGB;
? ? ? ?else ?textureFormat = GL_BGR;
? ?}
? ?else
? ?{
? ? ? ?printf(“ERROR: The image is not truecolor\n”);
? ? ? ?imageToTextureOK = false;
? ?}

I think this whole section can go away (or maybe just one case for
GL_RGBA vs GL_RGB).

// . . .

glTexImage2D( GL_TEXTURE_2D, 0, numberOfColors, tempSurface->w,
tempSurface->h, 0,
? ? ? ? ? ? ? ? ? ? ? ? textureFormat, GL_UNSIGNED_BYTE, tempSurface->pixels
);

In my game I always pass in GL_RGBA here (I guess I assume all my
images are 32-bit? I don’t remember).

Here’s the condensed version of what I do:

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
#define RMASK 0xff000000
#define GMASK 0x00ff0000
#define BMASK 0x0000ff00
#define AMASK 0x000000ff
#else
#define RMASK 0x000000ff
#define GMASK 0x0000ff00
#define BMASK 0x00ff0000
#define AMASK 0xff000000
#endif
#define MASKS RMASK, GMASK, BMASK, AMASK

entry->surface = SDL_CreateRGBSurface(0, entry->width, entry->height,
32, MASKS);

glTexImage2D(GL_TEXTURE_2D, 0, 4, entry->width, entry->height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, entry->surface->pixels);

So I think only SDL cares about the endianness in SDL_CreateRGBSurface
(the man page claims it treats a pixel as an integer, which is why
that would matter). The data you pass into glTexImage2D is the same
format regardless of the machine, so you don’t have to switch between
GL_RGBA and GL_BRGA.

You’ll probably have to read carefully through the man pages or source
if you want a more accurate explanation of why it matters in one and
not the other, but I think you’ll be fine if you just remove the
ColorIsRGBA flag :slight_smile:

-Mike


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Good to know - thanks for the correction! Maybe Jesse can use that to
come up with a more efficient solution once he gets it working
properly on all platforms.

-MikeOn Tue, Sep 14, 2010 at 1:03 PM, Jeremiah wrote:

On Tue, Sep 14, 2010 at 12:23 PM, Mike Shal <@Mike_Shal> wrote:

On Tue, Sep 14, 2010 at 12:00 PM, Jesse Palser wrote:

[1.2+OpenGL]-Color Problems-Windows/Linux/OS X…

Hi,

Trying to have one set of source code for:
Windows®
Linux
Mac OS X®
but am having troubles.

Project correctly displays PNG images using SDL_image
on both Windows® and Linux,
but on Mac OS X® the colors of the PNG images are wrong.
(source is build on an Intel® Mac)

Here is relevant sources:

// Below is done at beginning of program…
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
? ?R_Mask ?= 0xff000000;
? ?G_Mask ?= 0x00ff0000;
? ?B_Mask ?= 0x0000ff00;
? ?A_Mask ?= 0x000000ff;
? ?ColorIsRGBA = false;
#else
? ?R_Mask ?= 0x000000ff;
? ?G_Mask ?= 0x0000ff00;
? ?B_Mask ?= 0x00ff0000;
? ?A_Mask ?= 0xff000000;
? ?ColorIsRGBA = true;
#endif

This part looks fine, though I don’t think you need the ColorIsRGBA variable.


// Below is done when PNG images are loaded into OpenGL textures…
numberOfColors = tempSurface->format->BytesPerPixel;
if (numberOfColors == 4)
? ?{
? ? ? ?if (ColorIsRGBA == true) textureFormat = GL_RGBA;
? ? ? ?else ?textureFormat = GL_BGRA;
? ?}
? ?else if (numberOfColors == 3)
? ?{
? ? ? ?if (ColorIsRGBA == true) ?textureFormat = GL_RGB;
? ? ? ?else ?textureFormat = GL_BGR;
? ?}
? ?else
? ?{
? ? ? ?printf(“ERROR: The image is not truecolor\n”);
? ? ? ?imageToTextureOK = false;
? ?}

I think this whole section can go away (or maybe just one case for
GL_RGBA vs GL_RGB).

// . . .

glTexImage2D( GL_TEXTURE_2D, 0, numberOfColors, tempSurface->w,
tempSurface->h, 0,
? ? ? ? ? ? ? ? ? ? ? ? textureFormat, GL_UNSIGNED_BYTE, tempSurface->pixels
);

In my game I always pass in GL_RGBA here (I guess I assume all my
images are 32-bit? I don’t remember).

Here’s the condensed version of what I do:

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
#define RMASK 0xff000000
#define GMASK 0x00ff0000
#define BMASK 0x0000ff00
#define AMASK 0x000000ff
#else
#define RMASK 0x000000ff
#define GMASK 0x0000ff00
#define BMASK 0x00ff0000
#define AMASK 0xff000000
#endif
#define MASKS RMASK, GMASK, BMASK, AMASK

entry->surface = SDL_CreateRGBSurface(0, entry->width, entry->height,
32, MASKS);

glTexImage2D(GL_TEXTURE_2D, 0, 4, entry->width, entry->height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, entry->surface->pixels);

So I think only SDL cares about the endianness in SDL_CreateRGBSurface
(the man page claims it treats a pixel as an integer, which is why
that would matter). The data you pass into glTexImage2D is the same
format regardless of the machine, so you don’t have to switch between
GL_RGBA and GL_BRGA.

You’ll probably have to read carefully through the man pages or source
if you want a more accurate explanation of why it matters in one and
not the other, but I think you’ll be fine if you just remove the
ColorIsRGBA flag :slight_smile:

-Mike


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Something interesting from
http://w3.impa.br/~italo/out/apple_stuff/OpenGLProg_MacOSX.pdf

The combination GL_RGBA and GL_UNSIGNED_BYTE needs to be swizzled by
many cards when the data is
loaded, so it’s not recommended.

Your call

glTexImage2D( GL_TEXTURE_2D, 0, numberOfColors, tempSurface->w,
tempSurface->h, 0,
? ? ? ? ? ? ? ? ? ? ? ?textureFormat, GL_UNSIGNED_BYTE, tempSurface->pixels );

http://www.opengl.org/registry/specs/ARB/texture_swizzle.txt

Hi,

OK, I’ve got the colors looking the same on Windows®, Linux, & Mac OS X® now.

Problem now is that the transparent alpha pixels are not displayed as transparent on the screen.
The PNG’s were created in GIMP under Ubuntu 10.04 32bit Linix
(disregard the buttons - have not changed that source yet)

Here is a screenshot:
[Image: http://16bitsoft.com/images/LettersFall2/LF2-3OS-Trans01.png ]

Here is a link to download the PNG image (with alpha transparency set by GIMP):
http://16bitsoft.com/images/LettersFall2/LettersFall_Text_Logo.png

HOPE SOMEONE CAN HELP!

Here is the relevant source code:

Code:
//------------------------------------------------------------------------------------------------------------------------
if (filePath[0] != ‘~’)
{
tempSurface = NULL;

if ( (tempSurface = IMG_Load(filePath)) )
{
    if ( (tempSurface->w & (tempSurface->w - 1)) != 0 )
    {
        printf("ERROR: Image width is not a power of 2\n");
        loadedImageIsOK = false;
    }

    if ( (tempSurface->h & (tempSurface->h - 1)) != 0 )
    {
        printf("ERROR: Image height is not a power of 2\n");
        loadedImageIsOK = false;
    }

    if (loadedImageIsOK == true)
    {
        tempSurfaceAlpha = SDL_DisplayFormat(tempSurface);
        SDL_SetAlpha(tempSurfaceAlpha, 0, SDL_ALPHA_TRANSPARENT);

        tempSurfaceFixed = SDL_CreateRGBSurface(SDL_SWSURFACE, tempSurface->w, tempSurface->h, 32,
        R_Mask, G_Mask, B_Mask, A_Mask);

        SDL_BlitSurface(tempSurfaceAlpha, NULL, tempSurfaceFixed, NULL);

        numberOfColors = tempSurfaceFixed->format->BytesPerPixel;
        if (numberOfColors == 4)
        {
            textureFormat = GL_RGBA;
        }
        else if (numberOfColors == 3)
        {
            textureFormat = GL_RGB;
        }
        else
        {
            printf("ERROR: The image is not truecolor\n");
            imageToTextureOK = false;
        }

        Sprites[index].OGL_Texture = (GLuint)NULL;
        if (imageToTextureOK == true)
        {
            glGenTextures( 1, &Sprites[index].OGL_Texture );

            glBindTexture( GL_TEXTURE_2D, Sprites[index].OGL_Texture );

            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);//GL_LINEAR);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);//GL_LINEAR);

            glTexImage2D( GL_TEXTURE_2D, 0, numberOfColors, tempSurface->w, tempSurface->h, 0,
            textureFormat, GL_UNSIGNED_BYTE, tempSurfaceFixed->pixels );

            if ( tempSurface )
            {
                SDL_FreeSurface( tempSurface );
                SDL_FreeSurface(tempSurfaceFixed);
                SDL_FreeSurface(tempSurfaceAlpha);
            }
        }
    }
}
else
{
    printf("ERROR: SDL could not load image %s\n", SDL_GetError());
    loadedImageIsOK = false;
    imageToTextureOK = false;
}

if (loadedImageIsOK == false || imageToTextureOK == false)  return false;//index = NumberOfSprites+1;

Sprites[index].ScreenX = 320;
Sprites[index].ScreenY = 240;
Sprites[index].ScaleX = 1.0f;
Sprites[index].ScaleY = 1.0f;
Sprites[index].RotationDegree = 0.0f;
Sprites[index].Transparency = 1.0f;
Sprites[index].redHue = 1.0f;
Sprites[index].greenHue = 1.0f;
Sprites[index].blueHue = 1.0f;
Sprites[index].Smooth = true;
Sprites[index].FlipX = false;
Sprites[index].Width = tempSurface->w;
Sprites[index].Height = tempSurface->h;
Sprites[index].CenterX = Sprites[index].Width / 2;
Sprites[index].CenterY = Sprites[index].Height / 2;
Sprites[index].AnimationTimer = -1;

}
//------------------------------------------------------------------------------------------------------------------------------------------------
JeZ+Lee
JessePalser <AT> Gmail <DOT> com
16BitSoft®
Video Game Design Studio
www.16BitSoft.com

Where are you getting you R/G/B_MASK variables?On Tue, Sep 14, 2010 at 3:37 PM, JeZ-l-Lee wrote:

Hi,

OK, I’ve got the colors looking the same on Windows®, Linux, & Mac OS
X® now.

Problem now is that the transparent alpha pixels are not displayed as
transparent on the screen.
The PNG’s were created in GIMP under Ubuntu 10.04 32bit Linix
(disregard the buttons - have not changed that source yet)

Here is a screenshot:

Here is a link to download the PNG image (with alpha transparency set by
GIMP):
http://16bitsoft.com/images/LettersFall2/LettersFall_Text_Logo.png

HOPE SOMEONE CAN HELP!

Here is the relevant source code:

Code:

//------------------------------------------------------------------------------------------------------------------------
if (filePath[0] != ‘~’)
{
tempSurface = NULL;

if ( (tempSurface = IMG_Load(filePath)) )
{
    if ( (tempSurface->w & (tempSurface->w - 1)) != 0 )
    {
        printf("ERROR: Image width is not a power of 2\n");
        loadedImageIsOK = false;
    }

    if ( (tempSurface->h & (tempSurface->h - 1)) != 0 )
    {
        printf("ERROR: Image height is not a power of 2\n");
        loadedImageIsOK = false;
    }

    if (loadedImageIsOK == true)
    {
        tempSurfaceAlpha = SDL_DisplayFormat(tempSurface);
        SDL_SetAlpha(tempSurfaceAlpha, 0, SDL_ALPHA_TRANSPARENT);

        tempSurfaceFixed = SDL_CreateRGBSurface(SDL_SWSURFACE,

tempSurface->w, tempSurface->h, 32,
R_Mask, G_Mask, B_Mask, A_Mask);

        SDL_BlitSurface(tempSurfaceAlpha, NULL, tempSurfaceFixed,

NULL);

        numberOfColors = tempSurfaceFixed->format->BytesPerPixel;
        if (numberOfColors == 4)
        {
            textureFormat = GL_RGBA;
        }
        else if (numberOfColors == 3)
        {
            textureFormat = GL_RGB;
        }
        else
        {
            printf("ERROR: The image is not truecolor\n");
            imageToTextureOK = false;
        }

        Sprites[index].OGL_Texture = (GLuint)NULL;
        if (imageToTextureOK == true)
        {
            glGenTextures( 1, &Sprites[index].OGL_Texture );

            glBindTexture( GL_TEXTURE_2D, Sprites[index].OGL_Texture );

            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,

GL_NEAREST);//GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
GL_NEAREST);//GL_LINEAR);

            glTexImage2D( GL_TEXTURE_2D, 0, numberOfColors,

tempSurface->w, tempSurface->h, 0,
textureFormat, GL_UNSIGNED_BYTE, tempSurfaceFixed->pixels
);

            if ( tempSurface )
            {
                SDL_FreeSurface( tempSurface );
                SDL_FreeSurface(tempSurfaceFixed);
                SDL_FreeSurface(tempSurfaceAlpha);
            }
        }
    }
}
else
{
    printf("ERROR: SDL could not load image %s\n", SDL_GetError());
    loadedImageIsOK = false;
    imageToTextureOK = false;
}

if (loadedImageIsOK == false || imageToTextureOK == false)  return

false;//index = NumberOfSprites+1;

Sprites[index].ScreenX = 320;
Sprites[index].ScreenY = 240;
Sprites[index].ScaleX = 1.0f;
Sprites[index].ScaleY = 1.0f;
Sprites[index].RotationDegree = 0.0f;
Sprites[index].Transparency = 1.0f;
Sprites[index].redHue = 1.0f;
Sprites[index].greenHue = 1.0f;
Sprites[index].blueHue = 1.0f;
Sprites[index].Smooth = true;
Sprites[index].FlipX = false;
Sprites[index].Width = tempSurface->w;
Sprites[index].Height = tempSurface->h;
Sprites[index].CenterX = Sprites[index].Width / 2;
Sprites[index].CenterY = Sprites[index].Height / 2;
Sprites[index].AnimationTimer = -1;

}

//------------------------------------------------------------------------------------------------------------------------


JeZ+Lee
JessePalser Gmail com
16BitSoft®
Video Game Design Studio
www.16BitSoft.com


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hi,

At start of program, the following is done:

//----------------------------------------------------------------------------
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
R_Mask = 0xff000000;
G_Mask = 0x00ff0000;
B_Mask = 0x0000ff00;
A_Mask = 0x000000ff;
#else
R_Mask = 0x000000ff;
G_Mask = 0x0000ff00;
B_Mask = 0x00ff0000;
A_Mask = 0xff000000;
#endif
//----------------------------------------------------------------------------

JesseOn 09/14/2010 03:40 PM, Alex Barry wrote:

Where are you getting you R/G/B_MASK variables?

On Tue, Sep 14, 2010 at 3:37 PM, JeZ-l-Lee <SLNTHERO at aol.com <mailto:SLNTHERO at aol.com>> wrote:

Hi,

OK, I've got the colors looking the same on Windows(R), Linux, &
Mac OS X(R) now.

Problem now is that the transparent alpha pixels are not displayed
as transparent on the screen.
The PNG's were created in GIMP under Ubuntu 10.04 32bit Linix
(disregard the buttons - have not changed that source yet)

Here is a screenshot:


Here is a link to download the PNG image (with alpha transparency
set by GIMP):
http://16bitsoft.com/images/LettersFall2/LettersFall_Text_Logo.png

HOPE SOMEONE CAN HELP!

Here is the relevant source code:


	Code: 	


	//------------------------------------------------------------------------------------------------------------------------
if (filePath[0] != '~')
{
    tempSurface = NULL;

    if ( (tempSurface = IMG_Load(filePath)) )
    {
        if ( (tempSurface->w & (tempSurface->w - 1)) != 0 )
        {
            printf("ERROR: Image width is not a power of 2\n");
            loadedImageIsOK = false;
        }

        if ( (tempSurface->h & (tempSurface->h - 1)) != 0 )
        {
            printf("ERROR: Image height is not a power of 2\n");
            loadedImageIsOK = false;
        }

        if (loadedImageIsOK == true)
        {
            tempSurfaceAlpha = SDL_DisplayFormat(tempSurface);
            SDL_SetAlpha(tempSurfaceAlpha, 0, SDL_ALPHA_TRANSPARENT);

            tempSurfaceFixed = SDL_CreateRGBSurface(SDL_SWSURFACE,
tempSurface->w, tempSurface->h, 32,
            R_Mask, G_Mask, B_Mask, A_Mask);

            SDL_BlitSurface(tempSurfaceAlpha, NULL,
tempSurfaceFixed, NULL);

            numberOfColors = tempSurfaceFixed->format->BytesPerPixel;
            if (numberOfColors == 4)
            {
                textureFormat = GL_RGBA;
            }
            else if (numberOfColors == 3)
            {
                textureFormat = GL_RGB;
            }
            else
            {
                printf("ERROR: The image is not truecolor\n");
                imageToTextureOK = false;
            }

            Sprites[index].OGL_Texture = (GLuint)NULL;
            if (imageToTextureOK == true)
            {
                glGenTextures( 1, &Sprites[index].OGL_Texture );

                glBindTexture( GL_TEXTURE_2D,
Sprites[index].OGL_Texture );

                glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MIN_FILTER, GL_NEAREST);//GL_LINEAR);
                glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MAG_FILTER, GL_NEAREST);//GL_LINEAR);

                glTexImage2D( GL_TEXTURE_2D, 0, numberOfColors,
tempSurface->w, tempSurface->h, 0,
                textureFormat, GL_UNSIGNED_BYTE,
tempSurfaceFixed->pixels );

                if ( tempSurface )
                {
                    SDL_FreeSurface( tempSurface );
                    SDL_FreeSurface(tempSurfaceFixed);
                    SDL_FreeSurface(tempSurfaceAlpha);
                }
            }
        }
    }
    else
    {
        printf("ERROR: SDL could not load image %s\n",
SDL_GetError());
        loadedImageIsOK = false;
        imageToTextureOK = false;
    }

    if (loadedImageIsOK == false || imageToTextureOK == false) 
return false;//index = NumberOfSprites+1;

    Sprites[index].ScreenX = 320;
    Sprites[index].ScreenY = 240;
    Sprites[index].ScaleX = 1.0f;
    Sprites[index].ScaleY = 1.0f;
    Sprites[index].RotationDegree = 0.0f;
    Sprites[index].Transparency = 1.0f;
    Sprites[index].redHue = 1.0f;
    Sprites[index].greenHue = 1.0f;
    Sprites[index].blueHue = 1.0f;
    Sprites[index].Smooth = true;
    Sprites[index].FlipX = false;
    Sprites[index].Width = tempSurface->w;
    Sprites[index].Height = tempSurface->h;
    Sprites[index].CenterX = Sprites[index].Width / 2;
    Sprites[index].CenterY = Sprites[index].Height / 2;
    Sprites[index].AnimationTimer = -1;
}
//------------------------------------------------------------------------------------------------------------------------
	



------------------------------------------------------------------------

JeZ+Lee
JessePalser <AT> Gmail <DOT> com
16BitSoft(R)
Video Game Design Studio
www.16BitSoft.com <http://www.16BitSoft.com>

_______________________________________________
SDL mailing list
SDL at lists.libsdl.org <mailto:SDL at lists.libsdl.org>
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Are you using glEnable(GL_BLEND)?

Jonny DOn Tue, Sep 14, 2010 at 3:47 PM, Jesse Palser wrote:

Hi,

At start of program, the following is done:

//----------------------------------------------------------------------------

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
R_Mask = 0xff000000;
G_Mask = 0x00ff0000;
B_Mask = 0x0000ff00;
A_Mask = 0x000000ff;
#else
R_Mask = 0x000000ff;
G_Mask = 0x0000ff00;
B_Mask = 0x00ff0000;
A_Mask = 0xff000000;
#endif

//----------------------------------------------------------------------------

Jesse

On 09/14/2010 03:40 PM, Alex Barry wrote:

Where are you getting you R/G/B_MASK variables?

On Tue, Sep 14, 2010 at 3:37 PM, JeZ-l-Lee wrote:

Hi,

OK, I’ve got the colors looking the same on Windows®, Linux, & Mac OS
X® now.

Problem now is that the transparent alpha pixels are not displayed as
transparent on the screen.
The PNG’s were created in GIMP under Ubuntu 10.04 32bit Linix
(disregard the buttons - have not changed that source yet)

Here is a screenshot:

Here is a link to download the PNG image (with alpha transparency set by
GIMP):
http://16bitsoft.com/images/LettersFall2/LettersFall_Text_Logo.png

HOPE SOMEONE CAN HELP!

Here is the relevant source code:

Code:

//------------------------------------------------------------------------------------------------------------------------
if (filePath[0] != ‘~’)
{
tempSurface = NULL;

if ( (tempSurface = IMG_Load(filePath)) )
{
    if ( (tempSurface->w & (tempSurface->w - 1)) != 0 )
    {
        printf("ERROR: Image width is not a power of 2\n");
        loadedImageIsOK = false;
    }

    if ( (tempSurface->h & (tempSurface->h - 1)) != 0 )
    {
        printf("ERROR: Image height is not a power of 2\n");
        loadedImageIsOK = false;
    }

    if (loadedImageIsOK == true)
    {
        tempSurfaceAlpha = SDL_DisplayFormat(tempSurface);
        SDL_SetAlpha(tempSurfaceAlpha, 0, SDL_ALPHA_TRANSPARENT);

        tempSurfaceFixed = SDL_CreateRGBSurface(SDL_SWSURFACE,

tempSurface->w, tempSurface->h, 32,
R_Mask, G_Mask, B_Mask, A_Mask);

        SDL_BlitSurface(tempSurfaceAlpha, NULL, tempSurfaceFixed,

NULL);

        numberOfColors = tempSurfaceFixed->format->BytesPerPixel;
        if (numberOfColors == 4)
        {
            textureFormat = GL_RGBA;
        }
        else if (numberOfColors == 3)
        {
            textureFormat = GL_RGB;
        }
        else
        {
            printf("ERROR: The image is not truecolor\n");
            imageToTextureOK = false;
        }

        Sprites[index].OGL_Texture = (GLuint)NULL;
        if (imageToTextureOK == true)
        {
            glGenTextures( 1, &Sprites[index].OGL_Texture );

            glBindTexture( GL_TEXTURE_2D, Sprites[index].OGL_Texture

);

            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,

GL_NEAREST);//GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
GL_NEAREST);//GL_LINEAR);

            glTexImage2D( GL_TEXTURE_2D, 0, numberOfColors,

tempSurface->w, tempSurface->h, 0,
textureFormat, GL_UNSIGNED_BYTE, tempSurfaceFixed->pixels
);

            if ( tempSurface )
            {
                SDL_FreeSurface( tempSurface );
                SDL_FreeSurface(tempSurfaceFixed);
                SDL_FreeSurface(tempSurfaceAlpha);
            }
        }
    }
}
else
{
    printf("ERROR: SDL could not load image %s\n", SDL_GetError());
    loadedImageIsOK = false;
    imageToTextureOK = false;
}

if (loadedImageIsOK == false || imageToTextureOK == false)  return

false;//index = NumberOfSprites+1;

Sprites[index].ScreenX = 320;
Sprites[index].ScreenY = 240;
Sprites[index].ScaleX = 1.0f;
Sprites[index].ScaleY = 1.0f;
Sprites[index].RotationDegree = 0.0f;
Sprites[index].Transparency = 1.0f;
Sprites[index].redHue = 1.0f;
Sprites[index].greenHue = 1.0f;
Sprites[index].blueHue = 1.0f;
Sprites[index].Smooth = true;
Sprites[index].FlipX = false;
Sprites[index].Width = tempSurface->w;
Sprites[index].Height = tempSurface->h;
Sprites[index].CenterX = Sprites[index].Width / 2;
Sprites[index].CenterY = Sprites[index].Height / 2;
Sprites[index].AnimationTimer = -1;

}

//------------------------------------------------------------------------------------------------------------------------


JeZ+Lee
JessePalser Gmail com
16BitSoft®
Video Game Design Studio
www.16BitSoft.com


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing listSDL at lists.libsdl.orghttp://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hi,

Yes, glEnable(GL_BLEND) is on.

The problem is in these lines of code:
(the transparent alpha of the PNG’s are not working)
//-----------------------------------------------------------------------------------
tempSurfaceAlpha = SDL_DisplayFormat(tempSurface);
SDL_SetAlpha(tempSurfaceAlpha, 0, SDL_ALPHA_TRANSPARENT);

tempSurfaceFixed = SDL_CreateRGBSurface(SDL_SWSURFACE, tempSurface->w,
tempSurface->h, 32,
R_Mask, G_Mask, B_Mask, A_Mask);

SDL_BlitSurface(tempSurfaceAlpha, NULL, tempSurfaceFixed, NULL);
//-----------------------------------------------------------------------------------

JesseOn 09/14/2010 04:32 PM, Jonathan Dearborn wrote:

Are you using glEnable(GL_BLEND)?

Jonny D

On Tue, Sep 14, 2010 at 3:47 PM, Jesse Palser <SLNTHERO at aol.com <mailto:SLNTHERO at aol.com>> wrote:

Hi,

At start of program, the following is done:

//----------------------------------------------------------------------------


#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    R_Mask  = 0xff000000;
    G_Mask  = 0x00ff0000;
    B_Mask  = 0x0000ff00;
    A_Mask  = 0x000000ff;
#else
    R_Mask  = 0x000000ff;
    G_Mask  = 0x0000ff00;
    B_Mask  = 0x00ff0000;
    A_Mask  = 0xff000000;
#endif
//----------------------------------------------------------------------------

Jesse





On 09/14/2010 03:40 PM, Alex Barry wrote:
Where are you getting you R/G/B_MASK variables?

On Tue, Sep 14, 2010 at 3:37 PM, JeZ-l-Lee <SLNTHERO at aol.com <mailto:SLNTHERO at aol.com>> wrote:

    Hi,

    OK, I've got the colors looking the same on Windows(R),
    Linux, & Mac OS X(R) now.

    Problem now is that the transparent alpha pixels are not
    displayed as transparent on the screen.
    The PNG's were created in GIMP under Ubuntu 10.04 32bit Linix
    (disregard the buttons - have not changed that source yet)

    Here is a screenshot:


    Here is a link to download the PNG image (with alpha
    transparency set by GIMP):
    http://16bitsoft.com/images/LettersFall2/LettersFall_Text_Logo.png

    HOPE SOMEONE CAN HELP!

    Here is the relevant source code:


    	Code: 	


    	//------------------------------------------------------------------------------------------------------------------------
    if (filePath[0] != '~')
    {
        tempSurface = NULL;

        if ( (tempSurface = IMG_Load(filePath)) )
        {
            if ( (tempSurface->w & (tempSurface->w - 1)) != 0 )
            {
                printf("ERROR: Image width is not a power of 2\n");
                loadedImageIsOK = false;
            }

            if ( (tempSurface->h & (tempSurface->h - 1)) != 0 )
            {
                printf("ERROR: Image height is not a power of 2\n");
                loadedImageIsOK = false;
            }

            if (loadedImageIsOK == true)
            {
                tempSurfaceAlpha = SDL_DisplayFormat(tempSurface);
                SDL_SetAlpha(tempSurfaceAlpha, 0,
    SDL_ALPHA_TRANSPARENT);

                tempSurfaceFixed =
    SDL_CreateRGBSurface(SDL_SWSURFACE, tempSurface->w,
    tempSurface->h, 32,
                R_Mask, G_Mask, B_Mask, A_Mask);

                SDL_BlitSurface(tempSurfaceAlpha, NULL,
    tempSurfaceFixed, NULL);

                numberOfColors =
    tempSurfaceFixed->format->BytesPerPixel;
                if (numberOfColors == 4)
                {
                    textureFormat = GL_RGBA;
                }
                else if (numberOfColors == 3)
                {
                    textureFormat = GL_RGB;
                }
                else
                {
                    printf("ERROR: The image is not truecolor\n");
                    imageToTextureOK = false;
                }

                Sprites[index].OGL_Texture = (GLuint)NULL;
                if (imageToTextureOK == true)
                {
                    glGenTextures( 1, &Sprites[index].OGL_Texture );

                    glBindTexture( GL_TEXTURE_2D,
    Sprites[index].OGL_Texture );

                    glTexParameteri(GL_TEXTURE_2D,
    GL_TEXTURE_MIN_FILTER, GL_NEAREST);//GL_LINEAR);
                    glTexParameteri(GL_TEXTURE_2D,
    GL_TEXTURE_MAG_FILTER, GL_NEAREST);//GL_LINEAR);

                    glTexImage2D( GL_TEXTURE_2D, 0,
    numberOfColors, tempSurface->w, tempSurface->h, 0,
                    textureFormat, GL_UNSIGNED_BYTE,
    tempSurfaceFixed->pixels );

                    if ( tempSurface )
                    {
                        SDL_FreeSurface( tempSurface );
                        SDL_FreeSurface(tempSurfaceFixed);
                        SDL_FreeSurface(tempSurfaceAlpha);
                    }
                }
            }
        }
        else
        {
            printf("ERROR: SDL could not load image %s\n",
    SDL_GetError());
            loadedImageIsOK = false;
            imageToTextureOK = false;
        }

        if (loadedImageIsOK == false || imageToTextureOK ==
    false)  return false;//index = NumberOfSprites+1;

        Sprites[index].ScreenX = 320;
        Sprites[index].ScreenY = 240;
        Sprites[index].ScaleX = 1.0f;
        Sprites[index].ScaleY = 1.0f;
        Sprites[index].RotationDegree = 0.0f;
        Sprites[index].Transparency = 1.0f;
        Sprites[index].redHue = 1.0f;
        Sprites[index].greenHue = 1.0f;
        Sprites[index].blueHue = 1.0f;
        Sprites[index].Smooth = true;
        Sprites[index].FlipX = false;
        Sprites[index].Width = tempSurface->w;
        Sprites[index].Height = tempSurface->h;
        Sprites[index].CenterX = Sprites[index].Width / 2;
        Sprites[index].CenterY = Sprites[index].Height / 2;
        Sprites[index].AnimationTimer = -1;
    }
    //------------------------------------------------------------------------------------------------------------------------
    	



    ------------------------------------------------------------------------

    JeZ+Lee
    JessePalser <AT> Gmail <DOT> com
    16BitSoft(R)
    Video Game Design Studio
    www.16BitSoft.com <http://www.16BitSoft.com>

    _______________________________________________
    SDL mailing list
    SDL at lists.libsdl.org <mailto:SDL at lists.libsdl.org>
    http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org



_______________________________________________
SDL mailing list
SDL at lists.libsdl.org  <mailto:SDL at lists.libsdl.org>
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
_______________________________________________
SDL mailing list
SDL at lists.libsdl.org <mailto:SDL at lists.libsdl.org>
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

How about SDL_DisplayFormatAlpha?

Jonny DOn Tue, Sep 14, 2010 at 4:57 PM, Jesse Palser wrote:

Hi,

Yes, glEnable(GL_BLEND) is on.

The problem is in these lines of code:
(the transparent alpha of the PNG’s are not working)

//-----------------------------------------------------------------------------------

tempSurfaceAlpha = SDL_DisplayFormat(tempSurface);
SDL_SetAlpha(tempSurfaceAlpha, 0, SDL_ALPHA_TRANSPARENT);

tempSurfaceFixed = SDL_CreateRGBSurface(SDL_SWSURFACE, tempSurface->w,
tempSurface->h, 32,
R_Mask, G_Mask, B_Mask, A_Mask);

SDL_BlitSurface(tempSurfaceAlpha, NULL, tempSurfaceFixed, NULL);

//-----------------------------------------------------------------------------------

Jesse

On 09/14/2010 04:32 PM, Jonathan Dearborn wrote:

Are you using glEnable(GL_BLEND)?

Jonny D

On Tue, Sep 14, 2010 at 3:47 PM, Jesse Palser wrote:

Hi,

At start of program, the following is done:

//----------------------------------------------------------------------------

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
R_Mask = 0xff000000;
G_Mask = 0x00ff0000;
B_Mask = 0x0000ff00;
A_Mask = 0x000000ff;
#else
R_Mask = 0x000000ff;
G_Mask = 0x0000ff00;
B_Mask = 0x00ff0000;
A_Mask = 0xff000000;
#endif

//----------------------------------------------------------------------------

Jesse

On 09/14/2010 03:40 PM, Alex Barry wrote:

Where are you getting you R/G/B_MASK variables?

On Tue, Sep 14, 2010 at 3:37 PM, JeZ-l-Lee wrote:

Hi,

OK, I’ve got the colors looking the same on Windows®, Linux, & Mac OS
X® now.

Problem now is that the transparent alpha pixels are not displayed as
transparent on the screen.
The PNG’s were created in GIMP under Ubuntu 10.04 32bit Linix
(disregard the buttons - have not changed that source yet)

Here is a screenshot:

Here is a link to download the PNG image (with alpha transparency set by
GIMP):
http://16bitsoft.com/images/LettersFall2/LettersFall_Text_Logo.png

HOPE SOMEONE CAN HELP!

Here is the relevant source code:

Code:

//------------------------------------------------------------------------------------------------------------------------
if (filePath[0] != ‘~’)
{
tempSurface = NULL;

if ( (tempSurface = IMG_Load(filePath)) )
{
    if ( (tempSurface->w & (tempSurface->w - 1)) != 0 )
    {
        printf("ERROR: Image width is not a power of 2\n");
        loadedImageIsOK = false;
    }

    if ( (tempSurface->h & (tempSurface->h - 1)) != 0 )
    {
        printf("ERROR: Image height is not a power of 2\n");
        loadedImageIsOK = false;
    }

    if (loadedImageIsOK == true)
    {
        tempSurfaceAlpha = SDL_DisplayFormat(tempSurface);
        SDL_SetAlpha(tempSurfaceAlpha, 0, SDL_ALPHA_TRANSPARENT);

        tempSurfaceFixed = SDL_CreateRGBSurface(SDL_SWSURFACE,

tempSurface->w, tempSurface->h, 32,
R_Mask, G_Mask, B_Mask, A_Mask);

        SDL_BlitSurface(tempSurfaceAlpha, NULL, tempSurfaceFixed,

NULL);

        numberOfColors = tempSurfaceFixed->format->BytesPerPixel;
        if (numberOfColors == 4)
        {
            textureFormat = GL_RGBA;
        }
        else if (numberOfColors == 3)
        {
            textureFormat = GL_RGB;
        }
        else
        {
            printf("ERROR: The image is not truecolor\n");
            imageToTextureOK = false;
        }

        Sprites[index].OGL_Texture = (GLuint)NULL;
        if (imageToTextureOK == true)
        {
            glGenTextures( 1, &Sprites[index].OGL_Texture );

            glBindTexture( GL_TEXTURE_2D, Sprites[index].OGL_Texture

);

            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,

GL_NEAREST);//GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
GL_NEAREST);//GL_LINEAR);

            glTexImage2D( GL_TEXTURE_2D, 0, numberOfColors,

tempSurface->w, tempSurface->h, 0,
textureFormat, GL_UNSIGNED_BYTE, tempSurfaceFixed->pixels
);

            if ( tempSurface )
            {
                SDL_FreeSurface( tempSurface );
                SDL_FreeSurface(tempSurfaceFixed);
                SDL_FreeSurface(tempSurfaceAlpha);
            }
        }
    }
}
else
{
    printf("ERROR: SDL could not load image %s\n", SDL_GetError());
    loadedImageIsOK = false;
    imageToTextureOK = false;
}

if (loadedImageIsOK == false || imageToTextureOK == false)  return

false;//index = NumberOfSprites+1;

Sprites[index].ScreenX = 320;
Sprites[index].ScreenY = 240;
Sprites[index].ScaleX = 1.0f;
Sprites[index].ScaleY = 1.0f;
Sprites[index].RotationDegree = 0.0f;
Sprites[index].Transparency = 1.0f;
Sprites[index].redHue = 1.0f;
Sprites[index].greenHue = 1.0f;
Sprites[index].blueHue = 1.0f;
Sprites[index].Smooth = true;
Sprites[index].FlipX = false;
Sprites[index].Width = tempSurface->w;
Sprites[index].Height = tempSurface->h;
Sprites[index].CenterX = Sprites[index].Width / 2;
Sprites[index].CenterY = Sprites[index].Height / 2;
Sprites[index].AnimationTimer = -1;

}

//------------------------------------------------------------------------------------------------------------------------


JeZ+Lee
JessePalser Gmail com
16BitSoft®
Video Game Design Studio
www.16BitSoft.com


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing listSDL at lists.libsdl.orghttp://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing listSDL at lists.libsdl.orghttp://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org