killstealers / crashburn

This is the crashburn project, a simple 3D multiplayer video game, based on Crash Bash.
https://github.com/killstealers/crashburn
1 stars 0 forks source link

Loader TGA #1

Closed NewbiZ closed 11 years ago

NewbiZ commented 11 years ago

Done:

Missing:

NewbiZ commented 11 years ago

24 and 32bpp are enough. Nobody ever use 16bpp nowadays.

As for color mapped and direct color, I don't know of any editor that still use this, so closing the ticket for now, will add support for other formats as needed.

NewbiZ commented 11 years ago

Usage notes:

// Create a texture info structure
crashburn::TextureInfo texture_info

// Load a TGA file, filling the provided texture info with
crashburn::load_tga("./file.tga", texture_info);

The TextureInfo structure contains all the necessary bits to upload the texture to video memory later on.

GLuint load_texture(const std::string& filename)
{
    GLuint texture;
    glGenTextures(1, &texture);
    crashburn::TextureInfo texture_info;
    crashburn::load_tga(filename, texture_info);
    glBindTexture(GL_TEXTURE_2D, texture);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexImage2D(texture_info.target,
                 texture_info.level,
                 texture_info.internalFormat,
                 texture_info.width,
                 texture_info.height,
                 0,
                 texture_info.format,
                 texture_info.type,
                 texture_info.data);
    delete [] texture_info.data;
    return texture;
}
NewbiZ commented 11 years ago

test_tga