Utilizing the alpha channel on an image with OpenGL

Started by
15 comments, last by The Magical Pot 10 years, 8 months ago

perhaps your texture file loader code is not working.... did you look in your debugger to see what values you have for:

image->w

image->h

image->pixels

Advertisement

The values for image->w and image->h are correct, I have no idea about how to check image->pixel which is a pointer of type void, but when I write image->pixels as an integer, the output for a 32x32 texture is "86048840" if that says anything.

I searched a bit more about other people who have the same problem, but the only solution I've found was to switch over to the DevIL which takes care of image loading.

your image->pixels value will be a bunch of bytes that represent all your pixel data. For example if you are sending RGBA values then you will have 4 bytes per pixel. each byte is just a value from 0 to 255 which represents the color or alpha value.

I still don't know how to check such information, but it seems like there shouldn't be anything wrong with the pixels since the textures work fine when blending isn't enabled. It however seems like this problem isn't really going anywhere, so I could try with the DevIL image loading library instead of SDL's one.

I'd check if the alpha channel is 0 for all pixels

Ok, I gave up on SDL's image loading thingy and switched over to DevIL and it worked perfectly. For me I just added this piece of code right after I initialized OpenGL:


glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable( GL_BLEND );

This will basically enable blending (check out http://www.opengl.org/sdk/docs/man/xhtml/glBlendFunc.xml for more information about glBlendFunc).

To find out how to install and load images with DevIL into OpenGL textures, I'd recommend this link: http://lazyfoo.net/tutorials/OpenGL/06_loading_a_texture/index.php

Note: for Visual Studio users, you have to open up 'ilu.h' and replace the line:


#include <IL/il.h>

With:


#include <il.h>

Since Visual Studio don't include certain files in the same way that other IDEs do.

That worked for me, I hope it works for anyone else who's having the same problem :)

It might actually be the case that SDL only supports colorkeying and not blending, that might explain it since I've successfully used SDL for colorkeying while blending didn't work.

This topic is closed to new replies.

Advertisement