Jump to content
  • Advertisement

Archived

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

colinisinhere

Tga size?

This topic is 5382 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

Im creating a 2d game, so i need all the textures to be different sizes, like 16 x 80 and stuff, right now im using this code from one of nehe''s tutorials to load Tga''s:
// g_tga.h

/* 
=======Stick Army=======
Coded by Colin Hill 2003
======================== 
*/

#define T_FONT1 0

struct tga								
{
	GLubyte	*imageData;										
	GLuint	bpp;											
	GLuint	width;									
	GLuint	height;										
	GLuint	texID;										
};

tga textures[100];

bool loadTGA(tga *texture, char *filename)				
{    
	GLubyte		TGAheader[12]={0,0,2,0,0,0,0,0,0,0,0,0};	
	GLubyte		TGAcompare[12];								
	GLubyte		header[6];									
	GLuint		bytesPerPixel;									
	GLuint		imageSize;									
	GLuint		temp;										
	GLuint		type=GL_RGBA;								

	FILE *file = fopen(filename, "rb");						

	if(	file==NULL ||										
		fread(TGAcompare,1,sizeof(TGAcompare),file)!=sizeof(TGAcompare) ||	
		memcmp(TGAheader,TGAcompare,sizeof(TGAheader))!=0				||	
		fread(header,1,sizeof(header),file)!=sizeof(header))			
	{
		if (file == NULL)								
			return FALSE;									
		else												
		{
			fclose(file);									
			return FALSE;									
		}
	}

	texture->width  = header[1] * 256 + header[0];			
	texture->height = header[3] * 256 + header[2];				
    
 	if(	texture->width	<=0	||								
		texture->height	<=0	||								
		(header[4]!=24 && header[4]!=32))					
	{
		fclose(file);											
		return FALSE;										
	}

	texture->bpp	= header[4];							
	bytesPerPixel	= texture->bpp/8;						
	imageSize		= texture->width*texture->height*bytesPerPixel;

	texture->imageData=(GLubyte *)malloc(imageSize);	

	if(	texture->imageData==NULL ||								
		fread(texture->imageData, 1, imageSize, file)!=imageSize)	
	{
		if(texture->imageData!=NULL)					
			free(texture->imageData);						

		fclose(file);								
		return false;									
	}

	for(GLuint i=0; i<int(imageSize); i+=bytesPerPixel)		
	{														
		temp=texture->imageData[i];							
		texture->imageData[i] = texture->imageData[i + 2];	
		texture->imageData[i + 2] = temp;					
	}

	fclose (file);										


	glGenTextures(1, &texture[0].texID);				

	glBindTexture(GL_TEXTURE_2D, texture[0].texID);			
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);	
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);	
	
	if (texture[0].bpp==24)									
	{
		type = GL_RGB;										
	}

	glTexImage2D(GL_TEXTURE_2D, 0, type, texture[0].width, texture[0].height, 0, type, GL_UNSIGNED_BYTE, texture[0].imageData);
	return true;											
}
but this will only open 8x8 16x16 32x32 64x64 128x128 ECT... how can i make this open any sized texuture?

Share this post


Link to post
Share on other sites
Advertisement
you can open 16*128 and similar as well, you just need 2^n on each side, they doesnt need to be the same.

Are you sure that you have games that doenst have 2^n textures.. well if that is so, then they scale or pad them on load ( gluBuildMipmap automaticly rescales even the first mipmaplevel so it can handle uneven sizes)

Share this post


Link to post
Share on other sites
use ''NV_texture_rectangle'' or ''GL_EXT_texture_rectangle'' (can''t find its specs.


-----------------------------
Amma

Share this post


Link to post
Share on other sites
A lot of 2D games put all of there texture resources into a few big textures which cuts down on texture loading and thrashing. You can put a lot of stuff for a 2D game on a 256x256 texture. Seen one game where they only used 2 256x256 textures but shifted the uv''s to make up to 25 different creature characters. Works great for tile mapping too.

Share this post


Link to post
Share on other sites
Not really, its just that the gluBuildMipmap function automaticly resizes your non power of 2 to a n^2 texture before uploading it to the cards.. but i dont know it its up to the nearest, or down to the nearest power. ( better to do that yourself)

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!