• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

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

graeme

i need help in tweaking blitting sourcecode

11 posts in this topic

and the source code I need to tweak is here: http://www.codeproject.com/bitmap/gditutorial.asp#xx82862xx Now, I realise I am asking quite a lot by asking you to download the zipped file for tutorial 2 and taking a look at it, but I have been trying to crack this all day! What I am trying to do is modify the code in anticipation of using it as the basis for a program which will animate a series of bitmaps. The program initializes and paints the bitmap to the window within functions called by the message handler, WM_PAINT + WM_CREATE. At the moment I am trying to bypass the WM_PAINT call to the gdi02_OnPaint function, and call the function from within winMain instead, but nothing happens. I realise that this is probably due to the scope of the data structures within the functions. During the switch of a message is all data shared? How would I get around this? I realise that it''s a pain to go download a zip file but I would be really gratefiul! Thanks in advance, Graeme.
0

Share this post


Link to post
Share on other sites
quote:
At the moment I am trying to bypass the WM_PAINT call to the gdi02_OnPaint function, and call the function from within winMain instead, but nothing happens. I realise that this is probably due to the scope of the data structures within the functions. During the switch of a message is all data shared?
How would I get around this?


It really depends on what the overall program is supposed to do. If you''re seeking to move the blitting into a game loop or something similar, you''re headed in the right direction. If the animation is secondary to the app, then you''re heading in the wrong direction.

You might want to consider using memory dc (off screen buffer) and using the WM_PAINT message to blit that to the primary surface.

You might have an easier go of it using Joseph Farrell''s tuts
http://www.gamedev.net/reference/articles/article1251.asp

Sorry to not be more specifically helpful.
0

Share this post


Link to post
Share on other sites
The article was indeed very helpful. Thanks.

But still I would love to know the answer to the specific problem of what needs to be done to transplant the calling of the functions from WM_CREATE and WM_PAINT tio the winmain loop.
I have tried making different variables global, even transplanting alll of the code from the three blitting functions to winmain but I have had no success.
I''d like to stick with this bit of sourcecode, the URL of which is iin my first post, because it''s the only place that I have found a resource that shows how to blit with masks without resorting to using directX.

It''s driving me crazy!
0

Share this post


Link to post
Share on other sites
OK, maybe this will make it easier for people to answer my question, although I always though dumping a load of code and asking for fixes was a bit much (but maybe not as cheeky as asking for someone to download a zip file!!)

hbmImage = LoadBitmap(hinstance,MAKEINTRESOURCE(IDB_BITMAP2));
BITMAP bm;
GetObject(hbmImage,sizeof(bm),&bm);
hbmMask = CreateBitmap(bm.bmWidth,bm.bmHeight,1,1,NULL);

HDC hdcSrc = CreateCompatibleDC(NULL);
HDC hdcDst = CreateCompatibleDC(NULL);

HBITMAP hbmSrcT = SelectBitmap(hdcSrc,hbmImage);
HBITMAP hbmDstT = SelectBitmap(hdcDst,hbmMask);

COLORREF clrTopLeft = GetPixel(hdcSrc,0,0);
COLORREF clrSaveBk = SetBkColor(hdcSrc,clrTopLeft);

// This call sets up the mask bitmap.
BitBlt(hdcDst,0,0,bm.bmWidth,bm.bmHeight,hdcSrc,0,0,SRCCOPY);
HDC hdcMem = CreateCompatibleDC(NULL);

HBITMAP hbmT = SelectBitmap(hdcMem,hbmMask);

//BITMAP bm;
GetObject(hbmMask,sizeof(bm),&bm);

hdc = GetDC(hwnd);

BitBlt(hdc,0,0,bm.bmWidth,bm.bmHeight,hdcMem,myX,myY,SRCAND);


SelectBitmap(hdcMem,hbmImage);
BitBlt(hdc,0,0,bm.bmWidth,bm.bmHeight,hdcMem,myX,myY,SRCPAINT);

