Sign in to follow this  
anders211

share pasting HBITMAP and IDirect3DDevice9::Present method

Recommended Posts

anders211    250

Hi

I have a problem that Present method overwrite HBITMAP paste method. Here is my code:

 

if(mRefreshWindow)
{
       //mRefreshWindow = false;
            static bool once = false; 
            if(!once) //(-)
{
                pDev->Clear(0, 0, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL, 0xff000000, 1, 0); //(=)
   once = true;
   hDCWin=GetDC(NULL);


                i32 width = GetDeviceCaps(hDCWin, HORZRES);
                i32 height = GetDeviceCaps(hDCWin, VERTRES);


                HDC helpDc;
                helpDc=CreateCompatibleDC(NULL); //gui->hDCWin
                SelectObject(helpDc,hBMP);
                BOOL status = BitBlt(hDCWin,0,0,width,height,helpDc,0,0,SRCCOPY);
                ReleaseDC(hWnd,hDCWin); //do not release hdc, keep it for future purposes
                DeleteDC(helpDc);
}
}


pDev->BeginScene();


if(!mRefreshWindow)
   dialMgr->onRender(timeDelta);


pDev->EndScene();
if(!mRefreshWindow) //(*)
   pDev->Present(0, 0, 0, 0); //present back buffer

With the above code I have pasted my image on the screen.

If I uncomment (*) then my window is the whole black.

If I in addition to (*) delete (-) and (=) my window is black and image is pasted and this is very quickly changed like there is some fighting between "black screen and my image".

Does anybody know how to paste the image on the screen and then use Present method so that there is on the screen my image and also objects drawn between Begin and EndScene.

Edited by anders211

Share this post


Link to post
Share on other sites
Buckeye    10747

Does anybody know how to paste the image on the screen and then use Present method so that there is on the screen my image and also objects drawn between Begin and EndScene.

What do you mean by "the image?" Does it have something to do with "hBmp?"

 

It would help, also, if you describe, in a general sense, if there's a problem you're trying to solve.

 

Also, the following line isn't correct. hDCWin is the DC for the desktop returned from GetDC(NULL), not a DC for hWnd. DC's should be released only by the window from which it was retrieved.
 

ReleaseDC(hWnd,hDCWin);


Also note that pDev->Clear is called only once, the first time that mRefreshWindow is true. After that initial call, you don't clear the backbuffer before drawing and, among other effects, the depth buffer is never reset.

Edited by Buckeye

Share this post


Link to post
Share on other sites
anders211    250

By image I mean HBITMAP. Probably it isn't possible to use BitBlt and Present method because they have nothing in common, one overwrrite another one. Probably I must convert HBITMAP to texture and then render this texture with directx method and I cannot use BitBlt. However I don't know it is is true but based on my today experience I suppose it might be the true.

Share this post


Link to post
Share on other sites
Aardvajk    13207

By image I mean HBITMAP. Probably it isn't possible to use BitBlt and Present method because they have nothing in common, one overwrrite another one. Probably I must convert HBITMAP to texture and then render this texture with directx method and I cannot use BitBlt. However I don't know it is is true but based on my today experience I suppose it might be the true.

 

D3DXCreateTextureFromFile will open most image formats as a texture. It may be possible to use GDI to somehow draw an image to the backbuffer but it will be far more efficient to have it loaded as a texture and render it with a full-screen quad.

 

Just bear in mind a lot of hardware only supports textures with power-of-2 dimensions so unless your image happens to be that, D3DXCreateTextureFromFile will create an image of the wrong size for you. You may need to calculate the texture-co-ordinates yourself based on the difference between the image size and the size of the texture the method returns.

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