I have created a texture loading class as well as a BSP class. The TGA function and the BSP class are both based off the ones at www.gametutorials.com . For Some reason when I render it using my code I get some of the textures displaying weird. I think it may have something to do with my TGA code but have a look at my screen shot compared to the gametutorial screen shot . Im not sure whats wrong here is my TGA code
unsigned long x;
unsigned long y;
unsigned short int bpp; //bits per pixels unsigned short int
BYTE* data; //the data of the image
unsigned long size; //length of the file
int channels; //the channels of the image 3 = RGA 4 = RGBA
GLuint type;bool LoadTGA(char* FileName)
{
unsigned short width;
unsigned short height;
BYTE length; //the size must be BYTE
BYTE bits; //the bpp must be a BYTE
BYTE imagetype; //finds out the image type RLE RGB Alpha
int stride; //the stride(channels * width)
FILE* file = fopen(FileName, “rb”);if(!file)
{
fprintf(stderr, “Error reading TGA file %s!!!”, FileName);
return false;
}//read the length in BYTES
fread(&length, sizeof(BYTE), 1, file);fseek(file, 1, SEEK_CUR);
//read in the data to find out what kina image it is
fread(&imagetype, sizeof(BYTE), 1, file);fseek(file, 9, SEEK_CUR);
//read the width height and bits
fread(&width, sizeof(unsigned short), 1, file);
fread(&height, sizeof(unsigned short), 1, file);
fread(&bits, sizeof(BYTE), 1, file);fseek(file, length + 1, SEEK_CUR);
if(imagetype == TGA_RGB | | imagetype == TGA_A)
{
if(bits == 24 | | bits == 32)
{
channels = bits / 8;
stride = channels * width;
data = new BYTE[stride * height];for(int i = 0;i<height;i++) { unsigned char* line = &data[stride * i]; fread(line, stride, 1, file); //for some reason TGA files store data as BGR not RGB this just converts it for(int j = 0;j<stride;j+=channels) { int temp = line[i]; line[i] = line[i + 2]; line[i + 2] = temp; } } }else if(bits == 16) { //we just convert this to 24 bit unsigned short pixels = 0; int r, b, g; channels = 3; stride = channels * width; data = new BYTE[stride * height]; for(int i=0;i<width*height;i++) { //read the pixel fread(&pixels, sizeof(unsigned short), 1, file); b = (pixels & 0x1f) << 3; g = ((pixels >> 5) & 0x1f) << 3; r = ((pixels >> 10) & 0x1f) << 3; data[i * 3] = r; data[i * 3 + 1] = g; data[i * 3 + 2] = b; } }else{ fprintf(stderr, "TGA must be 16 24 or 32 bits per pixel not %i: %s
", bits, FileName);
fclose(file);
return false;
}
}else if(imagetype == TGA_RLE)
{
BYTE rleid;
int colorsread = 0;
channels = bits / 8;
stride = channels * width;data = new BYTE[stride * height]; BYTE* colors = new BYTE[channels]; for(int i=0;i<width*height;i++) { fread(&rleid, sizeof(BYTE), 1, file); if(rleid < 128) { rleid++; while(rleid) { fread(colors, sizeof(BYTE) * channels, 1, file); data[colorsread] = colors[2]; data[colorsread + 1] = colors[1]; data[colorsread + 2] = colors[0]; if(bits == 32) { data[colorsread + 3] = colors[3]; } rleid--; colorsread += channels; } }else{ rleid -= 127; fread(colors, sizeof(BYTE) * channels, 1, file); while(rleid) { data[colorsread] = colors[2]; data[colorsread + 1] = colors[1]; data[colorsread + 2] = colors[0]; if(bits == 32) { data[colorsread + 3] = colors[3]; } rleid--; colorsread+=channels; } } }
}else{
fprintf(stderr, "TGA type not supported: %s
", FileName);
fclose(file);
return false;
}fclose(file);
type = GL_RGB;
if(channels == 4)
{
type = GL_RGBA;
}bpp = bits;
size = length;
x = width;
y = height;return true;
}
Thanks
nuke