![gdi directdraw gdi directdraw](https://www.codeproject.com/KB/directx/SpaceWarrior/SpaceWarriorScreenshot.png)
The actual DDB-to-DIB conversion will be handled entirely by GetDIBits. For obvious reasons, de-selecting an object by passing NULL would not work because NULL gives no information whether the pen, the font, or the bitmap should be de-selected.īitBlt(OffscrDC, 0, 0, Width, Height, SurfDC, 0, 0, SRCCOPY) Step 2: Converting from DDB to DIB The return value should be stored to be able to de-select the object later on. When you select a bitmap, the return value is an HBITMAP. When you select a pen, the return value is an HPEN. The return value is the handle of the previously selected object of the same type. The first parameter specifies the device context, the second specifies the object that is to be selected. HBITMAP OldBmp = (HBITMAP)SelectObject(OffscrDC, OffscrBmp) HDC OffscrDC = CreatecompatibleDC(SurfDC) Ī GDI object, which can be a bitmap but also a pen, a brush, a clipping region, etc., is selected into a device context using a function call like the following: It is wise to create a DC that is compatible with the surface’s DC:
#Gdi directdraw driver
connect it to the device driver that will actually perform the transfer. Before we can do so, we need to “select the bitmap into a device context”, i.e. We are going to use BitBlt to copy the image from the surface to our offscreen bitmap. We have created a bitmap that is compatible with the surface, but it does not yet contain any picture.
#Gdi directdraw code
See the code listing at the end of this article. Note: We can query the surface’s width and height with its GetSurfaceDesc method. HBITMAP OffscrBmp = CreateCompatibleBitmap(SurfDC, Width, Height) That function does not expect an LPDIRECTDRAWSURFACE but the handle of a GDI device context, which, in turn, we will create by calling the surface’s GetDC method. A compatible bitmap is created with the GDI function CreateCompatibleBitmap. That bitmap should be compatible with the DirectDraw surface, as we will copy the surface’s contents to it. We need a GDI bitmap that GetDIBits can work with. GetDIBits will also generate a palette if needed. We could, for example, convert a 32-bit surface to a 16-bit BMP. The beauty of GetDIBits is that it can convert to any format. After the conversion, we simply dump the converted data into a file. Before we can call it, however, we need to obtain a GDI-compatible device context from the surface and obtain the handle of a DDB. The GDI function GetDIBits will do that for us. Our task when creating a screenshot is to convert the DDB on the surface to a DIB. In addition to the bitmap bits, the file contains an information header that describes the format of the data. The format stays the same no matter which device the bitmap is intended to be displayed on, be it a printer, a 24-bit display, a 16-bit display, etc. IDirectDrawSurface::Blt, which does not do more than that either, will fail if surface formats do not match.īMP files, on the other hand, store device- independent bitmaps (DIBs).
![gdi directdraw gdi directdraw](https://programmer.help/images/blog/f5219cb6289c416d92594eecb8077cee.jpg)
You could not copy it to a surface of a different pixel format with a simple memcpy. The bitmap on a DirectDraw surface is stored in a device-dependent format. Note: While we’ll be working with DirectDraw surfaces, the presented method can be used to capture any GDI device context. If ((int)wParam) = VK_F11) Screenshot("shot.bmp", lpDDSBack) Our goal is to have a single function for all resolutions and pixel formats that is as easy to call as this: In this tutorial we’ll write a screenshot function that can be used to capture DirectDraw surfaces.
#Gdi directdraw windows
Laziness is said to be one of the programmer’s virtues, but it will not deter us from writing a screenshot function! After all, there are Windows and its Graphics Device Interface, the GDI, that we can delegate to. You wouldn’t want to prevent either by being lazy, would you. Similarly, magazine reviewers will take screenshots for their articles, and users might wish to use them (the shots, not the reviewers!) as desktop wallpapers. Screenshots let you show off the beauty of your game to others, e.g. When they play your game, they must rely on you to provide a camera.
![gdi directdraw gdi directdraw](http://www.yaldex.com/games-programming/FILES/07fig38.gif)
This article was originally published at Gary Simmons’ Mr GameMaker.Įvery game should have a screenshot function! When people go to Disneyland, they bring their cameras.