Jump to content

double buffer in gdi+


oMBRa
 Share

Recommended Posts

what's wrong with this then:

#include <GUIConstants.au3>
#include <GDIplus.au3>

Global Const $width=600
Global Const $height=400
GLobal $title="GDI+"
Global $aPoints[4][2]
; Build your GUI here
Opt("GUIOnEventMode",1)
$hwnd=GUICreate($title,$width,$height)
GUISetOnEvent($GUI_EVENT_CLOSE,"close")
GUISetState()

; Load your GDI+ resources here:
_GDIPlus_Startup()
$graphics=_GDIPlus_GraphicsCreateFromHWND($hwnd)
$bitmap=_GDIPlus_BitmapCreateFromGraphics($width,$height,$graphics)
$backbuffer=_GDIPlus_ImageGetGraphicsContext($bitmap)
$Pen = _GDIPlus_PenCreate(0xFF00FF00, 5,  2)

Do
    _GDIPlus_GraphicsClear($backbuffer)
    
  ; Draw your GDI+ scene onto $backbuffer here
    
   
    $aPoints[0][0] = 3
    $aPoints[1][0] = 150
    $aPoints[1][1] = 150
    $aPoints[2][0] = 200
    $aPoints[2][1] = 100
    $aPoints[3][0] = 250
    $aPoints[3][1] = 150

    _GDIPlus_GraphicsDrawPolygon ($backbuffer, $aPoints, $Pen)

    Sleep(10)
Until False
Link to comment
Share on other sites

Why did you remove _GDIPlus_GraphicsDrawImageRect at the end of the loop?

Funky fun with polygons (and no flickering). Nice demo, monoceres:
#include <GUIConstants.au3>
#include <GDIplus.au3>

HotKeySet("{ESC}", "_Quit")

Global Const $width=600
Global Const $height=400
GLobal $title="GDI+"
Global $aPoints[4][2]
    $aPoints[0][0] = 3
    $aPoints[1][0] = 150
    $aPoints[1][1] = 150
    $aPoints[2][0] = 200
    $aPoints[2][1] = 100
    $aPoints[3][0] = 250
    $aPoints[3][1] = 150

; Build your GUI here
Opt("GUIOnEventMode",1)
$hwnd=GUICreate($title,$width,$height)
GUISetOnEvent($GUI_EVENT_CLOSE,"close")
GUISetState()

; Load your GDI+ resources here:
_GDIPlus_Startup()
$graphics=_GDIPlus_GraphicsCreateFromHWND($hwnd)
$bitmap=_GDIPlus_BitmapCreateFromGraphics($width,$height,$graphics)
$backbuffer=_GDIPlus_ImageGetGraphicsContext($bitmap)
$Pen = _GDIPlus_PenCreate(0xFF00FF00, 5,  2)

Do
    _GDIPlus_GraphicsClear($backbuffer)
    
  ; Draw your GDI+ scene onto $backbuffer here
    For $n = 1 To 3
        $aPoints[$n][0] -= 1
        If $aPoints[$n][0] < 0 Then $aPoints[$n][0] = $width
        $aPoints[$n][1] += 1
        If $aPoints[$n][1] > $height Then $aPoints[$n][1] = 0
    Next
    _GDIPlus_GraphicsDrawPolygon ($backbuffer, $aPoints, $Pen)
    _GDIPlus_GraphicsDrawImageRect($graphics,$bitmap,0,0,$width,$height)
    Sleep(10)
Until False

Func close()
    _GDIPlus_GraphicsDispose($backbuffer)
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_GraphicsDispose($graphics)
    _GDIPlus_Shutdown()
    Exit
EndFunc

Func _Quit()
    close()
    Exit
EndFunc

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Funky fun with polygons (and no flickering). Nice demo, monoceres:

:)

Heh great stuff PsaltyDS :)

I decided to play a bit myself o:)

#include <GUIConstantsEx.au3>
#include <GDIplus.au3>



Global Const $width = 600
Global Const $height = 400
Global Const $pi = 3.14
Global $title = "GDI+"
Global $aPoints[4][2]


