Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: texture loading with alpha

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2010
    Posts
    17

    texture loading with alpha

    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;
    }

  2. #2
    Junior Member Regular Contributor
    Join Date
    Sep 2000
    Location
    France
    Posts
    193

    Re: texture loading with alpha

    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.

  3. #3
    Intern Contributor Abdallah DIB's Avatar
    Join Date
    Feb 2009
    Location
    France
    Posts
    70

    Re: texture loading with alpha

    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(...)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •