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

  • Home
  • SEARCH
  • 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 8720823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:07:11+00:00 2026-06-13T07:07:11+00:00

I have custom model file format that I am reading from to create a

  • 0

I have custom model file format that I am reading from to create a model in DX. I use

DWORD dwFVF = ( D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1 );
D3DXCreateMeshFVF(numIndices/3, numVertices, D3DXMESH_MANAGED, dwFVF, *d3ddev, mesh);

to create the mesh, then lock, fill, unlock the index buffer, vertex buffer, and attribute buffer in turn.

void createMeshFromSkn(ifstream* fHandle, LPDIRECT3DDEVICE9 * d3ddev, LPD3DXMESH * mesh)
{
        // Start reading the file
        int magic = readInt(fHandle);
        short version = readShort(fHandle);
        short numObjects = readShort(fHandle);

        SKNMaterial *materialHeaders;

        if (version > 0)
        {
                // Read in the material headers
                int numMaterialHeaders = readInt(fHandle);
                fHandle->seekg((16 + MATERIAL_NAME_SIZE) * numMaterialHeaders, ios::cur);

                // Read in model data.
                int numIndices = readInt(fHandle);
                int numVertices = readInt(fHandle);

                // Create the mesh
                DWORD dwFVF = ( D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1 );
                D3DXCreateMeshFVF(numIndices/3, numVertices, D3DXMESH_MANAGED, dwFVF, *d3ddev, mesh);

                // Read in the index buffer
                WORD* indexBuffer = 0;
                (*mesh)->LockIndexBuffer(0, (void**)&indexBuffer);

                for (int i = 0; i < numIndices; i++)
                {
                        indexBuffer[i] = readShort(fHandle);
                }

                (*mesh)->UnlockIndexBuffer();

                // Read in the vertexBuffer
                D3DVERTEX* vertexBuffer;
                (*mesh)->LockVertexBuffer( 0, (void**)&vertexBuffer);

                for (int i = 0; i < numVertices; ++i)
                {
                        ((D3DVERTEX*)vertexBuffer)[i].position.x = readFloat(fHandle);
                        ((D3DVERTEX*)vertexBuffer)[i].position.y = readFloat(fHandle);
                        ((D3DVERTEX*)vertexBuffer)[i].position.z = readFloat(fHandle);


                        for (unsigned int j = 0; j < BONE_INDEX_SIZE; ++j)
                        {
                                int bone = (int) readByte(fHandle);
                                //data->vertices[i].boneIndex[j] = bone;
                        }

                        //////////////////////////////////////////////////////////////////////////
                        //
                        // Need to fix this to work with bones
                        //
                        //////////////////////////////////////////////////////////////////////////
                        D3DXVECTOR4 weight;

                        weight.x = readFloat(fHandle);
                        weight.y = readFloat(fHandle);
                        weight.z = readFloat(fHandle);
                        weight.w = readFloat(fHandle);

                        ((D3DVERTEX*)vertexBuffer)[i].normal.x = readFloat(fHandle);
                        ((D3DVERTEX*)vertexBuffer)[i].normal.y = readFloat(fHandle);
                        ((D3DVERTEX*)vertexBuffer)[i].normal.z = readFloat(fHandle);

                        ((D3DVERTEX*)vertexBuffer)[i].tu = readFloat(fHandle);
                        ((D3DVERTEX*)vertexBuffer)[i].tv = readFloat(fHandle);
                }

                (*mesh)->UnlockVertexBuffer();

                DWORD *pAttribBuf;
                HRESULT hRslt = (*mesh)->LockAttributeBuffer(0, &pAttribBuf);
                if(hRslt != D3D_OK)
                        return; // Add error handling

                unsigned int numFaces = (*mesh)->GetNumFaces();
                for(unsigned int i=0; i<numFaces; i++)
                        pAttribBuf[i]= 0;

                hRslt = (*mesh)->UnlockAttributeBuffer();
                if(hRslt != D3D_OK)
                        return; // Add error handling

                DWORD *m_pAdjacencyBuffer;
                m_pAdjacencyBuffer = new DWORD[3 * (*mesh)->GetNumFaces()];
                (*mesh)->GenerateAdjacency(0.0f, m_pAdjacencyBuffer);

                (*mesh)->OptimizeInplace(D3DXMESHOPT_ATTRSORT | D3DXMESHOPT_VERTEXCACHE, m_pAdjacencyBuffer, NULL, NULL, NULL);

        }

        return;
}

My problem is that the model is overlapping with itself:

http://imageshack.us/a/img210/2732/20121018181019896.png

I have CCW backface culling enabled:

d3ddev->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);

I also have z-buffer enabled, but I’m pretty sure that’s only between two meshes, not between a mesh and itself.

I’ve spent the last day and a half trying to Google for a solution, but I couldn’t find anything. Any help or links to help would be greatly appreciated.

  • 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-06-13T07:07:12+00:00Added an answer on June 13, 2026 at 7:07 am

    It turns out I hadn’t actually turned on Z-buffering, because I needed to turn it on in the d3d presentation parameters:

    d3dpp.EnableAutoDepthStencil = TRUE;
    d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
    

    Once I did that and added a

    d3ddev->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
    

    to the render loop, it renders correctly.

    Wow, so glad I figured this out. I hope this helps others in their explorations of DX

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom model binder which pulls an implementation of an interface from
In my application I have a custom model binder that I set to the
I have a model class that uses a custom validator as shown in following
I have a Model that contains a List of a custom type. I want
I have a model with a property that points to a file that contains
I have a file that defines a 3D model's vertexes, normals, and connectivity information.
I have a TODO file that I load emacs up to use 90% of
I have written a custom Django Model Field to store dateutil.relativedelta 's. The field
This is my custom model binder. I have my breakpoint set at BindModel but
We have a custom LocalizedString type used in our domain model. We want to

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.