Results 1 to 5 of 5

Thread: Load TGA files

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2008
    Location
    Sweden, Gävle
    Posts
    1

    Load TGA files

    Is there any easy way to load a TGA to a 2D quad?
    The function I use now distort the TGA file and make the color
    messed up.

    Code :
    GLuint loadTexture(const char * fname, int w, int h)
    {
    	GLuint texture;
    	unsigned char * data;
    	FILE * file;
    	file = fopen(fname, "rb");
    		if(file == NULL) return 0;
    		data = (unsigned char *) malloc (w * h * 3);
    		fread(data, w * h * 3, 1, file);
    	fclose(file);
    	glGenTextures(1, &texture);
    	glBindTexture(GL_TEXTURE_2D, texture); 
    	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 
     
    	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     
    	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
     
    	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
    	free(data);
    	return texture;
    }

    I want to load a TGA and make it as easy as possible to make a
    specific color on the texture transparent.

    Anyone has any idea?

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Dec 2000
    Location
    Reutlingen, Germany
    Posts
    2,042

    Re: Load TGA files

    That code does not load a TGA at all, it simply reads raw data from a file. A TGA contains a header, where width and height is stored and other information, like whether it is RLE compressed and how many channels it has. Also TGAs are usually stored in BGRA format not RGBA.

    Google for "TGA file format" or "TGA loader", there should be plenty of code out there. Many OpenGL tutorials include TGA loaders, since it is a very popular format.

    Jan.
    GLIM - Immediate Mode Emulation for GL3

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2008
    Posts
    6

    Re: Load TGA files

    Very good TGA file format

  4. #4
    Senior Member Frequent Contributor
    Join Date
    Feb 2006
    Location
    Sweden
    Posts
    744

    Re: Load TGA files

    When we worked on the new tutorials for NeHe we decided to create a new free use tga textureloader, it's not the final one that will soon be released, but the final one will use the same load engine witen by yours truly,
    However you can download it as it was in the first beta form here.

  5. #5
    Member Contributor
    Join Date
    Nov 2006
    Location
    Peru
    Posts
    95

    Re: Load TGA files

    Look in this forums for freeimage or image magick libraries

Similar Threads

  1. Can not load .obj files
    By Otak64 in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 01-26-2018, 07:41 AM
  2. load dxf files
    By adhara in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-11-2004, 05:27 AM
  3. Load xyz files
    By tyortel in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 05-06-2004, 08:51 AM
  4. How I can load a MAX (3D Studio MAX) files?
    By in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-11-2003, 03:26 PM
  5. Plib is too big for me, i only want to load 3DS files
    By Morglum in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 07-08-2001, 11:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean