Archived

This topic is now archived and is closed to further replies.

coach

non square textures

Recommended Posts

coach    122
is there something special that you have to do to get non square textures to work? The follwing code is ripped straight from the tutorials with a few modifications..doesn''t work on non square textures...works great for square ones though.. bool Texture::load (char* file) { if (!loadTGA(file)) { strcat(file, "textures not found: "); MessageBox ( NULL, file," Message ", MB_OK); return false; } glGenTextures(1, &texID); //Create the texture glBindTexture(GL_TEXTURE_2D, texID); //Bind it glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Linear Filtering //generate the texture glTexImage2D(GL_TEXTURE_2D, 0, type, width, height, 0, type, GL_UNSIGNED_BYTE, imageData); return true; } bool Texture::loadTGA(char* filename) { /* GLubyte* imageData; // Image Data (Up To 32 Bits) TGA GLuint bpp; // Image Color Depth In Bits Per Pixel GLuint width; // Image Width GLuint height; // Image Height GLuint texID; // Texture ID Used To Select A Texture GLuint type; // Set The Default GL Mode To RBGA (32 BPP) */ GLubyte TGAheader[12]={0,0,2,0,0,0,0,0,0,0,0,0}; // Uncompressed TGA Header GLubyte TGAcompare[12]; // Used To Compare TGA Header GLubyte header[6]; // First 6 Useful Bytes From The Header GLuint bytesPerPixel; // Holds Number Of Bytes Per Pixel Used In The TGA File GLuint imageSize; // Used To Store The Image Size When Setting Aside Ram GLuint temp; // Temporary Variable fstream file(filename); // Open The TGA File if (!file) { // does the file exist? return false; } //FIXME: should do some error checking file.read((char*)(&TGAcompare), sizeof(TGAcompare)); // Are There 12 Bytes To Read? if (memcmp(TGAheader,TGAcompare,sizeof(TGAheader))) { // check the header return false; } file.read((char*)&header,sizeof(header)); // read the next 6 bytes width = header[1] * 256 + header[0]; // Determine The TGA Width (highbyte*256+lowbyte) height = header[3] * 256 + header[2]; // Determine The TGA Height (highbyte*256+lowbyte) if( width <=0 || // Is The Width Less Than Or Equal To Zero height <=0 || // Is The Height Less Than Or Equal To Zero (header[4]!=24 && header[4]!=32)){ // Is The TGA 24 or 32 Bit? file.close(); // If Anything Failed, Close The File return false; // Return False } bpp = header[4]; // Grab The TGA''s Bits Per Pixel (24 or 32) (bpp==24) ? type = GL_RGB: type = GL_RGBA; // set the correct type bytesPerPixel= bpp/8; // Divide By 8 To Get The Bytes Per Pixel imageSize = width*height*bytesPerPixel; // Calculate The Memory Required For The TGA Data imageData= new GLubyte[imageSize]; // Reserve Memory To Hold The TGA Data file.read((char*)(imageData),imageSize); for(GLuint i=0; i; // Temporarily Store The Value At Image Data ''i'' imageData[i] = imageData[i + 2]; // Set The 1st Byte To The Value Of The 3rd Byte imageData[i + 2] = temp; // Set The 3rd Byte To The Value In ''temp'' (1st Byte Value) } file.close(); // Close The File return true; } my textures are powers of two (ie 64*128) am I missing something? coach

Share this post


Link to post
Share on other sites
coach    122
alrighty I have just opened the book of knowledge (the red book) and read about gluBuild2DMipmaps(...) instead of glglTexImage2D(...) this solves my problem for textures that are not powers of 2 but I still getting nothing when the width and height are different...(ie 64* 128)

coach

Share this post


Link to post
Share on other sites
Cel    122
By non square textures, perhaps you could just use texture maps with alpha channels.

just make sure glEnable(GL_ALPHA) (or alphatest i cant remember, at work atm)

And as long as the texture has an alpha channel (ie 32bit), it should give the ability to have ''non square'' textures depending on the shape of the alpha channel.

Cel

Share this post


Link to post
Share on other sites