Archived

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

Zyroth

Secondary surfaces DC?

Recommended Posts

Is it posible to write a bitmap on a device context taken from the secondary surface. The code that I''ve seen, makes a memory DC, writes the bitmap onto it, then copies that DC to a DC taken from the secondary surface and then blits it to the primary surface. Can I just select the bitmap into the secondary surface''s DC or must I do it like above? BTW I''m learning this from the Game Programming Genisis articles.

Share this post


Link to post
Share on other sites
You have to create another DC to hold your image. Like this:


  
//Lets just assume g_pSecondary is a valid pointer to our secondary surface


HBITMAP hbm = (HBITMAP)LoadImage(NULL,"image.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);

BITMAP bmp;
GetObject(hbm,sizeof(bmp),&bmp);

HDC SurfaceDC;
HDC ImageDC = CreateCompatibleDC(NULL);

g_pSecondary->GetDC(&SurfaceDC);
SelectObject(ImageDC,hbm);
BitBlt(SurfaceDC,0,0,bmp.bmWidth,bmp.bmHeight,ImageDC,0,0,SRCCOPY);
g_pSecondary->ReleaseDC(SurfaceDC);

DeleteDC(&ImageDC);
DeleteObject(hbm);


The second device context is required for the BitBlt operation. You need two device contexts: one for the surface and one for the image itself. You select the handle to our bitmap into the ImageDC, and when you call BitBlt it acts as our source device context. Geddit?

Share this post


Link to post
Share on other sites