Jump to content
  • Advertisement


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


Hey, could someone help me plz!?

This topic is 6455 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Can someone please tell me whats wrong with this code. bool CFont::LoadTexture(TextureImage *texture,char *filename) { //================AADDED EXTRA+================================== typedef struct { GLubyte r; GLubyte g; GLubyte b; GLubyte a; } PIXEL, *PPIXEL; //================AADDED EXTRA+================================== 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) // Did The File Even Exist? *Added Jim Strong* return false; // Return False else { 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; iimageData; // Temporarily Store The Value At Image Data ''i'' texture->imageData[i] = texture->imageData[i + 2]; // Set The 1st Byte To The Value Of The 3rd Byte texture->imageData[i + 2] = temp; // Set The 3rd Byte To The Value In ''temp'' (1st Byte Value) } fclose (file); // Close The File //================AADDED EXTRA+================================== unsigned char *pTexture = texture->imageData; PPIXEL Texture = (PPIXEL)LocalAlloc(LMEM_FIXED, texture->width*texture->height*sizeof(PIXEL)); for(int j=0; jheight; j++) for(int i=0; iwidth; i++) { unsigned char b = *pTexture++; unsigned char g = *pTexture++; unsigned char r = *pTexture++; Texture[(texture->height-1-j)*texture->width + i].r = b; Texture[(texture->height-1-j)*texture->width + i].g = b; Texture[(texture->height-1-j)*texture->width + i].b = b; Texture[(texture->height-1-j)*texture->width + i].a = 255 - (r-g); } //================AADDED EXTRA+================================== glBindTexture(GL_TEXTURE_2D, texture[0].texID); // Bind Our Texture glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //GL_NEAREST);// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //or GL_CLAMP glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //or GL_CLAMP if (texture[0].bpp==24) // Was The TGA 24 Bits { type=GL_RGB; // If So Set The ''type'' To GL_RGB } glTexImage2D(GL_TEXTURE_2D, 0, type, texture[0].width, texture[0].height, 0, type, GL_UNSIGNED_BYTE, Texture);//texture[0].imageData LocalFree(Texture); return true; }

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!