• Advertisement
Sign in to follow this  

Color picking, lire dans une surface

This topic is 3087 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

[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
Advertisement
You should only get that D3DERR_WASSTILLDRAWING error if you're using D3DPRESENT_DONOTWAIT.

I'd suggest not using D3DPRESENT_DONOTWAIT.

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
Doesn't seems to work, I still get the same error :(

Is that the good way to render to texture ?

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
I don't see anything obviously wrong there. Have you got up to date drivers for your graphics card?

Other things to try:

- Use D3DLOCK_READONLY when locking instead of 0.

- Use GetRenderTargetData() instead of Lock().

Share this post


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

  • Advertisement