Archived

This topic is now archived and is closed to further replies.

ji yan

Someone Please help!!!!!!!!!

Recommended Posts

I am having a weird problem that makes me think the CD3DApplication class was not written right. When I run the program it shows a window but the window changes its color form red to green and then from green to red in a very short period with obvious flickering.Can anyone tell me why that happen? //Here is my code // MyD3DPro.cpp : Defines the entry point for the application. // #include "stdafx.h" #include "d3dapp.h" int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // TODO: Place code here. CD3DApplication d3dApp; if(FAILED(d3dApp.Create(hInstance) )) return 0; return d3dApp.Run(); }

Share this post


Link to post
Share on other sites
Usually, you''ll see that happen when you are telling the device that your vertices are in one format and they are actually in another. There might be other reasons, but the general idea is that the device is expecting one thing and you''re giving it another.

Share this post


Link to post
Share on other sites
but how can that be the case when I am directly using microsoft code. does that proof the microsoft code is wrong

Share this post


Link to post
Share on other sites
just inherit from CD3DApplication
and override the Render() function

class MyApp : public CD3DApplication
{
virtual HRESULT Render();
}

HRESULT MyApp::Render()
{

m_pd3dDevice->Clear( 0L, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0L );

if(FAILED(m_pd3dDevice->BeginScene()))
return S_FALSE;

//your rendering stuff

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

return S_OK;
}

you should see a black screen then ....

hope this helps

[edited by - chrisodin on March 22, 2002 12:36:00 PM]

Share this post


Link to post
Share on other sites
My guess is that the front and back buffers are never cleared. The default Render function in CD3DApplication does nothing more than return S_OK so the front/back buffers are just being flipped back and forth. You need to use CD3DApplication as a base class and overload the Render function.

In YOUR Render() you should call:

m_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, 0x00000000, 1.0f, 0 );

if( SUCCEEDED(m_pd3dDevice->BeginScene()) )
{
// render stuff here
m_pd3dDevice->EndScene();
}

Share this post


Link to post
Share on other sites
uhm i had the same problem....
when i started one project with debug version of DX8.1
then used the retail and it worked perfectly

or try to lower the fps with

Sleep(20);

Share this post


Link to post
Share on other sites
I am sorry that I am a little confused about backbuffer stuff in d3d. I remember that I have never created a backbuffer. How can I know which is backbuffer and which is front screen? is m_pd3dDevice in my example a backbuffer or front screen?

Share this post


Link to post
Share on other sites
The backbuffer is created automatically for you. d3ddevice is a rendering device, not a backbuffer. You don''t need to access backbuffer directly, besides it''s very slow.

Backbuffer is like a screen that is not displayed. While the user stares at your current frame, you are drawing to the invisible backbuffer. Then you flip your buffers, making the backbuffer the frontbuffer that the user sees.

Flipping can be done during vertical retrace period and is very fast. In contrast, drawing your scene is rather slow. This is the reason for having a backbuffer.

Share this post


Link to post
Share on other sites