Announcement

Collapse
No announcement yet.

High Speed Graphics..

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • High Speed Graphics..

    I have been working on a high-speed graphic bitmap handler using PowerBasic. The purpose of this DLL is to eliminate the use of BitBlt, StretchBlt API Calls within a program I am writing. (SoftwareGame)

    I am using WinAPI to GetBitmapBits of any bitmaps I am using.. I have a screen (back-buffer) that I perform all my drawing on, and then use the SetBitmapBits afterwards...

    I have reduced the # of API calls from 20-40 down to 2. Everything else draws using pointers and data block copies..

    My problem is this: I am using the POKE$ Dest, PEEK$(Source, copy_size)
    command to block copy data. I keep getting a GP Fault.

    I am using a P266, WinNT and PowerBasic v1.1 (I know, I know.. I need to upgrade..) Here is a sample of my GFX_BitmapStorage routine.. Maybe someone can help me figure out what the problem is.. I know it crashes on the POKE command line because I out comments to a debug file as the code runs..


    Sub GFX_StoreBitmap (ByVal gPtr as DWORD, ByVal gType%, ByVal hBitmap as WORD, ByVal pWidth%, ByVal pHeight%)
    Dim array_count as Long, byte_count as Long, move_count%, page_count%
    Dim Source as STRING PTR, Dest as STRING PTR, Bmp as GraphicsIconType PTR
    Dim ok%, Size as DWORD, array_index as DWORD, x%, y$

    Bmp = gPtr
    array_count= pWidth% * pHeight%
    byte_count = array_count * 2
    Dim data(0:array_count) as WORD

    Size = GetBitmapBits (hBitmap, byte_count, data(0))
    page_count% = 1

    Call Debug ("e:\gfxdata.inf", "retrieve bits = "+str$(Size))

    While byte_count > 0
    If byte_count > 32750 Then
    move_count% = 32750
    Else
    move_count% = CINT(byte_count)
    End if
    byte_count = byte_count - move_count%

    Call Debug ("e:\gfxdata.inf", "page = "+str$(page_count%))
    Call Debug ("e:\gfxdata.inf", "moving = "+str$(move_count%))
    Call Debug ("e:\gfxdata.inf", "balance = "+str$(byte_count))

    Select Case gType%
    Case 0, 2
    If @Bmp.Icon2D.Icon.Page(page_count%) <> %NULL Then
    Call Debug ("e:\gfxdata.inf", "erasing pages..")
    For x% = 1 to 42
    If @Bmp.Icon2D.Icon.Page(x%) <> %NULL Then
    ok% = RlsStrAlloc(@Bmp.Icon2D.Icon.Page(x%))
    @Bmp.Icon2D.Icon.Page(x%) = %NULL
    End if
    Next x%
    End if
    @Bmp.Icon2D.Icon.Page(page_count%) = GetStrAlloc(move_count%)

    array_index = CDWD(((page_count% -1) * 32750)/2)
    Call Debug ("e:\gfxdata.inf", "array = "+str$(array_index))
    Source = VARPTR(data(array_index))
    Dest = @Bmp.Icon2D.Icon.Page(page_count%)

    Case 1
    If @Bmp.Icon2D.notIcon.Page(page_count%) <> %NULL Then
    For x% = 1 to 42
    If @Bmp.Icon2D.notIcon.Page(x%) <> %NULL Then
    ok% = RlsStrAlloc(@Bmp.Icon2D.notIcon.Page(x%))
    @Bmp.Icon2D.notIcon.Page(x%) = %NULL
    End if
    Next x%
    End if
    @Bmp.Icon2D.notIcon.Page(page_count%) = GetStrAlloc(move_count%)

    array_index = CDWD(((page_count% -1) * 32750)/2)
    Source = VARPTR(data(array_index))
    Dest = @Bmp.Icon2D.notIcon.Page(page_count%)
    End Select

    Call Debug ("e:\gfxdata.inf", "Source = "+str$(Source))
    Call Debug ("e:\gfxdata.inf", "Dest = "+str$(Dest))

    y$ =PEEK$(Source, move_count%)
    Call Debug ("e:\gfxdata.inf", "PEEK Worked!")
    POKE$ Dest, y$
    Call Debug ("e:\gfxdata.inf", "POKE Worked!")
    incr page_count%
    Wend
    End Sub


    The code is supposed to take any size bitmap (up to 1.5Megs) and break it into pages of 32K bytes in memory. Then with pointers (copy, paste, and trasnparent copy data to the GFX_Bitmap Pages FAST!) When all the work is done, call SetBitmapBits to refresh the visible window.

    The above routine is just a bitmap storage routine.. Its used to save an icon or character sprite into GFX format.. I use GetStrAlloc to make 32K memory pages, but when I copy the data from the data() to the memory allocated the program crashes..

    E

    -------------
    Explorations v3.0 RPG Development System
    http://www.explore-rpg.com
    Explorations v9.10 RPG Development System
    http://www.explore-rpg.com

  • #2
    From the 16-bit API helpfile:
    Code:
    LONG GetBitmapBits(hbm, cbBuffer, lpvBits)
      HBITMAP hbm;       /* handle of bitmap	*/
      LONG cbBuffer;     /* number of bytes to copy to buffer	*/
      void FAR* lpvBits; /* address of buffer for bitmap bits	*/
    In other words, try using VARPTR(Data(0)) instead of just Data(0).

    Comment


    • #3
      I use CopyMemeory it is fast and it is error free!
      Francis Beaulieu
      Prog senior of 17 years.
      Microsoft Specialist

      Comment


      • #4
        The code shows that "dest" is a string pointer, which means that you are trying to POKE a set of bytes into a string handle (which is the target of a string pointer).

        Because you already have a pointer, just use:
        Code:
        @dest = y$
        Easier?

        -------------
        Lance
        PowerBASIC Support
        ( mailto:[email protected][email protected]</A> )
        Lance
        mailto:[email protected]

        Comment


        • #5
          CopyMemory..

          Unfortunately I am in VB3.0, (haven't converted yet).. It doesn't have to command.


          VARPTR(Data(0))

          I will try that.. I got the routine to work, but when I GetBitmapBits, Windows returns some garbage characters in my data() array.. probably caused by the pointer.

          If anyone wants to see my project you can check out: http://www.explore-rpg.com

          Tyrone

          -------------
          Explorations v3.0 RPG Development System
          http://www.explore-rpg.com
          Explorations v9.10 RPG Development System
          http://www.explore-rpg.com

          Comment

          Working...
          X