; Build your GUI here
Opt("GUIOnEventMode", 1)
$hwnd = GUICreate($title, $width, $height)
GUISetOnEvent($GUI_EVENT_CLOSE, "close")
GUISetState()

; Load your GDI+ resources here:
_GDIPlus_Startup()
$graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
$bitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $graphics)
$backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)


$brush = _GDIPlus_BrushCreateSolid(0x0C000000)

_AntiAlias($backbuffer, 4)
$inc = 0

Global $Polygon_Size = Random(80, 120, 1)
Global $Polygon_X = Random(0, $width - $Polygon_Size, 1)
Global $Polygon_Y = Random(0, $height - $Polygon_Size, 1)

Global $Polygon_Xdir = 1
Global $Polygon_ydir = 1

Global $x1, $x2, $x3, $y1, $y2, $y3

Global $Polygon_Speed = 1.2

_GDIPlus_GraphicsClear($backbuffer)
Do
    $inc += 0.02
    _GDIPlus_GraphicsFillRect($backbuffer, 0, 0, $width, $height, $brush)
    
    $Polygon_X += $Polygon_Xdir
    $Polygon_Y += $Polygon_ydir
    
    $Polygon_Size = 0.5 * (Cos($inc / 1.5) + 1) * 100 + 50
    
    
    $red = ((Sin(1 * $inc / 1) + 1) / 2) * 256
    $green = ((Sin(2 * $inc / 1) + 1) / 2) * 256
    $blue = ((Sin(3 * $inc / 1) + 1) / 2) * 256
    
    $Pen = _GDIPlus_PenCreate("0xFF" & Hex($red, 2) & Hex($green, 2) & Hex($blue, 2), 3)
    
    $x1 = Cos($inc * $Polygon_Speed) * $Polygon_Size + $Polygon_X
    $y1 = Sin($inc * $Polygon_Speed) * $Polygon_Size + $Polygon_Y
    
    $x2 = Cos($inc * $Polygon_Speed + 2 * $pi / 3) * $Polygon_Size + $Polygon_X
    $y2 = Sin($inc * $Polygon_Speed + 2 * $pi / 3) * $Polygon_Size + $Polygon_Y
    
    $x3 = Cos($inc * $Polygon_Speed + 4 * $pi / 3) * $Polygon_Size + $Polygon_X
    $y3 = Sin($inc * $Polygon_Speed + 4 * $pi / 3) * $Polygon_Size + $Polygon_Y

    
    $aPoints[0][0] = 3
    $aPoints[1][0] = $x1
    $aPoints[1][1] = $y1
    $aPoints[2][0] = $x2
    $aPoints[2][1] = $y2
    $aPoints[3][0] = $x3
    $aPoints[3][1] = $y3
    
    
    
    For $i = 1 To $aPoints[0][0]
        If $aPoints[$i][1] >= $height Then
            $Polygon_ydir = -1
        ElseIf $aPoints[$i][1] <= 0 Then
            ConsoleWrite("meh!" & @CRLF)
            $Polygon_ydir = 1
        EndIf
        
        If $aPoints[$i][0] >= $width Then
            $Polygon_Xdir = -1
        ElseIf $aPoints[$i][0] <= 0 Then
            $Polygon_Xdir = 1
        EndIf
        
        
    Next
    

    _GDIPlus_GraphicsDrawPolygon($backbuffer, $aPoints, $Pen)
    _GDIPlus_PenDispose($Pen)
    
    _GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, $width, $height)
    Sleep(10)
Until False



Func close()
    _GDIPlus_BrushDispose($brush)
    _GDIPlus_GraphicsDispose($backbuffer)
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_GraphicsDispose($graphics)
    _GDIPlus_Shutdown()
    Exit
EndFunc ;==>close



Func _AntiAlias($hGraphics, $mode)
    Local $aResult
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetSmoothingMode", "hwnd", $hGraphics, "int", $mode)
    If @error Then Return SetError(@error, @extended, False)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc ;==>_AntiAlias

;)

Edited by monoceres

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

Hey thats pretty nice. It only flickered once in a while. Is it true that you can double buffer faster using _WinAPI_BitBlt?

I have no idea. I usually don't like mixing GDI and GDI+ but that might actually be faster :)

I'll test later (if you're not faster)

:)

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...