Sign in to follow this  
texel3d

OpenGL OpenTK: Loading texture under Linux

Recommended Posts

Hi,

i have this function to load textures using OpenTK. It works very well under Windows. It can load textures with alpha channel.
But under Linux, alpha channel seem to be not loaded (or set to 255).
When i display a sprite with a texture using:
[CODE]
GL.Enable(EnableCap.Blend);
GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
[/CODE]

colors are ok, but Alpha is ignored.

What is wrong with this function ?
(Or is it a bug in OpenTK under Linux).

[CODE]
public static bool CreateTextureFromFile(string filename,out int textureID)
{
GL.GenTextures(1, out textureID);
GL.BindTexture(TextureTarget.Texture2D, textureID);

try
{
Bitmap bitmap = new Bitmap(filename);
BitmapData data = bitmap.LockBits(
new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height),
ImageLockMode.ReadOnly,
System.Drawing.Imaging.PixelFormat.Format32bppArgb);

GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba,
data.Width, data.Height,
0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);

bitmap.UnlockBits(data);
}
catch (System.Exception e)
{
System.Console.WriteLine("Can't load texture: " + filename);
System.Console.WriteLine(e);
}

GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);


return true;
}
[/CODE]

thanks.

Share this post


Link to post
Share on other sites
I would suggest you try to take this to the OpenTK forum, I don't think you're likely to find help diagnosing an OpenTK bug here.

Share this post


Link to post
Share on other sites
The OpenTK forum does not work for the time beeing (it's not possible to post messages).
But i think it's probably a C# problem in the texture loading code (not opentk). Other blending function wich do not need alpha from texture work on textured sprite. Such as:
GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.One);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this