Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » d3d textures

This thread is locked; no one can reply to it. rss feed Print
d3d textures
shadyvillian
Member #12,426
December 2010

What should I use to load textures? I've been loading a texture with this:

#SelectExpand
1 D3DXMATERIAL* D3dxMaterials = (D3DXMATERIAL*)D3dMatBuf->GetBufferPointer(); 2 MeshMaterial = new D3DMATERIAL9[NumMaterials]; 3 MeshTextures = new LPDIRECT3DTEXTURE9[NumMaterials]; 4 5 MeshMaterial[0] = D3dxMaterials[0].MatD3D; 6 MeshMaterial[0].Ambient = MeshMaterial[0].Diffuse; 7 MeshTextures[0] = NULL; 8 9 if((D3dxMaterials[0].pTextureFilename != NULL) && (lstrlenA( D3dxMaterials[0].pTextureFilename) > 0)) 10 { 11 D3DXCreateTextureFromFile(D3dDevice, D3dxMaterials[0].pTextureFilename, &MeshTextures[0]); 12 13 if(MeshTextures[0] == NULL) 14 { 15 al_show_native_message_box(Screen, "Error", NULL, "failed to load texture", NULL, ALLEGRO_MESSAGEBOX_ERROR); 16 } 17 }

Will al_get_d3d_system_texture accomplish the same thing? I'm still learning how everything works and I noticed allegro had a texture loading function.

Software Engineer by day, hacker by night.

Trent Gamblin
Member #261
April 2000
avatar

Allegro will load textures for you. It has to create 2 different textures:

The system texture is like a backup. It's kept in system memory, not on the gpu. It's never drawn, only copied to. When the video texture changes, the system texture is made up to date with it.

The video texture is what you draw and draw to. It's kept in memory on the gpu. GPU memory can be "lost" (a really annoying DirectX "feature") in which case the video texture has to be refreshed from the system texture.

I think what you want is al_get_d3d_video_texture, but it's hard to tell what you plan on doing with it.

shadyvillian
Member #12,426
December 2010

I'm trying to apply the texture to this model.

void Render()
    {
        D3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

        for(int i = 0; i < (int)Tiger.NumMaterials; i++)
        {
            D3dDevice->SetMaterial(&Tiger.MeshMaterials[i]);
            D3dDevice->SetTexture(0, Tiger.MeshTextures[i]);

            Tiger.Mesh->DrawSubset(i);
        }

        al_flip_display();
    }

#SelectExpand
1int LoadMedia() 2 { 3 LPD3DXBUFFER D3dMatBuf; 4 5 D3DXLoadMeshFromX("tiger.x", D3DXMESH_SYSTEMMEM, D3dDevice, NULL, &D3dMatBuf, NULL, &Tiger.NumMaterials, &Tiger.Mesh); 6 if(Tiger.Mesh == NULL) 7 { 8 al_show_native_message_box(Screen, "Error", NULL, "failed to load tiger.x", NULL, ALLEGRO_MESSAGEBOX_ERROR); 9 Cleanup(); 10 return -1; 11 } 12 13 D3DXMATERIAL* D3dxMaterials = (D3DXMATERIAL*)D3dMatBuf->GetBufferPointer(); 14 Tiger.MeshMaterials = new D3DMATERIAL9[Tiger.NumMaterials]; 15 Tiger.MeshTextures = new LPDIRECT3DTEXTURE9[Tiger.NumMaterials]; 16 17 for( int i = 0; i < (int)Tiger.NumMaterials; i++ ) 18 { 19 20 Tiger.MeshMaterials[i] = D3dxMaterials[i].MatD3D; 21 22 23 Tiger.MeshMaterials[i].Ambient = Tiger.MeshMaterials[i].Diffuse; 24 25 Tiger.MeshTextures[i] = NULL; 26 if(D3dxMaterials[i].pTextureFilename != NULL && lstrlenA(D3dxMaterials[i].pTextureFilename ) > 0 ) 27 { 28 29 D3DXCreateTextureFromFileA(D3dDevice, D3dxMaterials[i].pTextureFilename, &Tiger.MeshTextures[i]); 30 31 if(Tiger.MeshTextures[i] == NULL) 32 { 33 al_show_native_message_box(Screen, "Error", NULL, "failed to load texture", NULL, ALLEGRO_MESSAGEBOX_ERROR); 34 Cleanup(); 35 return -1; 36 } 37 } 38 } 39 40 D3dMatBuf->Release(); 41 42 return 0; 43 }

#SelectExpand
1class Model 2{ 3 public: 4 5 float x; 6 float y; 7 float z; 8 9 LPD3DXMESH Mesh; 10 D3DMATERIAL9* MeshMaterials; 11 LPDIRECT3DTEXTURE9* MeshTextures; 12 13 DWORD NumMaterials; 14 15 Model(): 16 x(0.0), y(0.0), z(0.0), 17 Mesh(NULL), MeshMaterials(NULL), MeshTextures(NULL), 18 NumMaterials(0L) 19 {} 20}; 21 22Model Tiger;

I dont think its working right the model doesnt look right. Does the al_get_d3d_video_texture function do the mat3d3 and ambient stuff?

Software Engineer by day, hacker by night.

Trent Gamblin
Member #261
April 2000
avatar

No, it just gives you a texture, it has no knowledge mof materials or anything. If you're trying to texture something then you want the video texture not the system texture.

shadyvillian
Member #12,426
December 2010

So like this?

#SelectExpand
1int LoadMedia() 2 { 3 LPD3DXBUFFER D3dMatBuf; 4 5 D3DXLoadMeshFromX("tiger.x", D3DXMESH_SYSTEMMEM, D3dDevice, NULL, &D3dMatBuf, NULL, &Tiger.NumMaterials, &Tiger.Mesh); 6 if(Tiger.Mesh == NULL) 7 { 8 al_show_native_message_box(Screen, "Error", NULL, "failed to load tiger.x", NULL, ALLEGRO_MESSAGEBOX_ERROR); 9 Cleanup(); 10 return -1; 11 } 12 13 D3DXMATERIAL* D3dxMaterials = (D3DXMATERIAL*)D3dMatBuf->GetBufferPointer(); 14 Tiger.MeshMaterials = new D3DMATERIAL9[Tiger.NumMaterials]; 15 Tiger.MeshTextures = new LPDIRECT3DTEXTURE9[Tiger.NumMaterials]; 16 Tiger.Texture = al_load_bitmap("tiger.bmp"); 17 18 for( int i = 0; i < (int)Tiger.NumMaterials; i++ ) 19 { 20 21 Tiger.MeshMaterials[i] = D3dxMaterials[i].MatD3D; 22 23 Tiger.MeshMaterials[i].Ambient = Tiger.MeshMaterials[i].Diffuse; 24 25 Tiger.MeshTextures[i] = NULL; 26 27 if(Tiger.Texture == NULL) 28 { 29 al_show_native_message_box(Screen, "Error", NULL, "failed to load texture", NULL, ALLEGRO_MESSAGEBOX_ERROR); 30 Cleanup(); 31 return -1; 32 } 33 34 Tiger.MeshTextures[i] = al_get_d3d_video_texture(Tiger.Texture); 35 } 36 37 D3dMatBuf->Release(); 38 39 return 0; 40 }

Its still not showing up. Is there something else I have to do? I used the tutorial from msdn and their code was very similar and the texture showed up.

Software Engineer by day, hacker by night.

Trent Gamblin
Member #261
April 2000
avatar

I have no clue how to use all of that d3dx stuff. The only guess I can make is somethings wrong with your light source.

Go to: