Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3211570
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:44:51+00:00 2026-05-17T14:44:51+00:00

ok so i can load a mesh perfectly but loading its texture is not

  • 0

ok so i can load a mesh perfectly but loading its texture is not working. im not sure what im doing wrong.
here is my code..

//render a single frame
void RenderFrame(void)
{
    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
    d3ddev->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

    d3ddev->BeginScene();

    d3ddev->SetFVF(CUSTOMFVF);

    InitMatrices();

    D3DXMATRIX matTran;    // a matrix to store the rotation for each triangle
    D3DXMATRIX matRotz;
    D3DXMATRIX matRoty;
    D3DXMATRIX matRotx;
    D3DXMatrixTranslation(&matTran, x, y, z);   
    D3DXMatrixRotationZ(&matRotz, D3DXToRadian(rz));
    D3DXMatrixRotationY(&matRoty, D3DXToRadian(ry));
    D3DXMatrixRotationX(&matRotx, D3DXToRadian(rx));

    d3ddev->SetTransform(D3DTS_WORLD, &(matTran * matRotz * matRoty * matRotx));    // set the world transform

    // draw the spaceship
    for(DWORD i = 0; i < numMaterials; i++)    // loop through each subset
    {
        d3ddev->SetMaterial(&material[i]);    // set the material for the subset
        if(texture[i] != NULL)    // if the subset has a texture (if texture is not NULL)
            d3ddev->SetTexture(0, texture[i]);    // ...then set the texture

        meshSpaceship->DrawSubset(i);    // draw the subset
    }

    d3ddev->EndScene(); 

    d3ddev->Present(NULL, NULL, NULL, NULL);
}

// cleans up Direct3D and COM
void CleanD3D(void)
{
    meshSpaceship->Release();
    d3ddev->Release();    // close and release the 3D device
    d3d->Release();    // close and release Direct3D
}

VOID InitGraphic()
{
    LPD3DXBUFFER bufShipMaterial;

    D3DXLoadMeshFromX(L"ramiz.x",    // load this file
                      D3DXMESH_SYSTEMMEM,    // load the mesh into system memory
                      d3ddev,    // the Direct3D Device
                      NULL,    // we aren't using adjacency
                      &bufShipMaterial,    // put the materials here
                      NULL,    // we aren't using effect instances
                      &numMaterials,    // the number of materials in this model
                      &meshSpaceship);    // put the mesh here

    // retrieve the pointer to the buffer containing the material information
    D3DXMATERIAL* tempMaterials = (D3DXMATERIAL*)bufShipMaterial->GetBufferPointer();

    // create a new material buffer and texture for each material in the mesh
    material = new D3DMATERIAL9[numMaterials];
    texture = new LPDIRECT3DTEXTURE9[numMaterials];

    for(DWORD i = 0; i < numMaterials; i++)    // for each material...
    {
        material[i] = tempMaterials[i].MatD3D;    // get the material info
        material[i].Ambient = material[i].Diffuse;    // make ambient the same as diffuse
        D3DXCreateTextureFromFile(d3ddev,
                                    L"ramiz.x"
                                    ,
                                    &texture[i]);
        texture[i]=NULL;
     }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T14:44:51+00:00Added an answer on May 17, 2026 at 2:44 pm

    First of all, you’re setting all the textures to NULL in your for loop, so of course there’s no texture to render!

    for(DWORD i = 0; i < numMaterials; i++)
    { 
        /* ... */
        texture[i]=NULL; // <--- You're setting all your textures to NULL!
    } 
    

    Also:

    D3DXCreateTextureFromFile(d3ddev, L"ramiz.x", &texture[i]);  
    

    The function D3DXCreateTextureFromFile() only supports loading textures from these file types: .bmp, .dds, .dib, .hdr, .jpg, .pfm, .png, .ppm, and .tga. You’re attempting to load textures from an .x file, which can’t possibly be right.

    I think you meant to pass tempMaterials[i].pTextureFilename to D3DXCreateTextureFromFile() to load the texture files, no?

    Here’s how to properly load texture files for (simple) .x file rendering:

    //////////////////////////////////////////////////////////////////////////////
    // Code snippet from http://www.toymaker.info/Games/html/load_x_simply.html //
    //////////////////////////////////////////////////////////////////////////////
    
    for (DWORD i=0; i<m_numMaterials; i++)
    {
    
     // Copy the material
     meshMaterials[i] = d3dxMaterials[i].MatD3D;
    
     // Set the ambient color for the material (D3DX does not do this)
     meshMaterials[i].Ambient = meshMaterials[i].Diffuse;
    
     // Create the texture if it exists - it may not
     meshTextures[i] = NULL;
     if (d3dxMaterials[i].pTextureFilename)
         D3DXCreateTextureFromFile(gD3dDevice,
                                   d3dxMaterials[i].pTextureFilename,
                                   &meshTextures[i]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to dynamicaly compile code using CodeDom. I can load other assemblies,
How can one load custom (not an image, nor a sound file) resource file
I can load a list with the following code String[] projection = new String[]
I have a CSV of file of data that I can load in R
I have a little problem with a Listview. I can load it with listview
Can I load an stand alone aspx page in another stand alone aspx page
How can I load an external JavaScript file using a bookmarklet? This would overcome
When using PyWin I can easily load a python file into a fresh interactive
If I'm running a signed Java applet. Can I load additional classes from remote
How can I dynamically load a usercontrol in ASP.NET if I dont have access

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.