From 3d993058e5078fbdfd92d479281ad93bb40a4bc6 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Wed, 26 Mar 2008 23:24:26 +0000 Subject: improved TGA handling --- src/render/render.cc | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'src/render/render.cc') diff --git a/src/render/render.cc b/src/render/render.cc index 15a6d5c..3a9ebd3 100644 --- a/src/render/render.cc +++ b/src/render/render.cc @@ -10,6 +10,8 @@ #include #include "render/render.h" +#include "render/tga.h" +#include "render/gl.h" #include "core/core.h" #include "filesystem/filesystem.h" #include "sys/sys.h" @@ -22,6 +24,32 @@ core::Cvar *r_drawradius = 0; core::Cvar *r_drawstats = 0; core::Cvar *r_wireframe = 0; +bool texture(char * const filename, size_t id) +{ + Image *image = TGA::load(filename); + if (!image) + return false; + + // FIXME - I don't get this part... yet + + glGenTextures(1, &textures[id]); + glBindTexture(GL_TEXTURE_2D, textures[id]); + + int texture_type; + if (image->channels() == 4) + texture_type = GL_RGBA; + else + texture_type = GL_RGB; + + gluBuild2DMipmaps(GL_TEXTURE_2D, image->channels(), + image->width(), image->height(), texture_type, GL_UNSIGNED_BYTE, image->data()); + + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR); + + return true; +} + void init() { con_print << "Initializing renderer..." << std::endl; @@ -32,11 +60,11 @@ void init() con_print << "Loading textures..." << std::endl; - if (!TGA::texture(textures, "bitmaps/loader.tga", 0)) { + if (!texture( "bitmaps/loader.tga", 0)) { con_error << "Essential file bitmaps/loader.tga missing" << std::endl; core::application()->shutdown(); } - if (!TGA::texture(textures, "bitmaps/conchars.tga", 1)) { + if (!texture("bitmaps/conchars.tga", 1)) { con_error << "Essential file bitmaps/conchars.tga missing" << std::endl; core::application()->shutdown(); } -- cgit v1.2.3