Results 1 to 6 of 6

Thread: Drawing FASTER

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    81

    Question Drawing FASTER

    Im searching for the fastest way to draw a pixel and get a pixel:
    tried already Pset and Point, they were VERY slow.
    after that ive turned to an API solution: GetPixel SetPixelV,
    the GetPixel isnt much faster then Point but SetPixelV is faster by 50% then Pset (and Pset is MUCH faster then Line(x,y)-(x,y))
    but if i want to fill the whole screen with changing colors i have to find much faster solutions (it still takes about a minute to paint the whole screen)
    after some research ive found i can either use DirectDraw or use Pointers.
    ive encountered a problem using the pointer:
    VB Code:
    1. 'in the module:
    2. Option Explicit
    3.  
    4. Type SAFEARRAYBOUND
    5.     cElements As Long
    6.     lLbound As Long
    7. End Type
    8.  
    9. Type SAFEARRAY2D
    10.     cDims As Integer
    11.     fFeatures As Integer
    12.     cbElements As Long
    13.     cLocks As Long
    14.     pvData As Long
    15.     Bounds(0 To 1) As SAFEARRAYBOUND
    16. End Type
    17.  
    18. Type BITMAP
    19.     bmType As Long
    20.     bmWidth As Long
    21.     bmHeight As Long
    22.     bmWidthBytes As Long
    23.     bmPlanes As Integer
    24.     bmBitsPixel As Integer
    25.     bmBits As Long
    26. End Type
    27.  
    28. Declare Function VarPtrArray Lib "msvbvm50.dll" Alias "VarPtr" (Ptr() As Any) As Long
    29. Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
    30. Declare Function GetObjectAPI Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
    31.  
    32. Public pic() As Byte
    33. Public sa As SAFEARRAY2D
    34. Public bmp As BITMAP
    35. Public r As Long, g As Long, b As Long
    36.  
    37. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    38. 'on the form:
    39.  
    40. Private Sub Command1_Click()
    41. With sa
    42.     .cbElements = 1
    43.     .cDims = 2
    44.     .Bounds(0).lLbound = 0
    45.     .Bounds(0).cElements = bmp.bmHeight
    46.     .Bounds(1).lLbound = 0
    47.     .Bounds(1).cElements = bmp.bmWidthBytes
    48.     .pvData = bmp.bmBits
    49. End With
    50.  
    51. CopyMemory ByVal VarPtrArray(pic), VarPtrArray(sa), 4
    52.  
    53. For i = 0 To UBound(pic, 1) - 3 Step 3
    54.     For j = 0 To UBound(pic, 2)
    55.         r = pic(i + 2, j)
    56.         g = pic(i + 1, j)
    57.         b = pic(i, j)
    58.         r = ((g * b) \ 128)
    59.         g = ((r * b) \ 128)
    60.         b = ((r * g) \ 128)
    61.         If r > 255 Then r = 255
    62.         If r < 0 Then r = 0
    63.         If g > 255 Then g = 255
    64.         If g < 0 Then g = 0
    65.         If b > 255 Then b = 255
    66.         If b < 0 Then b = 0
    67.         pic(i, j) = b
    68.         pic(i + 1, j) = g
    69.         pic(i + 2, j) = r
    70.     Next j
    71. Next i
    72.  
    73. CopyMemory ByVal VarPtrArray(pic), 0&, 4
    74. Picture1.Refresh
    75. End Sub
    when i compile it says
    Compile error:
    Type mismatch: array or user defined type expected

    i have no idea of whats im doing wrong here....

    anyways ive tried to see how i do it in DDraw, but all the tutorials teach you only to initialize and use sprites...
    can anyone please help?
    (either find the error with the pointer or help me learn DDrwa)
    Pointer tutorial - on the bottom of the page

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    81

    oops, forgot to mantion

    after closing the compiler error massage the 'sa' from the line
    VB Code:
    1. CopyMemory ByVal VarPtrArray(pic), VarPtrArray(sa), 4
    2. 'overwriting 'pic()', with the 'sa' array.
    is being highlighted...

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    81
    nope, still doesnt work...
    btw can you help me drawing an array to the backbuffer with DX and bliting it to the surface within a window (without changing res and stuff)

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    81
    nope, still doesnt work... (i mean i dont get the error massage...
    ;-)
    it just crushes)
    btw, do you know how to work SetDIBits()
    and write to the backbuffer with DX then blit it to a window?

  5. #5
    Zaei
    Guest
    Nope (I use DX*, which doesnt support that functionality with any reasonable speed).

    Just make a new thread with that specific question.

    Z.

  6. #6
    Dreamlax
    Guest
    Since VB passes pointers to all API functions anyway, why not just use:

    VB Code:
    1. CopyMemory Destination(LBound(Destination)), Source(LBound(Source)), ArraySize


    Just a thought...

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