|
_ TUTORIAL: BitBlt & GDI32 for the Thick-Headed: BitBlt explained, + Load Sprites, Double Buffering! |
| | | | | | "BitBlt [and GDI32] for the Thick Headed" is an in-depth, plain-english, streight-forward tutorial that teaches everything there is to know about BitBlt, and some related API. It covers everything from loading bitmap files into memory (no more picture boxes) to double-buffering (say goodbye to the SLOW 'AutoRedraw'!) to Explaining the BitBlt API in PLAIN ENGLISH. PLUS the tutorial only takes about 15 to 20 minutes to complete! (A completed version of the example project is also included) This article has accompanying files | | | Terms of Agreement:
By using this article, you agree to the following terms...
1) You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
2) You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
3) You may link to this article from another website, but ONLY if it is not wrapped in a frame.
4) You will abide by any additional copyright restrictions which the author may have placed in the article or article's description. |
BitBlt for the Thick-Headed...
In this tutorial you will learn...
- Howto load a bitmap file into memory
- Howto create a back-buffer
- The BitBlt API explained in plain english
- Howto use double-buffering techniques to achieve fast, flickerless graphics (faster then AutoRedraw)
This tutorial should NOT take more then 15 minutes to read - If you read every line and follow every instruction, almost everything you need to know [about BitBlt] is here!
Welcome to my tutorial which I have titled BitBlt for the Thick Headed. If you want to go through this tutorial quickly, all the essential parts are in BOLD. For the record, I mean no offence to anyone on the PSC community, I was going to call it BitBlt for Dummies like the popular For Dummies books, but didn't want to get into copyright complications with book publishers. The goal of this tutorial is to step-by-step explain howto use BitBlt and some other Win32 GDI functions, to accomplish tasks such as double buffering and loading sprites from files - All in a relatively short reading-time (basically i'll try not to ramble on too much)
Anyways, let's get started...
The first thing your going to do obviously is create a form (so you can follow along with this tutorial), set the ScaleMode to '3 - Pixel', I suggest you always set the scalemode to Pixels if your going to be using the form with API.
Next Increase the form's size until the ScaleWidth is 320, and the ScaleHeight is 256.
We will be using the form as our practice surface, note that the form property called "HasDC" must be set to TRUE. Also, for many of you who fell in love with using AutoRedraw, we will NOT need AutoRedraw because we are going to be using Double Buffering which is ALOT faster, and more professional.
The next step is to declare the API calls that we will need, as shown below. So copy and paste the code below into your form. If you dont know what API is, then you should do some research about it, before you even try to figure this tutorial out! ;-)
'The following API calls are for:
'blitting
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
'code timer
Private Declare Function GetTickCount Lib "kernel32" () As Long
'creating buffers / loading sprites
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
'loading sprites
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
'cleanup
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
'end of copy-paste here...
|
Q. What is a DC (also known as: Device Context, hDC)?
A. A Device Context is a number that points to an "address" in memory where data is stored, when using BitBlt, we point to the Address where graphical data is stored in memory.
Next, we need to store the addresses of the DC's that we are creating. DC's addresses are Long values so we will Declare Public Variables to store the DC's memory address as shown below. (copy and paste
'our Buffer's DC
Public myBackBuffer As Long
Public myBufferBMP As Long
'The DC of our sprite/graphic
Public mySprite As Long
'coordinates of our sprite/graphic on the screen
Public SpriteX As Long
Public SpriteY As Long
'end of copy-paste here...
|
Q. Do we have to make all these variable's public?
A. NO, BUT its a good idea to at least make the DC's variables public so that its easier to cleanup the memory after the program is finished.
Now we have the foundation of our code, we have all the API declarations we'll be needing, and all the variables we'll be using in this example. The next thing we're gunna do is create a function that loads graphics into memory, it makes working with the API a bit simpler...
Device Contexts - TIP: One thing that is important to understand is that a device context alone has no graphical data in it. A device context needs to have a bitmap loaded into it, whether that be a bitmap file, or a blank bitmap to use as a canvas to draw on (which is how you create a back buffer).
Ok, so this is what our function does... It creates a Device Context compatible with the screen, it then loads the specified graphics file into the device context... Copy and paste the function below, but be sure to read all the comments so you understance the concept.
Public Function LoadGraphicDC(sFileName As String) As Long
'cheap error handling
On Error Resume Next
'temp variable to hold our DC address
Dim LoadGraphicDCTEMP As Long
'create the DC address compatible with
'the DC of the screen
LoadGraphicDCTEMP = CreateCompatibleDC(GetDC(0))
'load the graphic file into the DC...
SelectObject LoadGraphicDCTEMP, LoadPicture(sFileName)
'return the address of the file
LoadGraphicDC = LoadGraphicDCTEMP
End Function
'end of copy-paste here...
|
Q. What is double-buffering?
A. Double Buffering is when you create a graphical surface to paint on (like a canvas) that you blit all of your sprites/graphics/text onto in the memory (offscreen) then blit the final result onto the screen. It prevents flickering (which occurs if multiple sprites are blitted directly onto the screen.) and is much faster then AutoRedraw.
We're gunna be using the function in our example code... but before we go any further with the example project, I'm going to explain the BitBlt API from start to finish.
The BitBlt API...
BitBlt is a function in the DLL "gdi32".
Technical Deffinition: it performs a bit-block transfer of the color data corresponding to a rectangle of pixels from the specified source device context into a destination device context.
In Plain English... This basically means that it copys graphical data from one graphics surface [a bitmap] to another graphics surface [the screen, or a form].
Now lets take a look at the API declaration itself...
The API declaration should be placed in the "General Declarations" section of a form or module. Here's what it looks like:
Declare Function BitBlt Lib "gdi32" Alias "BitBlt" _
(ByVal hDestDC As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal hSrcDC As Long, _
ByVal xSrc As Long, _
ByVal ySrc As Long, _
ByVal dwRop As Long) As Long
The first part of this code, the first line (in this example) says that we're
accessing the BitBlt function from the gdi32 DLL. the following lines are parameters that we have to input in order to use the function in our program. Here's a rundown of what each of these parameters is:
hDestDC - The hDC of the destination surface (this could be a form.hDC if you want to blit to a form, or it could be the address of a backbuffer that we've created).
x - The X (horizontal position) coordinate of where we want the graphic to appear.
y - The Y (vertical position) coordinate of where we want the graphic to appear.
nWidth - The width of our graphic.
nHeight - The height of our graphic.
hSrcDC - The hDC of the source graphic, for example the DC address of a sprite that we loaded into memory.
xSrc - The X (horizontal) offset, 0 if you want to blit from the very left edge of the source graphic, if you want to start the blit from 18 and over then you would make this value 18, etc.
ySrc - The Y (vertical) offset, same idea as xSrc, except vertically
dwRop - The drawmode we want to use when blitting our graphic, also known as Raster Operations or ROPs. This parameter is explained below.
The drawmodes, or Raster Operations/ROPs available are as follows, each of these is a reserved constant in VB, so any one of these words (in italic) can be used in the dwRop parameter to acheive different effects:
<-- Blt Modes -->
- vbSrcCopy - Copy the source image data directly onto the destination,
replacing it completely.
- vbSrcPaint - ORs the source and destination image data, giving a
pseudo-alphablending effect.
- vbSrcAnd - ANDs the source and destination image data, giving a
pseudo-gamma effect.
- vbSrcInvert - XORs the source and destination image data.
- vbSrcErase - Inverts the destination image data then ANDs with
the source image data.
- vbDstInvert - Inverts the destination image data, and ignores the
source image data completely.
- vbNotSrcCopy - Inverts the source image data and copies directly onto
the destination, replacing it completely.
- vbNotSrcErase - ORs the source and destination image data and
inverts the result.
'An example of using BitBlt
BitBlt Form1.hDC, PlayerX, PlayerY, 48, 48, picPlayer.hDC, 0, 0, vbSrcCopy
On with our example project...
Next in our example project (this is the final part), we're going to use BitBlt in a loop much like you would in a game. Here's what you need to do:
- Save the project file (and form file) in its own Directory.
- Create a bitmap (BMP) file, make it 32 X 32 pixels. And save it in the same directory as the project.
- NAME THE BMP FILE "sprite1.bmp"
- Create a command button, rename it to cmdTest.
- Move the command button to the bottom right of the form.
- Double click on the command button to bring-up its sub in the code-window, so we can enter code to be executed when it is pushed.
Copy and paste this code into the command button's Click-Event subroutine.
READ ALL THE COMMENTS, to understand the code...
'=== THIS CODE GOES IN CMDTEXT_CLICK EVENT ===
'Timer variables...
Dim T1 As Long, T2 As Long
'create a compatable DC for the back buffer..
myBackBuffer = CreateCompatibleDC(GetDC(0))
'create a compatible bitmap surface for the DC
'that is the size of our form.. (320 X 256)
'NOTE - the bitmap will act as the actua
' l graphics surface inside the DC
'because without a bitmap in the DC, the
' DC cannot hold graphical data..
myBufferBMP = CreateCompatibleBitmap(GetDC(0), 320, 256)
'final step of making the back buffer...
'load our created blank bitmap surface into our buffer
'(this will be used as our canvas to draw-on off screen)
SelectObject myBackBuffer, myBufferBMP
'before we can blit to the buffer, we should fill it with black
BitBlt myBackBuffer, 0, 0, 320, 256, 0, 0, 0, vbWhiteness
'load our sprite (using the function we made)
mySprite = LoadGraphicDC(App.Path & "\sprite1.bmp")
'MsgBox Dir$(App.Path & "\sprite1.bmp")
'ok now all the graphics are loaded so
'lets start our main loop..
'Disable cmdTest, because if the graphics are
'reloaded there will be memory leaks...
cmdTest.Enabled = False
'== START MAIN LOOP ==
'get current tickcount (this is used as a code timer)
T2 = GetTickCount
Do
DoEvents 'DoEvents makes sure that our mouse and keyboard dont freeze-up
T1 = GetTickCount
'if 15MS has gone by, execute our next frame
If (T1 - T2) >= 15 Then
'clear the place where the sprite used to be...
'(we do this by filling in the old sprites place
'with black... but in games you'll probably have
'a background tile that you would blit here)
BitBlt myBackBuffer, SpriteX - 1, SpriteY - 1, _
32, 32, 0, 0, 0, vbBlackness
'blit sprites to the back-buffer ***
'You could blit multiple sprites to the
' backbuffer,
'but in our example we only blit on...
BitBlt myBackBuffer, SpriteX, SpriteY, 32, 32, _
mySprite, 0, 0, vbSrcPaint
'now blit the backbuffer to the form...
BitBlt Me.hdc, 0, 0, 320, 256, myBackBuffer, _
0, 0, vbSrcCopy
'move our sprite down on a diagonal...
'Me.Caption = SpriteX & ", " & SpriteY
SpriteX = SpriteX + 1
SpriteY = SpriteY + 1
'update timer
T2 = GetTickCount
End If
'loop it until our sprite is off the screen...
Loop Until SpriteX = 320
'end of copy-paste here...
|
DONT RUN THE PROGRAM YET, we need to write the cleanup code...
The cleanup code is just some code that we add that clears the memory that was occupied by the graphics that we loaded, and the backbuffer that we created (see above code).
This code should usually go in the Form_Unload event, so that it is executed when the form unloads...
Copy and Paste the code below into the form's module
Private Sub Form_Unload(Cancel As Integer)
'this clears up the memory we used to hold
'the graphics and the buffers we made
'Delete the bitmap surface that was in the backbuffer
DeleteObject myBufferBMP
'Delete the backbuffer HDC
DeleteDC myBackBuffer
'Delete the Sprite/Graphic HDC
DeleteDC mySprite
End
End Sub
'end of copy-paste here...
|
That's it! We're done! Run the program, click the button and you will see the sprite move from the top-left of the form to the bottom right, without any flickering...
Example project included.
yar interactive software - 2002
| | Download article
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzipto decompress it.
Virus note:All files are scanned once-a-day by Planet Source Code for viruses,but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE: 1)Re-scan downloaded files using your personal virus checker before using it. 2)NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code. 3)Scan the source code with Minnow's Project Scanner
If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com
| Terms of Agreement:
By using this article, you agree to the following terms...
1) You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
2) You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
3) You may link to this article from another website, but ONLY if it is not wrapped in a frame.
4) You will abide by any additional copyright restrictions which the author may have placed in the article or article's description. | Other 17 submission(s) by this author
| | | Report Bad Submission | | | Your Vote! |
See Voting Log | | Other User Comments | 6/20/2002 2:38:56 AM:(Tim Miron) yar-interactive software Comments appreciated. =-)
| 6/20/2002 3:03:10 AM:Plasma Very nice, thankyou :)
What would
be awsome is if you could create an
EXTREAMLY simple smooth scrolling game
(using grid to place textures,dosnt
really matter, I understand how to do
that I think :) ) but also where you
can shoot a projecticle (multiple).
That would totaly be cool, and I could
learn alot and so would others, 5
globes from me here, well done
tutorial, good effort :)
| 6/20/2002 3:09:11 AM:(Tim Miron) yar-interactive software Thanks... I know this tutorial looks
like its VERY LONG, but after I wrote
it I went through the whole thing
myself (and made the example project
that I included) and it only took about
15 minutes to complete, so if your
serious about learning this stuff, take
the time to read everything through!
You'll be thankful ya did. I hope this
helps people :)
| 6/20/2002 3:27:26 AM:(Tim Miron) yar-interactive software Oh and about making a smooth scrolling
game, I am already working on one... it
is a sequel to my game "Botmatch"
called "Botmatch - Secondary Protocal"
and is about 10 times as advanced (code
wise) as the first botmatch. =-) I will
be posting that project on here when
completed...
Any other suggestions
or comments about this tutorial are
welcomed :)
| 6/20/2002 3:42:52 AM:Plasma Thanks again!
Could you possibly
show some code to fire projectiles, Im
thinking I am to have a procedure
CreateNewBullet(startX, startY,
Direction) and it will load a new array
and do a gameloop to perform the
movement, maybe you have an alternate
version?
Oh, not sure if this is
'true' Frames per second code, but
seems to be running cool! Here Is what
I've added to my new project ive
started :P
Pop this in your GameLoop
(or in this example, cmdTest_Click) and
before starting the procedure make sure
you go lngTick = GetTickCount
I get
~52fps :)
'Approximate FPS
Counter
If GetTickCount - 1000 >=
lngTick Then
Caption = "FPS: " &
intFPS
intFPS = 0
lngTick =
GetTickCount
Else
intFPS = intFPS +
1
End If
'End FPS Counter
| 6/20/2002 3:44:44 AM:dafhi Few things:
1. I am Extremely
thick-headed when it comes to API stuff
that uses more than about 3
parameters.
2. Thank you for this fine
article.
3. HasDC at design-time seems
to work if True or False ..
4. I am
confused about myBufferBMP =
CreateCompatibleBitmap.. .. isn't that
almost like a ReDim statement?
confused, confused
| 6/20/2002 3:57:12 AM:(Tim Miron) yar-interactive software Ok, like it says in the article, a
device context by itself holds no
graphical data in it... so in order for
us to let the DC hold graphical data
(which is what the buffer does) it
needs to have a bitmap assigned to
it... before we can assign a bitmap to
it, we have to create a bitmap.
myBufferBMP is a variable that points
to the "address" of the bitmap object,
just like myBackBuffer points to the
address of a HDC. So we create a
bitmap using the CreateCompatibleDC
function, and the address of the bitmap
is returned to our variable
myBufferBMP, we then assign the bitmap
to the DC that we created for our
backbuffer by using the SelectObject
API.
That help at all?
| 6/20/2002 4:05:15 AM:(Tim Miron) yar-interactive software hehe make sure you read the Q. and A.
stuff i put in there in small red
text... some useful info ;)
| 6/20/2002 4:21:05 AM:dafhi ok so it looks like createcompatbitmap
then returns the address as well as
blocks off a chunk of memory .. alright
I think I am getting it now except I am
still stuck on SelectObject.
| 6/20/2002 4:56:13 AM:Rang3r Some corrections ,
a HDC is NOT the
same as a DC..
a HDC is a HANDLE to
DC.
a handle is NOT a memmory address
, its just like a KEY in a
collection..
think of it as you are
placing objects (DC's) into a
Collection , where each object have a
unique key , that key is the same thing
as the HDC , while the DC is the Object
referenced by that key...
eg. DC=0
does not mean that the desktop is
located at position 0 in the memory ...
its just has the KEY "0"
| 6/20/2002 4:57:33 AM:Ranger correction to my correction...
"DC=0
..." should be "HDC=0 ..."
| 6/20/2002 6:00:51 AM:Ranger also , when using AUTOREDRAW you ARE
using doublebuffering , eventhough the
implementation of autoredraw certainly
s ux...
| 6/20/2002 6:10:18 AM:dafhi u know what else s ux is that when
using autoredraw, u shouldn't have to
'ask windows permission' to draw to
that 'second surface' .. functions like
SetPixelV should be lightning-fast
| 6/20/2002 8:09:51 AM:dzzie great article and discussion :) *\:)/*
| 6/20/2002 10:55:12 AM:(Tim Miron) yar-interactive software HAha... well looks like someone cought
me red-handed I honestly didn't know
that the H in HDC stood for Handle...
should of figured that one it. Umm but
I already understood that a DC was an
object in memory, and basically
understood that you handle these object
by their handle's... overall, aside
from my lack of accuracy on the
meanings of terms, i believe for the
most part this artical is correct.
Anyways, I didn't even submit it for
votes I wrote it for practice (writing
programming articles) and simply hope
it helps people...
| 6/20/2002 10:58:15 AM:(Tim Miron) yar-interactive software And I knew autoredraw was a
double-buffering technique but its a
FRIGGIN SLOW double buffering
technique! ;)
| 6/20/2002 10:59:56 AM:(Tim Miron) yar-interactive software I think I'll submit an updated version
of this article making some
corrections, and also add info about
Transparent Blitting meathods etc.
| 6/21/2002 4:40:54 AM:Martin Good job Tim. It's not easy writing
tutorials there'll always be someone
who either doesn't understand it or can
find faults in it. Keep up the good
work - if you want to write this sort
of article PSC is good place to hone
your skills. I'll look forward to
another tut from you soon. Good luck.
| 6/21/2002 6:25:43 AM:dafhi Tim I wanted to say thanks again for
posting this article. To even get me
to paste code with BitBlt in it is a
major biggie. This is a fun project
and it really does take 15 minutes or
less. Not to mention the friendly and
professional layout of this article..
| 6/21/2002 12:21:03 PM:Jose M Serrano Thanks for sharing this excellent
tutorial, I think it's really good, I
would like to translate to VC++, cause
I'm learning it. Of course ALL THE
CREDITS are yours.
| 6/21/2002 11:55:57 PM:(Tim Miron) yar-interactive software No problem, if there's anything in this
tutorial that you think I could explain
more, or you have any questions, let me
know. Like I said, I am doing this for
practice!
| 6/22/2002 2:49:24 PM:Oscarreno I like your tutorial, very well
documented AND formatted.
| 6/22/2002 5:10:47 PM:Kareena
Thanks Tim.
This stuff is not easy
to get to grips with but your tutorial
has been a great help.
| 7/5/2002 8:35:20 AM: nice
| 7/16/2002 10:38:06 PM:Mr_Tuna That was incredible, especially for me
because i am new to this idea and have
been working on visual basic for a good
period of time. This is great for all
beginners. I have been trying to make
an arcade style shoot 'em game up like
space invaders or so, and i have been
working on that idea for months and not
being able to do it. now i think that i
have the knowledge to start really
gettings things goin. Again, thanks a
whole lot for you tutorial, keep up the
great work, and next time i'll
vote.
Great Job!
-Mr_Tuna-
| 7/20/2002 1:41:59 AM:alfadog Excellent! This code taught me what was
going through the API designers' heads
so that I can use their interfaces now!
Thanks a million.
| 7/20/2002 6:01:19 PM:(Tim Miron) yar-interactive software Thanks for your encouragment guys, I'm
trying to hink of what to write about
next... Any ideas are welcomed
| 7/29/2002 5:35:23 AM:MaradeuM Nice tut man, I always wondered how to
blit some graphic from file, well no
more those p. boxS. Now, how to
create a transp... if you'v heard 4
Commander Keen e-mail me !!!!!!!
| 8/23/2002 1:53:24 PM:Neal Blair This is wonderful. Your tutorial was
extremely helpful for the creation of a
program I just posted. Thank you.
| 8/26/2002 9:10:21 AM:Šonny Great tutorial! I could never figure
out bitblt until now. Keep up the good
work! 5 stars from me
| 9/7/2002 8:28:00 PM: Nice tutorial
| 9/22/2002 11:58:57 AM:Rob Loach Could you put a mask in? I'm having
some troubles with rendering multiple
Sprites with Masks onto a ready
rendered background.
| 9/24/2002 4:19:58 AM:zeff calilung hello. could you help me.
i made a
client server program.
i want to
capture my desktop in the client side
and send it to the picture box in the
server side of my program. how could i
do that with out saving the file and
transfering ito the server.
| 9/30/2002 12:37:58 PM:(Tim Miron) yar-interactive software I will shortly post a revised version
of this tutorial in which i will cover
masks and transparency. Look for it
soon here on PSC. :). If you want me
to add you to my mailing list, so i can
notify you of my tutorials and
game-development articles / projects,
send me an e-mail
at:
timbo_m45@hotmail.com
make the
subject "mailing list"
| 10/9/2002 4:33:33 AM:apidude great tutorial, easy to follow &
understand
thank you sir!
| 10/9/2002 7:28:57 AM:David Irvine this tutorial has helped alot, i just
couldn't get the double buffering
process to work last time but now i
understand.Thanks again!
| 10/15/2002 1:10:07 PM: Good Work! Excellent!
Your
sprite1.bmp is 32 x 32. What would you
need to do if the size of the sprite
was unknown? I tried using the
GetObjectAPI to obtain the bmWidth and
bmHeight from the BITMAP Structure but
it does not work because a DIB is not a
GDI.
| 11/2/2002 2:58:16 PM: Fantastic tutorial! I wish I'd found
this before I managed to piece together
a lot about BitBlt from a ton of
different bad tutorials! Still, it was
very informative to me. ^_^
Thank you,
keep up the good work~
| 11/3/2002 10:53:46 AM: Sound example, i have been not found
any more tutorials as good as this one,
Thanks for the help..
| 11/8/2002 2:00:05 AM: You have cured me of something that's
been nagging in my head for a long
time. Now I feel relieved and have a
huge chore behind me. Now, after
reading your great tutorial, these
questions come to mind. How can I
construct an array whose pointer I send
directly into BitBlt, this will not
only increase the scope of my
creativity but will also aleviate a
problem that VB has with
multi-threading; as noted by a poster
above whose having problems getting
simultaneous action going. And why
doesn't the image appear on the screen
immediately after I use BitBlt; how
does this work that placing a form HDC
draws the image on the screen; what
drawing powers does the form(windows)
have that's not in our reach and why
can't we tap into them and; I guess
that's it for now. I think we all
share the same views that's what's
limiting our creative potential is the
simple stuff hidden from us by Windows
which could give us a tap into the
tremendous power of our hardware. Thank
You again.
| 11/8/2002 4:02:35 PM:Rob Loach Dear previous poster,
You should be a
novelist :P.
| 11/9/2002 3:32:15 PM:(Tim Miron) yar-interactive software Thanks for the feedback everyone! More
is always welcomed!!!
| 11/11/2002 12:03:30 PM: Thanks, and I plan to partially be one.
Let me just clarify my previous post.
When you load a bitmap, all that you
are essentially doing is loading an
array of numbers. The way this array
works is unbeknown to me. Now, if I
had a desire to create dynamic images,
which I do, it would be impossible to
do them using predefined bitmaps. I
like and want to have control over the
individual pixels. Now your
instantaneous thought should be that I
should go into OpenGL and DirectX; and
this is what I plan to do, in addition
to Visual C++. Somehow, after visiting
this site, I found myself viewing
OpenGL pages and the amount of info and
details about creating games using it
inspired me to go into it.
| 11/12/2002 9:20:30 PM: You know it just occured to me, the
reason why setting individual pixels on
the form is so slow is because the
numbers of pixels you can set is
equivalent to the number of frames per
second minus the overhead used by the
PSet VB function. This is WASTHEBEST
by the way who posted the previous
comment.
| 11/15/2002 1:57:58 AM: That's a good tutorial. One question
though.. Why is your website linked to
a porno site?
| 11/16/2002 11:09:53 AM: looooooooooooooooooool linked to a
porno site :D good tut. though..
must've taken ages to write everything
| 11/19/2002 12:15:02 AM:(Tim Miron) yar-interactive software Actually it took about an hour to write
this tutorial... It aint very long if
you read it through it should take no
more then 15 minutes!
| 12/1/2002 3:36:12 AM:Nick Maresco wow, what an awesome tutorial. I spent
nearly a week trying to find something
that could tell me exactly how to use
BitBlt and all that and finally found
this just before I burned my machine
down :) One question though, is there
an easy way to draw a grid other than
blitting it onto the buffer? thanks.
~out.
| 1/13/2003 12:28:39 AM: Oh wow, lotsa comments here. Thanks
for the tutorial, it helped me out
tons. I already had most of it down,
just finally realized I was forgetting
the CreateCompatibleBitmap line.
(oops). Now I have a tough question:
How would I get to the raw data that
the bitmap buffed variable points to,
find out it's size, and then store it
in a file? I am trying to put together
a file that has the image data in it,
and some other stuff as well.
| 1/18/2003 8:44:29 AM: Hi, I've not tried to complete this
tutorial, but I'm sure it'll come in
handy. Thanks for writing the tutorial
because I've been wondering on how to
animate graphics without the flickering
and without using DirectDraw. Keep up
the good work.
| 1/20/2003 2:47:34 PM: I like your tutorial very much! It
really helped. (Not to mention the fact
that it shows how to use BitBlt
properly...) (Most people using Bitblt
for RPGs load tile blocks into picture
boxes and bitblt from those.(Yuck!))
One question:
I made the back buffer
1024x1024 and made my viewing window
320*200. I am using it as a scrolling
background on a Red Aleart clone. If I
make the back buffer HUGE (4024x4024)
it doesn't work. Do you know what the
max size is? Is it related to the
amount of video memory?
Thanks much!
| 1/28/2003 9:17:48 AM:Joseph Hicks First off, great tut (like THAT'S
original!). Second, I would like to
suggest that you take some(all?) of the
questions in here and answer them in a
FAQ-type-manner and distribute it to
your mailing list. Thanks again. :)
| 1/28/2003 1:10:59 PM:SkinRock Great tutorial, I've been waiting for a
good one on BitBlt. I too am trying to
make this into a map scrolling type
game. So far everything has been nice
to me, I rewrote some code so that the
bmp moves according to mouse postion
(all 8 sides actually), but now I don't
know how to do a loop that will keep
moving the bmp while you are in that
area. Basically I just put the
rendering code in the mouse move sub,
and took out the timer vars and
movement calls, and added some if
statements checking to see where the
mouse is, and if it is in one of the 4
sides or 4 corners, it will move, but
only once.
| 1/28/2003 4:31:01 PM:(Tim Miron) yar-interactive software RE: Joe Hicks, I will deffinitly do
that, a few of you have recently joined
the mailing list, if anyone else would
like to, send an e-mail to
timbo_m45@hotmail.com and make the
subject "mailing list".
<br><br>
For
further reading on VB game development,
I suggest seeing
http://vbgamer.strategon.com
| 1/29/2003 10:17:20 AM:IWon''tRevealIt Very cool, I made a game, an it was all
flickering, but now it's going to be S
M O O T H E! 5*
| 2/4/2003 4:46:10 PM: THANK YOU SO MUCH!!!! 5 globes all the
way!!!! Thank you so much!!!!
| 3/4/2003 3:31:42 AM: This is wonderful. Your tutorial was
extremely helpful
| 3/10/2003 10:16:42 AM: This is great, thanks. I'm in the
process of making an air-hockey game
and I think that this code is exactly
what I need.
Once again, thanks!
| 3/23/2003 10:44:51 PM: 9 months later this code is still
helping people like me, thanks
| 3/28/2003 9:15:25 PM: This tutorial is very imformative and
useful, infact I continue refering to
everytime I work with BitBlt. Great
work!
| 4/1/2003 12:42:44 PM:(Tim Miron) yar-interactive software wow.. I'm totally amazed at the
response I've gotten on this tutorial..
sorta makes me wanna write another one.
What do ya think I should write about
next? (try to keep it in the realm f
VB game/graphics programming).
| 4/1/2003 11:21:39 PM: Collision detection for dummies (so far
the code i've seen has done nothing but
confuse me), if its anywhere near as
easy as this was, it would be great!
| 4/2/2003 2:00:46 PM: I like to see a tutorial about hooking
up GDI to capture screen updates. By
the way nice work Tim Miron
| 4/6/2003 1:18:38 PM: I would like to see whatever you can
put into simple terms about
intermediate to advanced game
programming, that would be absolutely
great! I am looking forward to whatever
you come up with. And again thanks a
whole bunch, Game programming and
bitblt has become very clearer to me
because of your article.
-Mr_Tuna-
| 4/30/2003 11:09:59 AM:(Tim Miron) yar-interactive software Heads up people.. I'm releasing a new
game onto PSC in the next couple of
weeks [its April 30th today].. Look
for it it's gunna be SWEET! :)
| 4/30/2003 11:55:00 AM: Great tutorial! It helped me a lot, i
wat making a game that was flickering a
lot now it's going to be smooth! I have
to rewrite somethings but it's worth it.
| 5/22/2003 4:22:47 PM:Chris Hatton Thanks for sharing your code, very
helpful.
| 6/21/2003 1:06:06 PM: I'm very new to BitBlt and I can't
grasp this BackBuffer concept. What is
going on? Is it creating a blank bitmap
that is the size of the form, pasting
the sprite on that, then pasting the
product on the form?
| | Add Your Feedback! | Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.
NOTICE: The author of this article has been kind enough to share it with you. If you have a criticism, please state it politely or it will be deleted.
For feedback not related to this particular article, please click here. | | |