VertexBuffer in DirectX not clearing? Advice?

This is a discussion on VertexBuffer in DirectX not clearing? Advice? within the Game Programming forums, part of the General Programming Boards category; http://iam.colum.edu/students/tyler....3denginev1.rar So...I'm using the graphic device's "Clear" method before I begin a scene, however I still get some strange results ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    58

    Exclamation VertexBuffer in DirectX not clearing? Advice?

    http://iam.colum.edu/students/tyler....3denginev1.rar


    So...I'm using the graphic device's "Clear" method before I begin a scene, however I still get some strange results when it draws to the screen. I would post the code snippets here...but there is too much.

    In the application class, I call the BeginScene, and EndScene functions, and also clear and present the scenes....

    In the Game1 class, I populate a "draw" method with a vertexbuffer class, and draw some basic primitives...


    The problem is that I cannot get the device to properly dispose of the previous primitive data. If you press the assigned controls to move the primitives, you will see that the "box" continues drawing its previous positions underneath the current position...even when you close the .exe and reopen it.

    The controls are as follows:
    - Up: Move up
    - Down: Move down
    - Left: Move left
    - Right: Move right
    - Shift-Up: Zoom in
    - Shift-Down: Zoom out



    Any ideas on what I need to do in order to prevent it from drawing this way?
    Last edited by arcaine01; 10-04-2009 at 11:44 PM. Reason: Including the d/l link

  2. #2
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    Show us what you are doing to clear the scene, the parameters you're using etc.

    It should be something similar to -
    Code:
    Device->Clear(0 , 0 , D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER , 0X00000000 , 1.0f , 0);
    Last edited by abachler; 10-05-2009 at 12:34 AM.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    58
    Code:
    Application::StartDraw(void)
    {
        GraphicDevice::GetService()->Device()->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, Colors::Red, 1.0f, 0);
        GraphicDevice::GetService()->BeginScene();
    }

  4. #4
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    Quote Originally Posted by arcaine01 View Post
    Code:
    Application::StartDraw(void)
    {
        GraphicDevice::GetService()->Device()->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, Colors::Red, 1.0f, 0);
        GraphicDevice::GetService()->Device()->BeginScene();
    }
    red text is my addition. I don't know for what purpose you are abstracting it that far out, but the BeginScene() has to take place through the Device object. I am assuming your GetService()->Device() call returns a pointer to the device object.
    Last edited by abachler; 10-05-2009 at 11:27 AM.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    pDevice->Clear(0,D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL,0,1.0f,0);

    I'm a little confused when you say it doesn't clear the vertex buffer b/c Clear() is not supposed to touch vertex buffers.

    Make sure your viewport is set to the correct one. If you set the viewport at some point you must set it back to the default. Before setting a viewport ensure you get the current one so you can set it back when you are done.

  6. #6
    Registered User
    Join Date
    Apr 2008
    Posts
    58

    Lightbulb

    You're right Bubba, I'm sorry for my poor choice of words. I meant to say its not clearing the window...not the vertex buffer :P

    I also found that if I construct the method like so:

    Code:
    HRESULT a = pDevice->Clear(0, 0, D3DCLEAR_TARGET, 0, 1.0f, 0);
    The function will return an "S_OK", and will clear properly for textures being drawn.

    However, the following code, when drawing the vertices OR the textures, will return -2005530516:

    Code:
    HRESULT a = pDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0, 1.0f, 0);


    It appears that for some reason, whenever I combine the flags, the method fails. Does anyone know of any possible reason for this?

  7. #7
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    Make sure you have a zbuffer specified in your D3DPRESENT_PARAMETERS. Auto depth stencil should be set to true and one of the following formats should be used. Some older cards did not use 1 bit stencil correctly so you may have to query the device. Under Direct3D 10 you do not have to query for device caps since it is required that all video card manuf. are 100% compatible.
    D3DFMT_D24S8
    D3DFMT_D16
    D3DFMT_D15S1

  8. #8
    Registered User
    Join Date
    Apr 2008
    Posts
    58

    Thumbs up

    Bubba, you are a life saver :P

    Thank you again for your help. All I did was change the format for the auto depth stencil to one of the formats you suggested, and it worked perfectly.

  9. #9
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    Glad you got it working. Remember if Direct3D is not drawing it is usually something to do with present parameters, render states, or incorrect transforms.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with my DirectX program
    By fighter92 in forum Game Programming
    Replies: 1
    Last Post: 01-23-2007, 06:28 PM
  2. Isometric Tile Engine using DirectX
    By Wraithan in forum Game Programming
    Replies: 3
    Last Post: 07-17-2006, 01:16 PM
  3. DirectSound header issues
    By dxfoo in forum C++ Programming
    Replies: 0
    Last Post: 03-19-2006, 07:16 PM
  4. DirectX - Starting Guide?
    By Zeusbwr in forum Game Programming
    Replies: 13
    Last Post: 11-25-2004, 12:49 AM
  5. DirectX: VertexBuffer with Length 0?
    By Epo in forum Game Programming
    Replies: 6
    Last Post: 12-28-2003, 06:39 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21