I am writing a program that will do this, http://www.asmcommunity.net/board/index.php?topic=7748.

I have questions about painting with bitmaps. I have the chess board as my background( a bitmap of course ), all I do is SelectObject and BitBlt. But is there a better way to paint this background? What happens if I want to move it to a different place in the client area, do I just BitBlt to a different location?

Also I have to paint multiple chess pieces( 24 pieces ), I have read multiple posts here about painting transparent bitmaps( I found one from NaN ) and also the one at www.winprog.org, but that code seems to be for painting one bitmap, is this going to be a bad idea to use it for 24 bitmaps? :confused: Or is it just going to be plain hard what I want to do?

I am wanting to get the GUI first, the parsing and storing of data won't be that hard for me( Posted on 2002-09-17 10:33:27 by gorshing
I was once writing a program to serve as an editor for 2d game maps. Needless to say there was alot of bitblt-ing involved. Despite the fact that I was using DirectX for the game, once I started programming the editor my mind just went to GDI mode. It was a pretty bad choice becuase performance was quite poor. Even with using ScrollWindow and painting only the update rectangle, the flicker was quite noticeable. I ended up redoing the graphics rendering code to use DirectDraw and of course it now integrates better with the game.

I haven't clicked on the link yet, but based on you said in your post, it sounds like like a pretty good fit for DirectDraw. Transparency is a breeze in DD. No bitmasks and crap. Just specify which color in your graphic should be transparent and DirectDraw does not transfer it during a blt.

If you haven't used DirectX before its a bit of an investment but worth it IMO if you are going to be doing graphics stuff.


Or is it just going to be plain hard what I want to do?


I haven't done alot of transparency with the GDI functions but I suspect the answer to your above question is yes.


EDIT: Just did a quick MSDN library search. If you want to go the GDI route maybe you should check out the AlphaBlend function. I haven't used it before so I can't really say much apart from that. Probably somebody else will be of more help apart from suggesting that you do something totally different...heh
Posted on 2002-09-17 11:18:07 by Thanatos
I'd say 12 pieces would be enough. No need to have 2 towers (etc) of each color.

Just put all 12 chess pieces in 1 bitmap to start with. keep them all at exactly the same distance so that you can access each piece from an array once you got the bitmap in an DC.

(white - normal pieces)
(white - mask for pieces)
(black - normal pieces)
(black - mask for pieces)

So, all you have to calculate the x to where a piece is. As you always know the y.


PS: I don't know the names of chess pieces in english :stupid:
Here I just used the german initials of each piece from left to right.
Posted on 2002-09-17 11:26:02 by JimmyClif
hello gorshing (my last post today, pheew :) )


But is there a better way to paint this background?



WinMain PROC hInst:DWORD,hPrevInst:DWORD,CmdLine:DWORD,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
...
invoke LoadBitmap,hInst,BGPicID
mov hBitmap01,eax
invoke CreatePatternBrush,eax
mov wc.hbrBackground,eax
...


What happens if I want to move it to a different place in the client area, do I just BitBlt to a different location?

in this case you have to draw it via bitblt on wm_paint to your device-context (which you'll find in
the paintstruct structure that BeginPaint offers). bitblt features x and y offsets so you can drop
your picture where you want... another thing, you mentioned that you use selectobject on your dc.
a d-context doesn't allow ANY drawing operation until you select a bitmap into that device... here's
what i would do (backbuffered so it doesn't flicker)


.DATA MainDC DD ?
BackDC DD ?
hBitmap01 DD ?

.ELSEIF uMSG == WM_CREATE
INVOKE CreateCompatibleDC,NULL
MOV MainDC, EAX

INVOKE GetDC, NULL
PUSH EAX
INVOKE CreateCompatibleBitmap,EAX,1500,1500 ; CREATE A BIG BITMAP
PUSH EAX
INVOKE SelectObject, MainDC, EAX ; SETUP DC
POP EAX
INVOKE DeleteObject, EAX
POP EAX
INVOKE ReleaseDC,hWnd, EAX

INVOKE LoadBitmap, hInstance, BGPICID ; LOAD BACKGROUND-PIC
MOV hBitmap01, EAX

INVOKE CreateCompatibleDC,NULL
MOV BackDC, EAX
INVOKE SelectObject, EAX, hBitmap01

.ELSEIF uMSG == WM_PAINT
INVOKE BeginPaint, hWnd,ADDR ps

INVOKE BitBlt, MainDC, 0, 0, PICTURE_W, PICTURE_H, BackDC, 0, 0, SRCCOPY

;DRAW THE CHESS FIGURES HERE TO THE MainDC

INVOKE BitBlt, ps.hdc, 0, 0, ps.rcPaint.right, ps.rcPaint.bottom, MainDC, 0, 0, SRCCOPY

INVOKE EndPaint,hWnd,ADDR ps

.ELSEIF uMSG == WM_DESTROY
INVOKE DeleteDC, MainDC
INVOKE DeleteDC, BackDB
INVOKE DeleteObject, hBitmap01

it creates two dc's selects a compatible bitmap to the backbuffer-dc so that it allows
drawing actions from now on... the rest is easy...

I have read multiple posts here about painting transparent bitmaps

please see the attachement, it draws three transparent bitmaps to a black surface.
the first pixel is interpreted as transparent color... the routines are very old many
things are just nonsense, for example you have to pass the bitmap width/height...
thats stupid because you can get that information with the GetObject API
automaticly...
Posted on 2002-09-17 11:27:18 by mob
forgot the attachement
Posted on 2002-09-17 11:28:15 by mob