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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:31:42+00:00 2026-06-13T16:31:42+00:00

I have a DirectX10 + C++ problem. Basically we’re at the early stages of

  • 0

I have a DirectX10 + C++ problem.

Basically we’re at the early stages of rendering, and for some reason our depth stencil seems to be failing to understand our model. Basically, here is everything we are doing:

  1. Load shader, model and texture
  2. Initialize DirectX
  3. Draw

The model, shader and texture all load and work correctly, however (as shown in the screenshot below), the depth stencil is clearly not doing its job and the shader is being used in the wrong places. I have also included our initialization method in case you need it to figure it out. We believe we have tried almost everything but knowing our luck we have probably missed out 1 line of important code ^.^

We also saw that someone else had the same problem, however their fix didn’t work (their problem was that they had set the near clipping plane to 0.0, however ours is not 0.0 so that is not the problem)

Thanks in advance!

Problem screenshot

void GraphicsDeviceDirectX::InitGraphicsDevice(HWND hWnd)
{
    DXGI_SWAP_CHAIN_DESC scd;    // create a struct to hold various swap chain information

    ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC));    // clear out the struct for use

    scd.BufferCount = 2;    // create two buffers, one for the front, one for the back
    scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;    // use 32-bit color
    scd.BufferDesc.Height = 600;
    scd.BufferDesc.Width = 600;
    scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;    // tell how the chain is to be used
    scd.OutputWindow = hWnd;    // set the window to be used by Direct3D
    scd.SampleDesc.Count = 1;    // set the level of multi-sampling
    scd.SampleDesc.Quality = 0;    // set the quality of multi-sampling
    scd.Windowed = true;    // set to windowed or full-screen mode

    //set scan line ordering and scaling
    scd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
    scd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;

    //discard back buffer dontents
    scd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;

    //dont set advanced flags
    scd.Flags = 0;

    // create a device class and swap chain class using the information in the scd struct
    if(FAILED(D3D10CreateDeviceAndSwapChain(NULL,
                                  D3D10_DRIVER_TYPE_HARDWARE,
                                  NULL,
                                  D3D10_CREATE_DEVICE_DEBUG,
                                  D3D10_SDK_VERSION,
                                  &scd,
                                  &swapchain,
                                  &device)))
    {
        throw EngineException("Error creating graphics device");
    }

    //Push graphics device to Persistant Object Manager
    //PerObjMan::Push(device);
    //Push swapchain to Peristant Object Manager
    PerObjMan::Push(swapchain);

    // get the address of the back buffer and use it to create the render target
    ID3D10Texture2D* pBackBuffer;
    swapchain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&pBackBuffer);
    device->CreateRenderTargetView(pBackBuffer, NULL, &rtv);

    /*D3D10_TEXTURE2D_DESC descBack;
    pBackBuffer->GetDesc(&descBack);*/
    pBackBuffer->Release();
    pBackBuffer = NULL;

    //Push graphics device to Persistant Object Manager
    PerObjMan::Push(rtv);

    ID3D10Texture2D* pDepthStencil = NULL;
    D3D10_TEXTURE2D_DESC descDepth;

    ZeroMemory(&descDepth, sizeof(descDepth));

    descDepth.Width = 600;
    descDepth.Height = 600;
    descDepth.MipLevels = 1;
    descDepth.ArraySize = 1;
    descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
    descDepth.SampleDesc.Count = 1;
    descDepth.SampleDesc.Quality = 0;
    descDepth.Usage = D3D10_USAGE_DEFAULT;
    descDepth.BindFlags = D3D10_BIND_DEPTH_STENCIL;
    descDepth.CPUAccessFlags = 0;
    descDepth.MiscFlags = 0;
    HRESULT hr;
    hr = GetGraphicsDevice()->CreateTexture2D( &descDepth, NULL, &pDepthStencil );
    if(FAILED(hr))
        throw EngineException("FAIL");

    PerObjMan::Push(pDepthStencil);

    D3D10_DEPTH_STENCIL_DESC dsDesc;

    ZeroMemory(&dsDesc, sizeof(dsDesc));
    // Depth test parameters
    dsDesc.DepthEnable = true;
    dsDesc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK::D3D10_DEPTH_WRITE_MASK_ALL;
    dsDesc.DepthFunc = D3D10_COMPARISON_FUNC::D3D10_COMPARISON_LESS;

    // Stencil test parameters
    dsDesc.StencilEnable = false;
    dsDesc.StencilReadMask = 0xFF;
    dsDesc.StencilWriteMask = 0xFF;

    // Stencil operations if pixel is front-facing.
    dsDesc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
    dsDesc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_INCR;
    dsDesc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
    dsDesc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;

    // Stencil operations if pixel is back-facing.
    dsDesc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
    dsDesc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_DECR;
    dsDesc.BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
    dsDesc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;      

    // Create depth stencil state
    hr = device->CreateDepthStencilState(&dsDesc, &dss);
    if(FAILED(hr))
        throw EngineException("FAIL");

    // Bind depth stencil state
    device->OMSetDepthStencilState(dss, 1);


    PerObjMan::Push(dss);

    D3D10_DEPTH_STENCIL_VIEW_DESC descDSV;

    ZeroMemory(&descDSV, sizeof(descDSV));

    descDSV.Format = descDepth.Format;
    descDSV.ViewDimension = D3D10_DSV_DIMENSION::D3D10_DSV_DIMENSION_TEXTURE2D;
    descDSV.Texture2D.MipSlice = 0;

    // Create the depth stencil view
    hr = device->CreateDepthStencilView( pDepthStencil, // Depth stencil texture
                                         &descDSV, // Depth stencil desc
                                         &dsv );  // [out] Depth stencil view

    if(FAILED(hr))
        throw EngineException("FAIL");

    PerObjMan::Push(dsv);

    // Bind the depth stencil view
    device->OMSetRenderTargets( 1,          // One rendertarget view
                                &rtv,      // Render target view, created earlier
                                dsv);     // Depth stencil view for the render target


    D3D10_VIEWPORT viewport;    // create a struct to hold the viewport data

    ZeroMemory(&viewport, sizeof(D3D10_VIEWPORT));    // clear out the struct for use

    GameToImplement::GameInfo::Info info = GameToImplement::GameInfo::GetGameInfo();

    RECT rect;
    int width = 0;
    int height = 0;
    if(GetClientRect(hWnd, &rect))
    {
        width = rect.right - rect.left;
        height = rect.bottom - rect.top;
    }
    else
    {
        throw EngineException("");
    }

    viewport.TopLeftX = 0;    // set the left to 0
    viewport.TopLeftY = 0;    // set the top to 0
    viewport.Width = 600;    // set the width to the window's width
    viewport.Height = 600;    // set the height to the window's height
    viewport.MinDepth = 0.0f;
    viewport.MaxDepth = 1.0f;

    device->RSSetViewports(1, &viewport);    // set the viewport

}
  • 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-13T16:31:43+00:00Added an answer on June 13, 2026 at 4:31 pm

    I fixed it, thanks to catflier’s nod in the right direction. Turns out I was actually releasing the rasterizer state too early for the depth stencil to be used.

    I’ll leave this answer here for anyone who has the same problem.

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

Sidebar

Related Questions

I am working with directX 9. I have a problem while rendering triangles using
I have a problem just with rendering a simple rotating cube with SlimDX (DirectX
I have a problem with directx 11 rendering - if i try to render
I am developing the application that uses DirectX for graphics rendering. I have to
I am trying to learn some DirectX API and, for now, I have just
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
I have the following problem in application architecture and am willing to solve it
I have a problem where Device.Dispose() is taking a long time to execute when
I have done some looking and I can't figure out a good way to
I have a c#/winforms application that uses directx to play some video and audio.

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.