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 982983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:47:02+00:00 2026-05-16T04:47:02+00:00

#include <windows.h> #include <d3d9.h> #include <D3DX9Mesh.h> #define THROW_ERROR_AND_EXIT(x) { \ MessageBox(0,x,0,0); \ return -1;

  • 0
#include <windows.h>
#include <d3d9.h>
#include <D3DX9Mesh.h>

#define THROW_ERROR_AND_EXIT(x) { \
    MessageBox(0,x,0,0); \
    return -1; \
    }

LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
    // Handle close event
    switch( msg )
    {
    case WM_DESTROY:
        PostQuitMessage( 0 );
        return 0;
    }
    return DefWindowProc( hWnd, msg, wParam, lParam );
}

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    // Registering class
    WNDCLASSEX wcex;

    wcex.cbSize = sizeof(WNDCLASSEX); 
    wcex.style= CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc= (WNDPROC)WndProc;
    wcex.cbClsExtra= 0;
    wcex.cbWndExtra= 0;
    wcex.hInstance= hInstance;
    wcex.hIcon= 0;
    wcex.hCursor= LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground= (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName= 0;
    wcex.lpszClassName= "MyMeshViewer";
    wcex.hIconSm= 0;

    RegisterClassEx(&wcex);

    // Creating Window
    HWND hWnd = CreateWindow("MyMeshViewer", "MyMeshViewer", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);

    // Creating Direct3D object
    LPDIRECT3D9 d3dObject=NULL;
    LPDIRECT3DDEVICE9 d3dDevice=NULL;

    d3dObject=Direct3DCreate9(D3D_SDK_VERSION);

    // Creating Direct3D device
    if(NULL == d3dObject)
        THROW_ERROR_AND_EXIT("NULL == d3dObject");
    D3DPRESENT_PARAMETERS presParams;
    ZeroMemory(&presParams,sizeof(presParams));
    presParams.Windowed=TRUE;
    presParams.SwapEffect=D3DSWAPEFFECT_DISCARD;
    presParams.BackBufferFormat=D3DFMT_UNKNOWN;
    presParams.PresentationInterval=D3DPRESENT_INTERVAL_ONE;
    HRESULT hr=d3dObject->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &presParams, &d3dDevice);
    if(FAILED(hr))
        THROW_ERROR_AND_EXIT("d3dObject->CreateDevice");

    // Rendering
    d3dDevice->Clear(0,NULL,D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,255,0),1.0f,0);
    d3dDevice->BeginScene();

    // Loading the mesh
    LPD3DXBUFFER materialBuffer = NULL;
    DWORD numMaterials = 0;
    LPD3DXMESH mesh = NULL;
    hr=D3DXLoadMeshFromX("tiger.x", D3DXMESH_SYSTEMMEM, 
        d3dDevice, NULL, 
        &materialBuffer,NULL, &numMaterials, 
        &mesh );
    if(FAILED(hr))
        THROW_ERROR_AND_EXIT("hr=D3DXLoadMeshFromX");

    // Loading the material buffer
    D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)materialBuffer->GetBufferPointer();
    // Holding material and texture pointers
    D3DMATERIAL9 *meshMaterials = new D3DMATERIAL9[numMaterials];
    LPDIRECT3DTEXTURE9 *meshTextures  = new LPDIRECT3DTEXTURE9[numMaterials];   
    // Filling material and texture arrays
    for (DWORD i=0; i<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(d3dDevice, d3dxMaterials[i].pTextureFilename,     &meshTextures[i]);
    }

    materialBuffer->Release();

    for (DWORD i=0; i<numMaterials; i++)
    {
        // Set the material and texture for this subset
        d3dDevice->SetMaterial(&meshMaterials[i]);
        d3dDevice->SetTexture(0,meshTextures[i]);
        // Draw the mesh subset
        mesh->DrawSubset( i );
    }

    d3dDevice->EndScene();
    d3dDevice->Present(NULL, NULL, NULL, NULL);    

    // Show Window
    ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd);

    // Handle messages
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0)) 
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }    

    return (int)msg.wParam;
}

This is my program to load a mesh tiger.x and display it. But it is not getting displayed. The value of the variable numMaterials remains 1 all the time. I guess there is some issue with my program. Someone please help me to figure it out. Thanks.


The tiger.x mesh file below

http://pastebin.com/DuvpS4mh

  • 1 1 Answer
  • 1 View
  • 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-16T04:47:02+00:00Added an answer on May 16, 2026 at 4:47 am

    The problem is that you are rendering to the window and then calling UpdateWindow which forces a re-paint, thus erasing the drawing.

    I suggest you download the DirectX SDK and look at the samples to see how to build a ‘correct’ rendering loop.

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

Sidebar

Related Questions

Here is my code: #include <stdio.h> #include <string.h> #include <windows.h> #include <tchar.h> #define MAX_KEY_LENGTH
#include <OgreRoot.h> #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 #define WIN32_LEAN_AND_MEAN #include windows.h #endif #ifdef __cplusplus extern
#include <algorithm> #include <Windows.h> int main() { int k = std::min(3, 4); return 0;
I just needed to include windows office 2010 Ribbon bar into my C# application(Not
.386 .model flat, stdcall option casemap:none include windows.inc include kernel32.inc include user32.inc includelib user32.lib
I'm looking to include a Windows .exe in my gem and call on that
windows.h is included, code: #include <windows.h> int main() { HANDLE hToken; DWORD dwSize; TOKEN_ELEVATION_TYPE
My sytem: Windows, Python 2.7 I downloaded a package and want to include it
#include <iostream> #include <cassert> #include <vector> #include <ctime> #include <cstdlib> #include <Windows.h> using namespace
suppose you have the following structure: #include <windows.h> // BOOL is here. #include <stdio.h>

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.