By John Pullen, Paul Bearne and Jeff Kurtz
[Q] Can I draw image library images on a regular Delphi Canvas without DirectX?
[A] Yes. If you drop an image library compnoent on your form and load a library you can draw the images on a regular Delphi canvas without any other DGC components. This means you can write regular Delphi applications without any DirectX components. This is useful for writing map editors etc. You can do the same kind of thing with the sound components and write regular Delphi application that just make use of the sound components (I wrote a simple drum machine for example - source available on request).
Example of drawing an image library image:
DGCImageLib1.DrawImage(Canvas, x, y, ImageNbr);
[Q] Can DGC run in a window mode?
[A] No. This is because initialising DirectDraw to run in a window causes too many restrictions and problems. The main problem is that double buffered surfaces and page flipping are not supported in that mode. You also have to keep the 20 system colors in the palette for windows to use. If you want tun run DGC in a windowed mode to write a map editor or something like that then use the DrawImage function mentioned above. If you want a windowed mode during development for dugging then use the TRACEWIN.EXE program (the source only is supplied and must be compiled). If you run the tracewin program before your DGC program any exceptions raised will be sent to the trace window. You can send your own messages to the window by using the Trace unit and the TraceString command.
Example:
TraceString(Format('xpos=%d, ypos=%d', [x, y]));
[Q] When running my program the screen goes black, I hear a beep and the mouse pointer appears?
[A] This is because an exception has occured. You can hear the beep because of the TDGCScreen property BeepOnException is set to True. If you want to see what the exception message is then you must run the TRACEWIN.EXE utility before running your DGC program. This is mentioned above. Common causes of this type of error are drawing an image with BltFast outside of a surface area, or using an image library that is not assigned to the TDGCScreen component.
[Q] I am having trouble using transparent images with the image library component?
[A] The key thing to remember is that when an image is loaded into the image library editor you must set the color that is to be transparent color for the image before it is added to the image library. A step by step guide of doing this is described below:
1. The first thing you need to do is determine which is the pallette index of the color that is to be the transparent color for the image. This may not always be index 0. This is easily done by loading the .Bmp file into Paint Shop Pro and using the pipet.
2. From within the Iimage Library Editor select menu option Bitmap|Open and load the bitmap. Do not do anything else at this point.
3. Select menu option Bitmap|Edit Palette to edit the palette for the bitmap that was just opened. Now comes the crucial bit. Either type it in or use the right mouse button to select the color that is to be the transparent color for that bitmap. This is the value returned by the PaintShop Pro pipet, and remember, this may not always be palette index 0. What happens now is when you hit the OK button all occurences of the selected palette index will be changed to index 0. The end result is that all images added to the image library will have a transparent palette index of 0.
4. Finally add the image to the library by selecting menu option Library|Add Image.
If all of your bitmap files have a palette index of 0 you can use the Bitmap|Batch Add to add multiple images at the same time.