Jump to content
  • Advertisement
Sign in to follow this  

DrawSubset() causing mad crazy texture flickering

This topic is 3467 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

OK, so I have a little engine that can draw cubes and ramps using IDIRECT3DVERTEXBUFFER9's. The vertex format I'm using has XYZ and UV coordinates. Whenever I want to draw one of them, I just do:
              d3ddev->SetTexture(0, Tex_Cube1);
              d3ddev->SetStreamSource(0, Shape_cube, 0, sizeof(VERTEXUV));
              d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 12);
Free Image Hosting at www.ImageShack.us Works fine! Then I tried to render meshes... I tried both of these:
D3DXCreateSphere(d3ddev, 0.5f, 10,10, &Mesh_sphere1, NULL);
D3DXCreateTeapot(d3ddev, &Mesh_sphere1, NULL);
When when I try to render the mesh, all the textures flicker and go crazy. All I did was call Mesh_sphere1->DrawSubset(0); . Free Image Hosting at www.ImageShack.us What's going on?? Anybody have any ideas? Any help would be much, much, much appreciated :]

Share this post

Link to post
Share on other sites
Do you get any error messages from the debug runtimes?

If that doesn't help, please post some more code. If there's lots of it, surround it with [ source ] and [ /source ] tags (without the spaces).

Share this post

Link to post
Share on other sites
Here is my Direct3D initialization routine:

int Init_Direct3D(HWND hwnd, int width, int height, bool fullscreen)
//initialize Direct3D
d3d = Direct3DCreate9(D3D_SDK_VERSION);
if (d3d == NULL)
MessageBox(hwnd, L"Error initializing Direct3D", L"Error", MB_OK);
return 0;

//set Direct3D presentation parameters
d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &dm);
ZeroMemory(&d3dpp, sizeof(d3dpp));

d3dpp.Windowed = (!fullscreen);
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
d3dpp.BackBufferFormat = dm.Format;
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferWidth = width;
d3dpp.BackBufferHeight = height;
d3dpp.hDeviceWindow = hwnd;

//Only needed for dialog boxes

//create Direct3D device

if (d3ddev == NULL)
MessageBox(hwnd, L"Error creating Direct3D device", L"Error", MB_OK);
return 0;

//clear the backbuffer to black
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);

//create pointer to the back buffer
d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);

D3DXCreateSprite(d3ddev, &sprite_handler);

//turn dynamic lighting and z-buffering off
d3ddev->SetRenderState(D3DRS_LIGHTING, FALSE);
d3ddev->SetRenderState(D3DRS_ZENABLE, FALSE);

//set the Direct3D stream to use the custom vertex
d3ddev->SetFVF(D3DFVF_XYZ | D3DFVF_TEX1);

return 1;

Here's the game initialization:

int Game_Init(HWND hwnd)

//Position the camera: Camera position, camera lookat, and up direction
SetCameraUp(0,0,-5, 0,0,0, 0,1,0);
float ratio = (float)SCREEN_WIDTH / (float)SCREEN_HEIGHT;
SetPerspective(45.0f, ratio, 0.1f, 10000.0f); //Set up the projection matrix (may wish to tweak this)

//turn dynamic lighting off, z-buffering on
d3ddev->SetRenderState(D3DRS_LIGHTING, FALSE);
d3ddev->SetRenderState(D3DRS_ZENABLE, TRUE);

//set the Direct3D stream to use the custom VERTEXUV
d3ddev->SetFVF(D3DFVF_XYZ | D3DFVF_TEX1);

//Load resources.

//Set up the level.
CreateGrid(10, 10, 10);

//Timer functions
return 1;

LoadResources() leads to the code that creates my mesh, which I do like so:

D3DXCreateTeapot(d3ddev, &Mesh_sphere1, NULL);

Then, here's my draw routine:

if(d3ddev->BeginScene() == D3D_OK)
//Draw the level.

//Draw a sprite in the corner.

//Print the framerate.
char fps_string[256];
sprintf(fps_string, "FPS: %d", fps_framerate);
DrawFont(&Font1, sprite_handler, fps_string, 320, 10);




Inside of DrawPlayers(), here's the one line I've been using to draw the mesh.
I've also tried creating a material and setting d3ddev's material to that, but I see no difference.


Maybe that will be helpful. Thanks for the reply! Sorry, I am still somewhat of a beginner at this D3D Mesh-drawing stuff.

I will check on that debug runtime thing.

Share this post

Link to post
Share on other sites
OK, this is really bizarre.

I enabled the DirectX debug runtime thingy (by changing options in the DirectX control panel and switching to d3dx9d.lib, as was specified in the link you gave me.).

What happens now is drastically different than before... Basically, the framerate grinds to a halt, and all I get is this dark blue teapot in the corner. No cubes are displayed.

Free Image Hosting at www.ImageShack.us

This happens with both Debug and Release configurations --- which leads me to believe that it was the change to the Direct3D Control Panel that caused this change in my program's behavior.

I've worked out my code so that I can render the player as a cube. Basically, ALL of these problems are being caused by switching between these two drawing routines:

d3ddev->SetTexture(0, Tex_Player1);
d3ddev->SetStreamSource(0, Shape_cube, 0, sizeof(VERTEXUV));
d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 12);



The former code works perfectly --- runs at a steady 100fps and does exactly what it's supposed to, displaying all cubes as well as the player cube.

But when I comment out the former code and use the latter code, it just freaks out. The "debug" mode is not giving me any error messages... should it be?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!