void MESHXFILE::InitXMesh(wchar_t *xfile) //传入x文件名,创建网格对象与纹理 { LPD3DXBUFFER pAdjBuffer = NULL; LPD3DXBUFFER pMtrlBuffer = NULL; //读取x文件中的网格数据 D3DXLoadMeshFromX(xfile, D3DXMESH_MANAGED, _device, &pAdjBuffer, &pMtrlBuffer, NULL, &_NumMaterials, &_mesh); //读取材质和纹理数据 D3DXMATERIAL *pMaterial = (D3DXMATERIAL*)pMtrlBuffer->GetBufferPointer(); _materials = new D3DMATERIAL9[_NumMaterials]; //创建记录材质信息的对象 _textures = new LPDIRECT3DTEXTURE9[_NumMaterials]; //创建记录纹理的指针 for(DWORD i = 0;i < _NumMaterials;i++) { _materials[i] = pMaterial[i].MatD3D; _materials[i].Ambient = _materials[i].Diffuse; _textures[i] = NULL; char *name_xfile; name_xfile = new char; if(pMaterial[i].pTextureFilename != NULL) { find_texture(xfile,&name_xfile,pMaterial[i].pTextureFilename); D3DXCreateTextureFromFileA(_device, name_xfile, //从pMtrBuffer得到起始地址 &_textures[i]); //存储纹理 } if(name_xfile != NULL) delete []name_xfile; } pAdjBuffer->Release(); pMtrlBuffer->Release(); //设置纹理过滤模式 }
void free_texture(GLContext *c, int h) { GLTexture *t, **ht; GLImage *im; t = find_texture(c, h); if (!t->prev) { ht = &c->shared_state.texture_hash_table[t->handle % TEXTURE_HASH_TABLE_SIZE]; *ht = t->next; } else { t->prev->next = t->next; } if (t->next) t->next->prev = t->prev; for (int i = 0; i < MAX_TEXTURE_LEVELS; i++) { im = &t->images[i]; if (im->pixmap) im->pixmap.free(); } gl_free(t); }
void glInitTextures(GLContext *c) { // textures c->texture_2d_enabled = 0; c->current_texture = find_texture(c, 0); }