Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "Render_Device.h"
00026
00027 namespace OVR { namespace Render {
00028
00029 Texture* LoadTextureTga(RenderDevice* ren, File* f, unsigned char alpha)
00030 {
00031 f->SeekToBegin();
00032
00033 int desclen = f->ReadUByte();
00034 int palette = f->ReadUByte();
00035 OVR_UNUSED(palette);
00036 int imgtype = f->ReadUByte();
00037 f->ReadUInt16();
00038 int palCount = f->ReadUInt16();
00039 int palSize = f->ReadUByte();
00040 f->ReadUInt16();
00041 f->ReadUInt16();
00042 int width = f->ReadUInt16();
00043 int height = f->ReadUInt16();
00044 int bpp = f->ReadUByte();
00045 f->ReadUByte();
00046 int imgsize = width * height * 4;
00047 unsigned char* imgdata = (unsigned char*) OVR_ALLOC(imgsize);
00048 unsigned char buf[16];
00049 f->Read(imgdata, desclen);
00050 f->Read(imgdata, palCount * (palSize + 7) >> 3);
00051 int bpl = width * 4;
00052
00053 switch (imgtype)
00054 {
00055 case 2:
00056 switch (bpp)
00057 {
00058 case 24:
00059 for (int y = 0; y < height; y++)
00060 for (int x = 0; x < width; x++)
00061 {
00062 f->Read(buf, 3);
00063 imgdata[y*bpl+x*4+0] = buf[2];
00064 imgdata[y*bpl+x*4+1] = buf[1];
00065 imgdata[y*bpl+x*4+2] = buf[0];
00066 imgdata[y*bpl+x*4+3] = alpha;
00067 }
00068 break;
00069 case 32:
00070 for (int y = 0; y < height; y++)
00071 for (int x = 0; x < width; x++)
00072 {
00073 f->Read(buf, 4);
00074 imgdata[y*bpl+x*4+0] = buf[2];
00075 imgdata[y*bpl+x*4+1] = buf[1];
00076 imgdata[y*bpl+x*4+2] = buf[0];
00077 if (buf[3] == 255)
00078 imgdata[y*bpl+x*4+3] = alpha;
00079 else
00080 imgdata[y*bpl+x*4+3] = buf[3];
00081 }
00082 break;
00083
00084 default:
00085 OVR_FREE(imgdata);
00086 return NULL;
00087 }
00088 break;
00089
00090 default:
00091 OVR_FREE(imgdata);
00092 return NULL;
00093 }
00094
00095 Texture* out = ren->CreateTexture(Texture_RGBA|Texture_GenMipmaps, width, height, imgdata);
00096
00097
00098 if(strstr(f->GetFilePath(), "_c."))
00099 {
00100 out->SetSampleMode(Sample_Clamp);
00101 }
00102
00103 OVR_FREE(imgdata);
00104 return out;
00105 }
00106
00107 }}