128x600 textures...need help reading them

Started by
4 comments, last by _Titan_ 22 years, 3 months ago
I need to use a texture thats 128x600. The current TGA texture reader doesnt allow for this, it only allows for sizes like 256x256 128x128 etc. I need a tga function that reads in these textures and allows me to use these textures in my project. It needs to do the same thing as my current function does, read 32bit and 24bit textures (with/without alpha). Thnx for any help.
Advertisement
If you use a mipmaped texture it should work otherwise your textures have to be to power of 2.
i''m using this function (the LoadTGA from lesson 33)

/***********************************************************\

bool LoadTGA(TextureImage *texture, char *filename) // Loads A TGA File Into Memory
{
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
GLuint type=GL_RGBA; // Set The Default GL Mode To RBGA (32 BPP)

FILE *file = fopen(filename, "rb"); // Open The TGA File

if( file==NULL || // Does File Even Exist?
fread(TGAcompare,1,sizeof(TGAcompare),file)!=sizeof(TGAcompare) || // Are There 12 Bytes To Read?
memcmp(TGAheader,TGAcompare,sizeof(TGAheader))!=0 || // Does The Header Match What We Want?
fread(header,1,sizeof(header),file)!=sizeof(header)) // If So Read Next 6 Header Bytes
{
if (file == NULL) // Does The File Even Exist? *Added Jim Strong*
return FALSE; // Return False
else // Otherwise
{
fclose(file); // If Anything Failed, Close The File
return FALSE; // Return False
}
}

texture->width = header[1] * 256 + header[0]; // Determine The TGA Width (highbyte*256+lowbyte)
texture->height = header[3] * 256 + header[2]; // Determine The TGA Height (highbyte*256+lowbyte)

if( texture->width <=0 || // Is The Width Less Than Or Equal To Zero
texture->height <=0 || // Is The Height Less Than Or Equal To Zero
(header[4]!=24 && header[4]!=32)) // Is The TGA 24 or 32 Bit?
{
fclose(file); // If Anything Failed, Close The File
return FALSE; // Return False
}

texture->bpp = header[4]; // Grab The TGA''s Bits Per Pixel (24 or 32)
bytesPerPixel = texture->bpp/8; // Divide By 8 To Get The Bytes Per Pixel
imageSize = texture->width*texture->height*bytesPerPixel; // Calculate The Memory Required For The TGA Data

texture->imageData=(GLubyte *)malloc(imageSize); // Reserve Memory To Hold The TGA Data

if( texture->imageData==NULL || // Does The Storage Memory Exist?
fread(texture->imageData, 1, imageSize, file)!=imageSize) // Does The Image Size Match The Memory Reserved?
{
if(texture->imageData!=NULL) // Was Image Data Loaded
free(texture->imageData); // If So, Release The Image Data

fclose(file); // Close The File
return FALSE; // Return False
}

for(GLuint i=0; i { // Swaps The 1st And 3rd Bytes (''R''ed and ''B''lue)
temp=texture->imageData; // Temporarily Store The Value At Image Data ''i''
texture->imageData = texture->imageData; // Set The 1st Byte To The Value Of The 3rd Byte<br> texture->imageData = temp; // Set The 3rd Byte To The Value In ''temp'' (1st Byte Value)<br> }<br><br> fclose (file); // Close The File<br><br> // Build A Texture From The Data<br> glGenTextures(1, &texture[0].texID); // Generate OpenGL texture IDs<br><br> glBindTexture(GL_TEXTURE_2D, texture[0].texID); // Bind Our Texture<br> glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Filtered<br> glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Linear Filtered<br> <br> if (texture[0].bpp==24) // Was The TGA 24 Bits<br> {<br> type=GL_RGB; // If So Set The ''type'' To GL_RGB<br> }<br><br> glTexImage2D(GL_TEXTURE_2D, 0, type, texture[0].width, texture[0].height, 0, type, GL_UNSIGNED_BYTE, texture[0].imageData);<br><br> return true; // Texture Building Went Ok, Return True<br>} </i>
Non-Standard Texture Reader

http://romka.demonews.com/opengl/demos/texture_eng.htm

========================
Leyder Dylan
http://ibelgique.ifrance.com/Slug-Production/
========================Leyder Dylan (dylan.leyder@slug-production.be.tf http://users.skynet.be/fa550206/Slug-Production/Index.htm/
ok, this would be nice if i was reading and using JPEG's! I need 24 and 32bit TGA capabilities like the one i have now, but with mip mapping enabled i guess, or some otehr way of reading in textures like 128x600. MUST BE TGA (TARGA)!! I appriciate your help though, this code will come in handy later on

What if i just changed the line in my function i use now from

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

to

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

would this work?

Edited by - _Titan_ on December 28, 2001 12:41:15 PM
You should replace glTexImage2D with gluBuild2DMipmaps. At that point, mipmapping will be enabled, and it works.

This topic is closed to new replies.

Advertisement