|
-
Apr 18th, 2005, 06:25 AM
#1
Thread Starter
G&G Moderator
BitBlt Problem
Howdy all,
Somewhere out there, I managed to find a copy of Visual Studio 6. I've now got VB and C++ 6 back. w00t!
Anyway, I'm trying to create a small (albiet crappy) 2D game engine, using BitBlt. Basically what I'm trying to do at the moment, is create a World Object, which will paint the main background, and hold all the different areas of the World (world is made up of regions, moving past a certain trigger will load the next region, kinda like KOTOR on Xbox and PC).
I have a BeginScene function, UpdateScene function and an EndScene Function. BeginScene just makes the usual Backbuffer, and then it fills it with black. The UpdateScene function draws the backbuffer to the World Objects HDC (in this case, the frmWorld form). The EndScene function then deletes the DC and Bitmap from memory.
This is my code..
VB Code:
Dim WorldDC As Long
Dim WorldBMP As Long
Dim FormDC As Long
Dim WorldRegions() As Long
Dim num_regions As Long
Private Function Initialize()
End Function
Public Function BeginScene(hdc As Long) As Long
'Here we will initialize the WorldDC and paint it plain black
Dim hr As Long, vr As Long
Dim wh As Long, ww As Long 'world height and width
FormDC = hdc
hr = GetDeviceCaps(hdc, HORZRES)
vr = GetDeviceCaps(hdc, VERTRES)
'set them to how they should be
If (hr > 0) Then
ww = hr * 0.4
wh = vr * 0.15
End If
'set up our world
WorldDC = CreateCompatibleDC(hdc)
WorldBMP = CreateCompatibleBitmap(hdc, ww, wh)
SelectObject WorldDC, WorldBMP
'fill it with black
BitBlt WorldDC, 0, 0, ww, wh, 0, 0, 0, vbBlackness
End Function
Public Function UpdateScene() As Long
'blit the backbuffer to the screen
BitBlt FormDC, 0, 0, ww, wh, WorldDC, 0, 0, vbSrcCopy
End Function
Public Function EndScene() As Long
'delete the memory users
DeleteDC WorldDC
DeleteObject WorldBMP
End Function
Private Function Terminate()
'Delete the memory users
DeleteDC WorldDC
DeleteObject WorldBMP
End Function
Anyone know why it doesn't blit blackness to the screen? I admit its been well into 7 months since I've typed a line of anything but ASM.
Any help would be appreciated,
Phreak
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Apr 18th, 2005, 06:31 AM
#2
Frenzied Member
Re: BitBlt Problem
Just use FillRect (win api) instead of BitBlt if you just want to fill the screen with a certain color (black).
-
Apr 18th, 2005, 06:33 AM
#3
Thread Starter
G&G Moderator
Re: BitBlt Problem
I'm just filling it with black to test it. I'll eventually get to drawing other things onto it. Mainly, the world background, and a few items and stuff. But at the moment, I just want it to work with black.
Phreak
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Apr 18th, 2005, 07:42 AM
#4
Frenzied Member
Re: BitBlt Problem
I do see that you are not selecting the old HGDIOBJ's into the dc. Which you would get at BeginScene and select back in at EndScene.
-
Apr 18th, 2005, 07:49 AM
#5
Thread Starter
G&G Moderator
Re: BitBlt Problem
Sorry but, for example..
Been a while,
Phreak
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Apr 18th, 2005, 12:11 PM
#6
Junior Member
Re: BitBlt Problem
Are you using Option Explicit?
Seems like the variables ww and wh are out of scope here. You've declared them in one function and are trying to use them in another.
VB Code:
Public Function BeginScene(hdc As Long) As Long
'Here we will initialize the WorldDC and paint it plain black
Dim hr As Long, vr As Long
Dim wh As Long, ww As Long 'world height and width '<-Local Scope
FormDC = hdc
hr = GetDeviceCaps(hdc, HORZRES)
vr = GetDeviceCaps(hdc, VERTRES)
'set them to how they should be
If (hr > 0) Then
ww = hr * 0.4
wh = vr * 0.15
End If
'set up our world
WorldDC = CreateCompatibleDC(hdc)
WorldBMP = CreateCompatibleBitmap(hdc, ww, wh)
SelectObject WorldDC, WorldBMP
'fill it with black
BitBlt WorldDC, 0, 0, ww, wh, 0, 0, 0, vbBlackness
End Function
Public Function UpdateScene() As Long
'blit the backbuffer to the screen
BitBlt FormDC, 0, 0, [B]ww[/B], [B]wh[/B], WorldDC, 0, 0, vbSrcCopy
End Function
You'll have to declare those variables with a little broader scope to use them across two functions.
If Option Explicit is not used, the undeclared variables will default to variants and coerced to a int or long type with a default value of zero.
-
Apr 18th, 2005, 09:27 PM
#7
Thread Starter
G&G Moderator
Re: BitBlt Problem
I've tried replacing those with say, 20 in both the BeginScene function and UpdateScene functions. It still doesn't work. I think it might be because I'm using it in a class and not in a plain module.
Anyone else know why it aint working?
Thanks in advance,
Phreak
Visual Studio 6, Visual Studio.NET 2005, MASM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|