TEXTURE/Rose_1.dds Not Found!劲舞团texture弹出这个窗…

TEXTURE/gui/userfo/pig_event.dds Not Found!劲舞团上老是出现着个你出现就掉出来了着是东西啊要怎么解决啊
你可以重新***一遍就好拉要是再上不去那我也没办法了
为您推荐:
其他类似问题
扫描下载二维码DDS loading in C++
Source Code
a look under the hood and perhaps add a tweak or 2.
During the making of Racer, the DDS file format came up. Although used a lot by Microsoft's DirectX, for use in OpenGL the information on the internet is sparse. There is Microsoft's documentation on the file format. However, in OpenGL, all textures need to be flipped vertically (compared to use in DirectX). And as the file data is compressed, this means that we have to flip the compressed data!
The solution came more or less with Chromium, the open source version of Google's browser. That browser contains a DDS loader, but it had bugs (I've reported those so it may have changed). In time also, here at Cruden we started using the DDS file format more often and some other bugs were fixed.
The source code below is the current version of our DDS loader. It doesn't contain the pixel flipping bugs in Chromium, and at a late time the last 2 mipmap levels loading was also fixed. Hopefully this is useful for other people trying to load .dds files in their OpenGL projects.
#ifndef __D3_DDS_H
#define __D3_DDS_H
// Structures from Direct3D 9
struct D3D_PixelFormat // DDPIXELFORMAT
int dwFourCC;
int dwRGBBitC
int dwRBitMask, dwGBitMask, dwBBitM
int dwRGBAlphaBitM
struct D3D_Caps2
int dwCaps1;
int dwCaps2;
int Reserved[2];
struct D3D_SurfaceDesc2
int dwPitchOrLinearS
int dwMipMapC
int dwReserved1[11];
D3D_PixelFormat ddpfPixelF
D3D_Caps2 ddsC
int dwReserved2;
#define FOURCC(a, b, c, d) \
((unsigned int)((unsigned int)(a)
((unsigned int)(b) &&
((unsigned int)(c) && 16) | \
((unsigned int)(d) && 24))
typedef enum
DDS_COMPRESS_NONE = 0,
DDS_COMPRESS_BC1,
DDS_COMPRESS_BC2,
DDS_COMPRESS_BC3,
DDS_COMPRESS_BC3N,
/* DXT5n */
DDS_COMPRESS_BC4,
DDS_COMPRESS_BC5,
DDS_COMPRESS_AEXP,
DDS_COMPRESS_YCOCG,
DDS_COMPRESS_YCOCGS,
DDS_COMPRESS_MAX
} DDS_COMPRESSION_TYPE;
typedef enum
DDS_S***E_SELECTED_LAYER = 0,
DDS_S***E_CUBEMAP,
DDS_S***E_VOLUMEMAP,
DDS_S***E_MAX
} DDS_S***E_TYPE;
typedef enum
DDS_FORMAT_DEFAULT = 0,
DDS_FORMAT_RGB8,
DDS_FORMAT_RGBA8,
DDS_FORMAT_BGR8,
DDS_FORMAT_ABGR8,
DDS_FORMAT_R5G6B5,
DDS_FORMAT_RGBA4,
DDS_FORMAT_RGB5A1,
DDS_FORMAT_RGB10A2,
DDS_FORMAT_R3G3B2,
DDS_FORMAT_A8,
DDS_FORMAT_L8,
DDS_FORMAT_L8A8,
DDS_FORMAT_AEXP,
DDS_FORMAT_YCOCG,
DDS_FORMAT_MAX
} DDS_FORMAT_TYPE;
typedef enum
DDS_COLOR_DEFAULT = 0,
DDS_COLOR_DISTANCE,
DDS_COLOR_LUMINANCE,
DDS_COLOR_INSET_BBOX,
DDS_COLOR_MAX
} DDS_COLOR_TYPE;
typedef enum
DDS_MIPMAP_DEFAULT = 0,
DDS_MIPMAP_NEAREST,
DDS_MIPMAP_BOX,
DDS_MIPMAP_BILINEAR,
DDS_MIPMAP_BICUBIC,
DDS_MIPMAP_LANCZOS,
DDS_MIPMAP_MAX
} DDS_MIPMAP_TYPE;
#define DDS_HEADERSIZE
#define DDSD_CAPS
#define DDSD_HEIGHT
#define DDSD_WIDTH
#define DDSD_PITCH
#define DDSD_PIXELFORMAT
#define DDSD_MIPMAPCOUNT
#define DDSD_LINEARSIZE
#define DDSD_DEPTH
#define DDPF_ALPHAPIXELS
#define DDPF_ALPHA
#define DDPF_FOURCC
#define DDPF_PALETTEINDEXED8
#define DDPF_RGB
#define DDPF_LUMINANCE
#define DDSCAPS_COMPLEX
#define DDSCAPS_TEXTURE
#define DDSCAPS_MIPMAP
#define DDSCAPS2_CUBEMAP
#define DDSCAPS2_CUBEMAP_POSITIVEX 0x
#define DDSCAPS2_CUBEMAP_NEGATIVEX 0x
#define DDSCAPS2_CUBEMAP_POSITIVEY 0x
#define DDSCAPS2_CUBEMAP_NEGATIVEY 0x
#define DDSCAPS2_CUBEMAP_POSITIVEZ 0x
#define DDSCAPS2_CUBEMAP_NEGATIVEZ 0x
#define DDSCAPS2_VOLUME
class DDDS
// A cross-platform DDS loader
MAX_MIPMAP_LEVEL=16
images (2^16)
unsigned char *pixels[MAX_MIPMAP_LEVEL];
// Texture data
bytes[MAX_MIPMAP_LEVEL];
// Info extracted from file
int mipmapL
int internalF
int compressionT
int blockS
// Used in passing compressed textures to OpenGL
GetWidth(){ }
GetHeight(){ }
GetMipMapLevels(){ return mipmapL }
bool Load(cstring fname);
DTexture *CreateTexture();
* D3 - DDS loading
* 09-04-09: Created!
* 16-04-09: Now vertically flips DDS files. Wasn't that easy, since you need to flip each 4x4 pixel block.
* ??-??-10: Fixed last 2 mipmap level loading (not loaded correctly)
* - Add max mipmap level (if DDS file doesn't contain all mipmap levels)
#include &d3/d3.h&
#include &qlib/debug.h&
#include &d3/dds.h&
DEBUG_ENABLE
// Loading images
//#define LTRACE_LOAD
#define MAGIC_DDS 0x
// DDS&space&
// DXT&n& id's
#define ID_DXT1
#define ID_DXT3
#define ID_DXT5
DDDS::DDDS()
for(i=0;i&MAX_MIPMAP_LEVEL;i++)
pixels[i]=0;
bytes[i]=0;
mipmapLevels=0;
wid=hgt=0;
compressionType=0;
internalFormat=0;
blockSize=0;
DDDS::~DDDS()
for(i=0;i&MAX_MIPMAP_LEVEL;i++)
QFREE(pixels[i]);
static void ConvertARGB2RGBA(unsigned char *a,int n)
// In hex dump: BGRA -& RGBA
for(i=0;i&n;i++)
a[2]=a[0];
static void FlipDXT1BlockFull(unsigned char *data)
// A DXT1 block layout is:
// [0-1] color0.
// [2-3] color1.
// [4-7] color bitmap, 2 bits per pixel.
// So each of the 4-7 bytes represents one line, flipping a block is just
// flipping those bytes.
// Note that http://src.chromium.org/viewvc/chrome/trunk/src/o3d/core/cross/bitmap_dds.cc?view=markup&pathrev=21227
// contains an error in the last line: data[6]=data[5] is a bug!
tmp=data[4];
data[4]=data[7];
tmp=data[5];
data[5]=data[6];
static void FlipDXT3BlockFull(unsigned char *block)
// Flips a full DXT3 block in the y direction.
// A DXT3 block layout is:
alpha bitmap, 4 bits per pixel.
// [8-15] a DXT1 block.
// We can flip the alpha bits at the byte level (2 bytes per line).
unsigned char tmp = block[0];
block[0] = block[6];
block[6] =
tmp = block[1];
block[1] = block[7];
block[7] =
tmp = block[2];
block[2] = block[4];
block[4] =
tmp = block[3];
block[3] = block[5];
block[5] =
// And flip the DXT1 block using the above function.
FlipDXT1BlockFull(block + 8);
static void QBitDump(unsigned char *a,int n)
char buf[1024],*d;
qdbg(&Bitdump at %p&,a);
for(i=0;i&n;i++)
for(j=0;j&8;j++)
if(a[i]&(1&&j))*d++='1';
if((bits%12)==11)*d++='.';
qdbg(&%s\n&,buf);
static void FlipDXT5BlockFull(unsigned char *block)
// From http://src.chromium.org/viewvc/chrome/trunk/src/o3d/core/cross/bitmap_dds.cc?view=markup&pathrev=21227
// Original s fixed here.
// A DXT5 block layout is:
alpha bitmap, 3 bits per pixel.
// [8-15] a DXT1 block.
// The alpha bitmap doesn't easily map lines to bytes, so we have to
// interpret it correctly.
Extracted from
// http://www.opengl.org/registry/specs/EXT/texture_compression_s3tc.txt :
The 6 &bits& bytes of the block are decoded into one 48-bit integer:
bits = bits_0 + 256 * (bits_1 + 256 * (bits_2 + 256 * (bits_3 +
256 * (bits_4 + 256 * bits_5))))
bits is a 48-bit unsigned integer, from which a three-bit control code
is extracted for a texel at location (x,y) in the block using:
code(x,y) = bits[3*(4*y+x)+1..3*(4*y+x)+0]
where bit 47 is the most significant and bit 0 is the least
significant bit.
//QBitDump(block+2,6);
// From Chromium (source was buggy)
unsigned int line_0_1 = block[2] + 256 * (block[3] + 256 * block[4]);
unsigned int line_2_3 = block[5] + 256 * (block[6] + 256 * block[7]);
// swap lines 0 and 1 in line_0_1.
unsigned int line_1_0 = ((line_0_1 & 0x000fff) && 12) |
((line_0_1 & 0xfff000) && 12);
// swap lines 2 and 3 in line_2_3.
unsigned int line_3_2 = ((line_2_3 & 0x000fff) && 12) |
((line_2_3 & 0xfff000) && 12);
block[2] = line_3_2 & 0
block[3] = (line_3_2 & 0xff00) && 8;
block[4] = (line_3_2 & 0xff0000) && 16;
block[5] = line_1_0 & 0
block[6] = (line_1_0 & 0xff00) && 8;
block[7] = (line_1_0 & 0xff0000) && 16;
// And flip the DXT1 block using the above function.
FlipDXT1BlockFull(block+8);
bool DDDS::Load(cstring fname)
unsigned char *temp=0;
QFile *f=new QFile(fname);
f-&Read(&magic,sizeof(magic));
if(magic!=MAGIC_DDS)
// Direct3D 9 format
D3D_SurfaceDesc2
f-&Read(&header,sizeof(header));
//qdbg(&pixelfmt: rgb bit count %d\n&,header.ddpfPixelFormat.dwRGBBitCount);
// Remember info for users of this object
wid=header.dwW
hgt=header.dwH
mipmapLevels=header.dwMipMapC
// Number of pixels
nBytes=header.dwHeight*header.dwW
// Block size default
blockSize=16;
if(header.ddpfPixelFormat.dwFlags&DDPF_FOURCC)
// Compressed
format=DDS_FORMAT_YCOCG;
// ???????? Not right
unsigned int fourCC;
fourCC=header.ddpfPixelFormat.dwFourCC;
if(fourCC==ID_DXT1)
blockSize=8;
internalFormat=GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
//internalFormat=GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;
} else if(fourCC==ID_DXT3)
internalFormat=GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
//internalFormat=GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;
} else if(fourCC==ID_DXT5)
internalFormat=GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
//internalFormat=GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
char buf[5];
buf[0]=fourCC&255;
buf[1]=(fourCC&&8)&255;
buf[2]=(fourCC&&16)&255;
buf[3]=(fourCC&&24)&255;
qwarn(&DDDS:Load(%s); unknown compressed format (%s)&,fname,buf);
// DXT5 compression
//bytes/=4;
} else if(header.ddpfPixelFormat.dwRGBBitCount==32)
format=DDS_FORMAT_RGBA8;
// Calculate bytes for highest mipmap level
//bytes=header.dwHeight*header.dwWidth*header.ddpfPixelFormat.dwRGBBitCount/8;
nBytes=nBytes*header.ddpfPixelFormat.dwRGBBitCount/8;
} else //if(header.ddpfPixelFormat.dwRGBBitCount!=32)
qwarn(&DDDS:Load(%s); unknown DDS format (rgb bitcount not 32, not DXT5)&,fname);
// Read all mipmap levels
for(i=0;i&header.dwMipMapCount&&i&MAX_MIPMAP_LEVEL;i++)
// Deduce # of bytes
// Close to the higher mipmap levels, wid or hgt may become 0; keep things at 1
if(w==0)w=1;
if(h==0)h=1;
if(format==DDS_FORMAT_RGBA8)
nBytes=w*h*4;
nBytes=((w+3)/4)*((h+3)/4)*blockS
// Create temp buffer to flip DDS
temp=(unsigned char*)qalloc(nBytes);
bytes[i]=nB
pixels[i]=(unsigned char*)qalloc(nBytes);
if(!pixels[i])
qerr(&DDDS:Load(%s); out of memory for mipmap level %d&,fname,i);
if(format!=DDS_FORMAT_RGBA8)
// First read in temp buffer
f-&Read(temp,nBytes);
// Flip & copy to actual pixel buffer
int j,widBytes,k;
unsigned char *s,*d;
widBytes=((w+3)/4)*blockS
d=pixels[i]+((h+3)/4-1)*widB
//int count=0;
for(j=0;j&(h+3)/4;j++)
memcpy(d,s,widBytes);
if(blockSize==8)
for(k=0;k&widBytes/blockSk++)
FlipDXT1BlockFull(d+k*blockSize);
// DXT3, DXT5
if(compressionType==DDS_COMPRESS_BC2)
for(k=0;k&widBytes/blockSk++)
FlipDXT3BlockFull((unsigned char*)d+k*blockSize);
for(k=0;k&widBytes/blockSk++)
FlipDXT5BlockFull((unsigned char*)d+k*blockSize);
//count+=widB
//qdbg(&j=%d/%d - count=%d (total %d)\n&,j,h,count,nBytes); QWait(1);
count=123;
//f-&Read(pixels[i],nBytes);
if(format==DDS_FORMAT_RGBA8)
ConvertARGB2RGBA(pixels[i],nBytes);
// Next level is smaller
// Release temp buffer
QFREE(temp);
QDELETE(f);
QDELETE(f);
DTexture *DDDS::CreateTexture()
// Create a texture from this dds
DTexture *t;
int i,w,h;
t=new DTexture();
t-&SetSize(w,h);
t-&EnableMipmap(true);
t-&DisableCompression();
t-&SetInternalFormat(DTexture::IF_RGBA);
t-&CreateTexture();
// Fill mipmaps
t-&Select();
// Define mipmap range
if(mipmapLevels&0)
t-&SetMipMapRange(0,mipmapLevels-1);
glPixelStorei(GL_UNPACK_ROW_LENGTH,0);
glPixelStorei(GL_UNPACK_SKIP_ROWS,0);
glPixelStorei(GL_UNPACK_SKIP_PIXELS,0);
for(i=0;i&mipmapLi++)
// Keep size at a minimum
if(w==0)w=1;
if(h==0)h=1;
if(pixels[i])
if(format==DDS_FORMAT_RGBA8)
glTexImage2D(GL_TEXTURE_2D,i,GL_RGBA,w,h,0,GL_RGBA,GL_UNSIGNED_BYTE,pixels[i]);
// Compressed formats
if(format==DDS_FORMAT_YCOCG)
// DXT1/3/5
glCompressedTexImage2D(GL_TEXTURE_2D,i,internalFormat,w,h,0,bytes[i],pixels[i]);
qwarn(&DDS:CreateT not DDS_FORMAT_YCOCG for mipmap level %d&,i);
// Verify that compression took place
QShowGLErrors(&DDDS:CreateTexture()&);
GLint param=0;
glGetTexLevelParameteriv(GL_TEXTURE_2D,i,GL_TEXTURE_COMPRESSED_ARB,¶m);
if(param==0)
qwarn(&DDDS:CreateTexture(); mipmap level %d indicated compression failed&,i);
GLint param=0;
glGetTexLevelParameteriv(GL_TEXTURE_2D,i,GL_TEXTURE_INTERNAL_FORMAT,¶m);
//qdbg(&Mipmap %d: internal format 0x%x\n&,i,param);
qwarn(&DDDS:CreateTexture(); missing pixels for mipmap level %d&,i);
// Next level uses less levels
The original files (with better formatting than above) can be found here:
Known problems in the above code:
It doesn't load cubemaps
Not all DDS files provi you need to specify which mipmap levels exist to OpenGL using these calls:
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_BASE_LEVEL,baseLevel);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAX_LEVEL,maxLevel);
(this is done in the above code using DTexture::SetMipMapRange())
November 13, 2012

参考资料

 

随机推荐