Results 1 to 7 of 7

Thread: BitBlt Problem

  1. #1

    Thread Starter
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    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:
    1. Dim WorldDC As Long
    2. Dim WorldBMP As Long
    3. Dim FormDC As Long
    4. Dim WorldRegions() As Long
    5. Dim num_regions As Long
    6.  
    7. Private Function Initialize()
    8.  
    9. End Function
    10.  
    11. Public Function BeginScene(hdc As Long) As Long
    12. 'Here we will initialize the WorldDC and paint it plain black
    13. Dim hr As Long, vr As Long
    14. Dim wh As Long, ww As Long 'world height and width
    15.  
    16. FormDC = hdc
    17.  
    18. hr = GetDeviceCaps(hdc, HORZRES)
    19. vr = GetDeviceCaps(hdc, VERTRES)
    20.  
    21. 'set them to how they should be
    22. If (hr > 0) Then
    23.     ww = hr * 0.4
    24.     wh = vr * 0.15
    25. End If
    26.  
    27. 'set up our world
    28. WorldDC = CreateCompatibleDC(hdc)
    29. WorldBMP = CreateCompatibleBitmap(hdc, ww, wh)
    30. SelectObject WorldDC, WorldBMP
    31. 'fill it with black
    32. BitBlt WorldDC, 0, 0, ww, wh, 0, 0, 0, vbBlackness
    33.  
    34. End Function
    35.  
    36. Public Function UpdateScene() As Long
    37. 'blit the backbuffer to the screen
    38. BitBlt FormDC, 0, 0, ww, wh, WorldDC, 0, 0, vbSrcCopy
    39. End Function
    40.  
    41. Public Function EndScene() As Long
    42. 'delete the memory users
    43. DeleteDC WorldDC
    44. DeleteObject WorldBMP
    45. End Function
    46.  
    47. Private Function Terminate()
    48. 'Delete the memory users
    49. DeleteDC WorldDC
    50. DeleteObject WorldBMP
    51. 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

  2. #2
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037

    Re: BitBlt Problem

    Just use FillRect (win api) instead of BitBlt if you just want to fill the screen with a certain color (black).

  3. #3

    Thread Starter
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    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

  4. #4
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037

    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.

  5. #5

    Thread Starter
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: BitBlt Problem

    Sorry but, for example..

    Been a while,

    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  6. #6
    Junior Member noi_max's Avatar
    Join Date
    Jul 2004
    Location
    Portland OR
    Posts
    18

    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:
    1. Public Function BeginScene(hdc As Long) As Long
    2.  
    3.    'Here we will initialize the WorldDC and paint it plain black
    4.    Dim hr As Long, vr As Long
    5.    
    6.    Dim wh As Long, ww As Long 'world height and width  '<-Local Scope
    7.    FormDC = hdc
    8.    
    9.    hr = GetDeviceCaps(hdc, HORZRES)
    10.    vr = GetDeviceCaps(hdc, VERTRES)
    11.    
    12.    'set them to how they should be
    13.    If (hr > 0) Then
    14.        ww = hr * 0.4
    15.        wh = vr * 0.15
    16.    End If
    17.    
    18.    'set up our world
    19.    WorldDC = CreateCompatibleDC(hdc)
    20.    WorldBMP = CreateCompatibleBitmap(hdc, ww, wh)
    21.    SelectObject WorldDC, WorldBMP
    22.    'fill it with black
    23.    BitBlt WorldDC, 0, 0, ww, wh, 0, 0, 0, vbBlackness
    24.  
    25. End Function
    26.  
    27. Public Function UpdateScene() As Long
    28.  
    29.    'blit the backbuffer to the screen
    30.    BitBlt FormDC, 0, 0, [B]ww[/B], [B]wh[/B], WorldDC, 0, 0, vbSrcCopy
    31.  
    32. 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.

  7. #7

    Thread Starter
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    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
  •  



Click Here to Expand Forum to Full Width