// // File: texture.cc // // (C) 2000-2006 Helmut Cantzler // // Licensed under the terms of the Lesser General Public License. // #include "texture.h" Texture::Texture() { GLint proxyComponents; image = new Image(); // check which texture sizes are supported max_size=4096*2; do { max_size/=2; glTexImage2D(GL_PROXY_TEXTURE_2D, 0, GL_RGB, max_size, max_size, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &proxyComponents); } while (proxyComponents != GL_RGB); //printf("Max texture size is: %dx%d\n", max_size, max_size); } Texture::~Texture() { delete image; } int Texture::read(const char *filename) { int width, height; delete image; image = new Image(); // Read the image if (image->read(filename) != 0) return 1; // printf(" Read texture: %s\n", filename); //texture_format=GL_LUMINANCE; texture_format=GL_RGB; // Find texture size width=max_size; height=max_size; while (image->width() / width < 0.8) width/=2; while (image->height() / height < 0.8) height/=2; // printf(" Scale from %dx%d to %dx%d\n", image_height, image_width, // texture_height, texture_width); // Scale image to texture size image->scale(height, width); return 0; } int Texture::height(void) const { return image->height(); } int Texture::width(void) const { return image->width(); } int Texture::color_components(void) const { return 3; } GLenum Texture::format(void) const { return texture_format; } const unsigned char* Texture::data(void) const { return image->data(); }