// Now, clean up.
SelectBitmap(hdcMem,hbmT);
DeleteDC(hdcMem);
DeleteObject(hbmImage);
ReleaseDC(hwnd, hdc);

I should imagine that''s all pretty straightforwards for someone who is more experienced thatn I. The one thing which may not look obvious at first sight is the COLORREF getting of pixels, this is a device by the author of the code to work out the background transparancy colour.

Oh yes, and hbmMask and hbmImage are bothe declared as globals earlier in the script.
0

Share this post


Link to post
Share on other sites
First, I''m not aware of the SelectBitmap api - looks to me like that ought to be SelectObject.

After you get that set of code working, you''ll have to integrate it into the message handling loop of WinMain. You might want to use PeekMessage instead of GetMessage. For example:
  
// main message loop

while( TRUE )
{
// test for message in queue, if so get it

if ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) )
{
if ( msg.message == WM_QUIT )
{
break;
}
// send the message to the window proc

DispatchMessage(&msg);
}
else {

// insert blitting code

}
}


Be careful with this construct as your app will use up all of the CPU time.

You''ll also want to set the hbrBackground member of the WNDCLASS structure to NULL or return 0 from the WM_ERASEBKGND handler so as to prevent any flicker from happening. You don''t need to deal with WM_PAINT at all.

HTH :-)


0

Share this post


Link to post
Share on other sites
Thanks alot for your reply, less bread. I shall try changing the SelectBitmap command, but I think that it is probably ok, because the source code that I took it from compilled and ran just fine. Perhaps I should have mentioned it, but it is allready in the winMain function, after the message queue is checked...
0

Share this post


Link to post
Share on other sites
Aha!
I rebuilt the whole thing from scratch and it worked, so whatever was wrong will always be a mystery to me!

0

Share this post


Link to post
Share on other sites
I couldn''t find SelectBitmap listed in the exports from gdi32.dll so perhaps SelectBitmap was defined in the sample code (I glanced at it but didn''t pay that close of attention) - or maybe its a W9x specific function, I''m running W2K. Anyway, glad I could help!
0

Share this post


Link to post
Share on other sites
hi there LessBread,
I found it in MSDN : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmeother/graphcnt_1lys.asp , selectBitmap, that is. It says at the top of the page that it''s supported by Win 98/ME (and it also says Windows DDK, what''s that? developers something Kit I expect.) Does this mean that any executable I write using this function won''t work under other windows platforms, or does it mean that the function can only be compiled by compilers running under these platforms? Complecated stuff, this windows programming...
0

Share this post


Link to post
Share on other sites
Greets,

Turns out that SelectBitmap is a macro that calls SelectObject.
  
#define SelectBitmap(dc,bm) ((HBITMAP)SelectObject((dc),(HGDIOBJ)(bm)))


The C preprocessor will replace your calls to SelectBitmap with a call to SelectObject as defined above before sending the source code to the compiler. This means your prog will run on NT also, granted that the rest of the program doesn''t make W9x specific calls.

To unravel the macro a bit. If you examine your source code after preprocessing, where you wrote

HBITMAP hbmSrcT = SelectBitmap(hdcSrc,hbmImage);

you would find

HBITMAP hbmSrcT = ((HBITMAP)SelectObject((hdcSrc),(HGDIOBJ)(hbmImage)));

Since I never use that macro, I didn''t recognize it.

Windows DDK -> Driver Development Kit: "...specific information needed to write any type of driver for Windows xxx platforms." There are different DDK''s for each of the different versions of Windows as well as for each Service Pack. Lots of low level stuff, mostly C and some assembly language too. Definitely not for the faint of heart. :-)







0

Share this post


Link to post
Share on other sites
Let me know what you get, I''m curious to hear about it.

‘But truth's a menace, science a public danger.’ Brave New World, Aldous Huxley
0

Share this post


Link to post
Share on other sites