PDA

View Full Version : Texture Displaying Problem



nukem
07-12-2003, 03:40 PM
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 (http://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 (http://zonkbonk.virtualave.net/NuclearBSP.png) compared to the gametutorial screen shot (http://zonkbonk.virtualave.net/GameTutorialsBSP.png) . 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 = &amp;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(&amp;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\n", 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(&amp;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\n", 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

rgpc
07-13-2003, 02:39 AM
Not really relevant to this forum but it looks to me like you leave a texture object bound when you render the "skybox".

The Background/Skybox doesn't have a texture (and in Q3A is normally rendered black rather than white).

Could I suggest that you ask your BSP/Q3 questions on a BSP/Q3 forum? Perhaps gametutorials has some forums?

nukem
07-13-2003, 07:37 PM
Yes I realize that the skybox texture is missing what I was really conserined about is how much duller mine seemed compared to gametutorials and how that looked a little brighter then when it is rendered in Q3A (http://zonkbonk.virtualave.net/Q3ABSP.png) . The TGA thing I was wondering if it was my code opening the TGA or if it was my code telling OGL how to load the data.

rgpc
07-13-2003, 08:19 PM
I'm sure someone on gametutorials (or more relevant forums) would point out that you're not displaying the lightmaps.