Sign in to follow this  
BerMan

Color picking, lire dans une surface

Recommended Posts

[VF] Bonjour, Mon premier message sur ce forum, c'est un grand moment ! Mon application est réalisée en C++ sous DirectX9. Je compte faire dans mon application un picking par couleur car j'ai l'impression que c'est le meilleur moyen d'en avoir un qui soit optimisé dans le cas d'un test continue, non juste lors d'un clic. De ce que j'en ai compris, il faut rendre la scène avec seulement la couleur propre à chaque objet puis lire la couleur sous le curseur, et c'est cette dernière étape qui coince. J'ai beau rendre dans une IDirect3DSurface9 (et afficher le rendu final avec StretchRect, ce qui m'indique donc que la surface est remplie correctement) je ne sais pas comment accéder à une couleur dans cette surface !
	D3DLOCKED_RECT rect;
	HRESULT res = m_pBackBuffer->LockRect(&rect, NULL, D3DLOCK_READONLY );
me retourne le code d'erreur : D3DERR_WASSTILLDRAWING Des indices ? Merci d'avance [English] Hi ! My first thread on this forum :) I'm working on DirectX9 with C++. I want to implement a color picking (seems to be the most optimized for pick during the idle) Here is what I understood. I have to draw my scene with only objct own colors and get the color under the cursor, but that last step failed. I use a IDirect3DSurface9 and then i draw it on a quad, no problem there. But when I try to read into this surface, i get the error D3DERR_WASSTILLDRAWING
	D3DLOCKED_RECT rect;
	HRESULT res = m_pBackBuffer->LockRect(&rect, NULL, D3DLOCK_READONLY );
Thanks for advice ! Edit : Ajout de la traduction pour nos amis anglophones [Edited by - BerMan on September 9, 2009 4:41:58 AM]

Share this post


Link to post
Share on other sites
D3DPRESENT_DONOTWAIT is used when the Present function is called isn't it?

I call this one with params (NULL, NULL, NULL, NULL), I guess it's the third I have to change. Am I right ?

HRESULT Present(
CONST RECT * pSourceRect,
CONST RECT * pDestRect,
==> HWND hDestWindowOverride, <==
CONST RGNDATA * pDirtyRegion
);

Share this post


Link to post
Share on other sites
When you call CreateDevice() one of the parameters is a D3DPRESENT_PARAMETERS.

You want to make sure the PresentationInterval in that structure isn't set to D3DPRESENT_DONOTWAIT.

Your code should look something like:

D3DPRESENT_PARAMETERS pp;
memset(&pp, 0, sizeof(pp));
pp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
// Set up other settings ...
pD3D->CreateDevice(..., &pp, &pDevice);



http://msdn.microsoft.com/en-us/library/bb172588%28VS.85%29.aspx

http://msdn.microsoft.com/en-us/library/bb172585%28VS.85%29.aspx

Share this post


Link to post
Share on other sites
Here is my code :



// Création du device
hr = m_pD3D->CreateDevice( m_d3dSettings.AdapterOrdinal(), pDeviceInfo->DevType,
m_hWndFocus, behaviorFlags, &m_d3dpp,
&m_pd3dDevice );

//with m_d3dpp.PresentationInterval == D3DPRESENT_INTERVAL_DEFAULT

...

m_pd3dDevice->SetRenderTarget(0, PostRenderer::GetInstance()->GetSceneRenderSurface());
...//Clear, shader etc
m_pd3dDevice->BeginScene();
...//render stuff
m_pd3dDevice->EndScene();


D3DLOCKED_RECT rect;
HRESULT res = PostRenderer::GetInstance()->GetSceneRenderSurface()->LockRect(&rect, NULL, 0 );



and then, res == D3DERR_WASSTILLDRAWING and my rect is empty.
I hope it's clearer now.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this