PDA

View Full Version : texture loading with alpha



RobertEd
05-14-2010, 10:39 AM
Some help plese...

Has anyone had any luck loading in a texture with a alpha channel? Can you post a link to some source?



QUICK ? --> Why do I get this error (invalid conversion from `void*' to `BYTE*')


GLuint LoadTexture( const char * filename, int wrap, int width, int height )
{
GLuint texture;

BYTE * data;
FILE * file;

// open texture data
file = fopen( filename, "rb" );
if ( file == NULL ) return 0;

// allocate buffer

data = malloc( width * height * 3 );

// read texture data
fread( data, width * height * 3, 1, file );
fclose( file );

// allocate a texture name
glGenTextures( 1, &texture );

// select our current texture
glBindTexture( GL_TEXTURE_2D, texture );

// select modulate to mix texture with color for shading
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

// when texture area is small, bilinear filter the closest mipmap
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_NEAREST );
// when texture area is large, bilinear filter the first mipmap
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );

// if wrap is true, the texture wraps over at the edges (repeat)
// ... false, the texture ends at the edges (clamp)
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
wrap ? GL_REPEAT : GL_CLAMP );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
wrap ? GL_REPEAT : GL_CLAMP );

// build our texture mipmaps
gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height,
GL_RGB, GL_UNSIGNED_BYTE, data );

// free buffer
free( data );

return texture;
}

Nicolas Lelong
05-14-2010, 01:08 PM
This has _nothing_ to do with alpha channel... This is a basic C programming problem: you have to explicitly convert the types you're using, or change them.

You could try to change your 'data' declaration to :
void * data;

You may also want to set GL_UNPACK_ALIGNMENT to 1.

Abdallah DIB
05-14-2010, 06:35 PM
i dont know if this has something to do with textures with alpha channels,
check this link, it is an image library that has a systax similar to opengl
http://openil.sourceforge.net/
now concerning ur compiler error . cast the return value of malloc to BYTE*
(BYTE*)malloc(...)