Click to See Complete Forum and Search --> : DirectX Flickering Problem


Bljashinsky
June 13th, 2004, 10:18 PM
This is my first DirectX Program that I have made on my own without using a book but I am having some minor trouble. The cube with the teapot inside rotates whatever way you want using the arrow keys, is multi-colored, and is smooth shaded but keeps flickering. My guess is that I am not using the back buffer correctly or not putting things in order for the rendering pipeline. I have attached all of the code and my utility code. I believe the problem is in the render function. Thank you for any help you can provide and I was wondering if this is using DirectX in retained mode because I wasn't sure?


bool render(float timeDelta)
{
if( Device)
{
// spin the teapot
D3DXMATRIX Rx, Ry;

// rotate 45 degrees on x-axis
D3DXMatrixRotationX(&Rx, 3.14f / 4.0f);

// increment y-rotation value each frame
static float y = 0.0f;
D3DXMatrixRotationY(&Ry, y);
if ( userDecision == 1)
{
y += timeDelta;
}
else
{
y -= timeDelta;
}

// reset angle to zero when angle reaches 2*PI(Full circle turn was made)
if( y>= 6.28f )
{
y = 0.0f;
}

// combine rotations
D3DXMATRIX p = Rx + Ry;

Device->SetTransform(D3DTS_WORLD, &p);

// draw the scene:

// Clear back buffer to black color
Device->Clear(0,
0,
D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
0xffffffff,
1.0f,
0);


Device->BeginScene();
Device->SetFVF(ColorVertex::FVF);
Device->SetStreamSource(0, VB, 0, sizeof(ColorVertex));
Device->SetIndices(IB);

//set render to gouraud
Device->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD);

// draw cube
Device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,
0,
0,
8,
0,
12);

// Draw teapot using DrawSubset method with 0 as the argument.
Teapot->DrawSubset(0);

Device->EndScene();

// Swap the back and front buffers. This will display the back buffer on the screen.
Device->Present(0, 0, 0, 0);
}
return true;
}

Bljashinsky
June 13th, 2004, 10:23 PM
Here is the code I forgot to attach.

Bljashinsky
June 14th, 2004, 11:48 PM
Figured it out.

Tamerocyte
July 8th, 2004, 12:48 PM
what was it?

did you not handle the erase background message?

Bljashinsky
July 8th, 2004, 03:40 PM
The problem was with the coloring of the vertices and lighting.