Jump to content

OpenGL


trancexx
 Share

Recommended Posts

It was inevitable to happen sooner or later.

Two small examples:

Global Const $GL_VERSION_1_1 = 1
Global Const $PFD_TYPE_RGBA = 0
Global Const $PFD_MAIN_PLANE = 0
Global Const $PFD_DOUBLEBUFFER = 1
Global Const $PFD_DRAW_TO_WINDOW = 4
Global Const $PFD_SUPPORT_OPENGL = 32
Global Const $GL_PROJECTION = 0x1701
Global Const $GL_COLOR_BUFFER_BIT = 0x00004000
Global Const $GL_TRIANGLES = 0x0004



Global $gui = GUICreate("OpenGL", 250, 250)
GUISetBkColor(0x000000)
Global $dc
EnableOpenGL($gui, $dc)
glMatrixMode($GL_PROJECTION)
glViewport(0, 0, 250, 250)

GUISetState(@SW_SHOW)


While GUIGetMsg() <> -3
    
    glClear($GL_COLOR_BUFFER_BIT)

    glBegin($GL_TRIANGLES)

    glColor3f(0, 1, 0)
    glVertex3f(-.75, -.5, 0)

    glColor3f(1, 0, 0)
    glVertex3f(0, .75, 0)

    glColor3f(0, 0, 1)
    glVertex3f( .75, -.5, 0)

    glEnd()
    
    SwapBuffers($dc)
    
WEnd


Func EnableOpenGL($hwnd, ByRef $hDC)
    
    Local $pfd = DllStructCreate("short nSize;" & _
            "short nVersion;" & _
            "dword dwFlags;" & _
            "byte  iPixelType;" & _
            "byte  cColorBits;" & _
            "byte  cRedBits;" & _
            "byte  cRedShift;" & _
            "byte  cGreenBits;" & _
            "byte  cGreenShift;" & _
            "byte  cBlueBits;" & _
            "byte  cBlueShift;" & _
            "byte  cAlphaBits;" & _
            "byte  cAlphaShift;" & _
            "byte  cAccumBits;" & _
            "byte  cAccumRedBits;" & _
            "byte  cAccumGreenBits;" & _
            "byte  cAccumBlueBits;" & _
            "byte  cAccumAlphaBits;" & _
            "byte  cDepthBits;" & _
            "byte  cStencilBits;" & _
            "byte  cAuxBuffers;" & _
            "byte  iLayerType;" & _
            "byte  bReserved;" & _
            "dword dwLayerMask;" & _
            "dword dwVisibleMask;" & _
            "dword dwDamageMask;")

    Local $h_dc = DllCall("user32.dll", "hwnd", "GetDC", "hwnd", $hwnd)

    DllStructSetData($pfd, "nSize", DllStructGetSize($pfd))
    DllStructSetData($pfd, "nVersion", $GL_VERSION_1_1)
    DllStructSetData($pfd, "dwFlags", BitOR($PFD_DRAW_TO_WINDOW, $PFD_SUPPORT_OPENGL, $PFD_DOUBLEBUFFER))
    DllStructSetData($pfd, "iPixelType", $PFD_TYPE_RGBA)
    DllStructSetData($pfd, "cColorBits", 24)
    DllStructSetData($pfd, "cDepthBits", 16)
    DllStructSetData($pfd, "iLayerType", $PFD_MAIN_PLANE)

    DllOpen("gdi32.dll")
    DllOpen("opengl32.dll")

    Local $iFormat = DllCall("gdi32.dll", "int", "ChoosePixelFormat", "hwnd", $h_dc[0], "ptr", DllStructGetPtr($pfd))
    
    Local $iSetFormat = DllCall("gdi32.dll", "int", "SetPixelFormat", "hwnd", $h_dc[0], "int", $iFormat[0], "ptr", DllStructGetPtr($pfd))

    Local $h_cont = DllCall("opengl32.dll", "hwnd", "wglCreateContext", "hwnd", $h_dc[0])
    
    Local $iRet = DllCall("opengl32.dll", "int", "wglMakeCurrent", "int", $h_dc[0], "int", $h_cont[0])

    $hDC = $h_dc[0]
    
    Return 1 ; absolutley no error checking at this moment

EndFunc   ;==>EnableOpenGL


Func glBegin($mode)
    DllCall("opengl32.dll", "none", "glBegin", "uint", $mode)
EndFunc   ;==>glBegin


Func glClear($mask)
    DllCall("opengl32.dll", "none", "glClear", "uint", $mask)
EndFunc   ;==>glClear


Func glColor3f($red, $green, $blue)
    DllCall("opengl32.dll", "none", "glColor3f", "float", $red, "float", $green, "float", $blue)
EndFunc   ;==>glColor3f


Func glEnd()
    DllCall("opengl32.dll", "none", "glEnd")
EndFunc   ;==>glEnd


Func glMatrixMode($mode)
    DllCall("opengl32.dll", "none", "glMatrixMode", "uint", $mode)
EndFunc   ;==>glMatrixMode


Func glVertex3f($x, $y, $z)
    DllCall("opengl32.dll", "none", "glVertex3f", "float", $x, "float", $y, "float", $z)
EndFunc   ;==>glVertex3f


Func glViewport($x, $y, $width, $height)
    DllCall("opengl32.dll", "none", "glViewport", "int", $x, "int", $y, "int", $width, "int", $height)
EndFunc   ;==>glViewport


Func SwapBuffers($hDC)
    DllCall("gdi32.dll", "int", "SwapBuffers", "hwnd", $hDC)
EndFunc   ;==>SwapBuffers
Opt("GUIOnEventMode", 1)

Global Const $GL_VERSION_1_1 = 1
Global Const $PFD_TYPE_RGBA = 0
Global Const $PFD_MAIN_PLANE = 0
Global Const $PFD_DOUBLEBUFFER = 1
Global Const $PFD_DRAW_TO_WINDOW = 4
Global Const $PFD_SUPPORT_OPENGL = 32
Global Const $GL_PROJECTION = 0x1701
Global Const $GL_COLOR_BUFFER_BIT = 0x00004000
Global Const $GL_LINES = 0x0001


Global $gui = GUICreate("Simple OpenGL Example", 350, 350)
GUISetBkColor(0x000000)
GUISetOnEvent(-3, "Quit")

Global $dc
EnableOpenGL($gui, $dc)
glMatrixMode($GL_PROJECTION)
glViewport(0, 0, 350, 350)

GUISetState(@SW_SHOW)

Global $a, $m

While 1
    
    
    glViewport(0, 0, 400 - $a / 5, 400 - $a / 5)
    $a += 10
    If $a > 1750 Then $a = 0
    
    
    glClear($GL_COLOR_BUFFER_BIT)
    
    glPopMatrix()
    glPushMatrix()
        
    $m -= .5 
    glRotated($m, 0, 0, 1)
    
    glBegin($GL_LINES)
    
    glColor3f(0, 1, 0)
    glVertex2d(-.5, -.5)
    glColor3f(1, 0, 0)
    glVertex2d(-.5, .5)

    glColor3f(0, 1, 0)
    glVertex2d(-.5, -.5)
    glColor3f(1, 0, 0)
    glVertex2d(.75, -.5)

    glColor3f(1, 0, 0)
    glVertex2d(.75, -.5)
    glColor3f(0, 1, 0)
    glVertex2d(.75, .5)
    
    
    glColor3f(0, 1, 0)
    glVertex2d(.75, .5)
    glColor3f(1, 0, 0)
    glVertex2d(-.5, .5)
    glEnd()

    SwapBuffers($dc)
    
    Sleep(10)
    
WEnd


Func EnableOpenGL($hwnd, ByRef $hDC)
    
    Local $pfd = DllStructCreate("short nSize;" & _
            "short nVersion;" & _
            "dword dwFlags;" & _
            "byte  iPixelType;" & _
            "byte  cColorBits;" & _
            "byte  cRedBits;" & _
            "byte  cRedShift;" & _
            "byte  cGreenBits;" & _
            "byte  cGreenShift;" & _
            "byte  cBlueBits;" & _
            "byte  cBlueShift;" & _
            "byte  cAlphaBits;" & _
            "byte  cAlphaShift;" & _
            "byte  cAccumBits;" & _
            "byte  cAccumRedBits;" & _
            "byte  cAccumGreenBits;" & _
            "byte  cAccumBlueBits;" & _
            "byte  cAccumAlphaBits;" & _
            "byte  cDepthBits;" & _
            "byte  cStencilBits;" & _
            "byte  cAuxBuffers;" & _
            "byte  iLayerType;" & _
            "byte  bReserved;" & _
            "dword dwLayerMask;" & _
            "dword dwVisibleMask;" & _
            "dword dwDamageMask;")

    Local $h_dc = DllCall("user32.dll", "hwnd", "GetDC", "hwnd", $hwnd)

    DllStructSetData($pfd, "nSize", DllStructGetSize($pfd))
    DllStructSetData($pfd, "nVersion", $GL_VERSION_1_1)
    DllStructSetData($pfd, "dwFlags", BitOR($PFD_DRAW_TO_WINDOW, $PFD_SUPPORT_OPENGL, $PFD_DOUBLEBUFFER))
    DllStructSetData($pfd, "iPixelType", $PFD_TYPE_RGBA)
    DllStructSetData($pfd, "cColorBits", 24)
    DllStructSetData($pfd, "cDepthBits", 32)
    DllStructSetData($pfd, "iLayerType", $PFD_MAIN_PLANE)

    DllOpen("gdi32.dll")
    DllOpen("opengl32.dll")

    Local $iFormat = DllCall("gdi32.dll", "int", "ChoosePixelFormat", "hwnd", $h_dc[0], "ptr", DllStructGetPtr($pfd))
    
    Local $iSetFormat = DllCall("gdi32.dll", "int", "SetPixelFormat", "hwnd", $h_dc[0], "int", $iFormat[0], "ptr", DllStructGetPtr($pfd))

    Local $h_cont = DllCall("opengl32.dll", "hwnd", "wglCreateContext", "hwnd", $h_dc[0])
    
    Local $iRet = DllCall("opengl32.dll", "int", "wglMakeCurrent", "int", $h_dc[0], "int", $h_cont[0])

    $hDC = $h_dc[0]
    
    Return 1

EndFunc   ;==>EnableOpenGL


Func glColor3f($red, $green, $blue)
    DllCall("opengl32.dll", "none", "glColor3f", "float", $red, "float", $green, "float", $blue)
EndFunc   ;==>glColor3f


Func glVertex2d($x, $y)
    DllCall("opengl32.dll", "none", "glVertex2d", "double", $x, "double", $y)
EndFunc   ;==>glVertex2d

Func glClear($mask)
    DllCall("opengl32.dll", "none", "glClear", "uint", $mask)
EndFunc   ;==>glClear


Func glBegin($mode)
    DllCall("opengl32.dll", "none", "glBegin", "uint", $mode)
EndFunc   ;==>glBegin


Func glViewport($x, $y, $width, $height)
    DllCall("opengl32.dll", "none", "glViewport", "int", $x, "int", $y, "int", $width, "int", $height)
EndFunc   ;==>glViewport

Func glEnd()
    DllCall("opengl32.dll", "none", "glEnd")
EndFunc   ;==>glEnd


Func glMatrixMode($mode)
    DllCall("opengl32.dll", "none", "glMatrixMode", "uint", $mode)
EndFunc   ;==>glMatrixMode


Func glPopMatrix()
    DllCall("opengl32.dll", "none", "glPopMatrix")
EndFunc   ;==>glPopMatrix


Func glPushMatrix()
    DllCall("opengl32.dll", "none", "glPushMatrix")
EndFunc   ;==>glPushMatrix


Func glRotated($angle, $x, $y, $z)
    DllCall("opengl32.dll", "none", "glRotated", "double", $angle, "double", $x, "double", $y, "double", $z)
EndFunc   ;==>glRotated

Func SwapBuffers($hDC)
    DllCall("gdi32.dll", "int", "SwapBuffers", "hwnd", $hDC)
EndFunc   ;==>SwapBuffers


Func Quit()
    Exit
EndFunc

OpenGl contstants:

OpenGLconstants.au3

OpenGL functions: *

OpenGLfunctions.au3

Absolutley no error checking at this moment.

edit:

* 2nd July 2009 This is not reliable. You should check every used function with msdn or some other source. I found many mistakes I've made when writting it. Some functions are corrected and can be found in some other scripts I wrote on this subject. Search the forum.

Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Link to comment
Share on other sites

nice, specially first example

It can be rotated too:

Opt("GUIOnEventMode", 1)

Global Const $GL_VERSION_1_1 = 1
Global Const $PFD_TYPE_RGBA = 0
Global Const $PFD_MAIN_PLANE = 0
Global Const $PFD_DOUBLEBUFFER = 1
Global Const $PFD_DRAW_TO_WINDOW = 4
Global Const $PFD_SUPPORT_OPENGL = 32
Global Const $GL_PROJECTION = 0x1701
Global Const $GL_COLOR_BUFFER_BIT = 0x00004000
Global Const $GL_TRIANGLES = 0x0004

Global $gui = GUICreate("OpenGL Rotation", 250, 250)
GUISetBkColor(0x000000)
Global $dc
EnableOpenGL($gui, $dc)
glMatrixMode($GL_PROJECTION)
glViewport(0, 0, 250, 250)

GUISetState(@SW_SHOW)

GUISetOnEvent(-3, "Quit")

Global $m, $r, $timer = TimerInit()

While 1

    glClear($GL_COLOR_BUFFER_BIT)
    
    glPopMatrix()
    glPushMatrix()
        
    $m -= .1 ; 0.1
    glRotated($m, 0, 0, 1)

    glBegin($GL_TRIANGLES)

    glColor3f(0, 0, 1)
    glVertex3f(-.866, -.5, 0)

    glColor3f(1, 0, 0)
    glVertex3f(0, 1, 0)

    glColor3f(0, 1, 0)
    glVertex3f( .866, -.5, 0)

    glEnd()

    SwapBuffers($dc)
    
    Sleep(10)

WEnd



Func EnableOpenGL($hwnd, ByRef $hDC)

    Local $pfd = DllStructCreate("short nSize;" & _
            "short nVersion;" & _
            "dword dwFlags;" & _
            "byte  iPixelType;" & _
            "byte  cColorBits;" & _
            "byte  cRedBits;" & _
            "byte  cRedShift;" & _
            "byte  cGreenBits;" & _
            "byte  cGreenShift;" & _
            "byte  cBlueBits;" & _
            "byte  cBlueShift;" & _
            "byte  cAlphaBits;" & _
            "byte  cAlphaShift;" & _
            "byte  cAccumBits;" & _
            "byte  cAccumRedBits;" & _
            "byte  cAccumGreenBits;" & _
            "byte  cAccumBlueBits;" & _
            "byte  cAccumAlphaBits;" & _
            "byte  cDepthBits;" & _
            "byte  cStencilBits;" & _
            "byte  cAuxBuffers;" & _
            "byte  iLayerType;" & _
            "byte  bReserved;" & _
            "dword dwLayerMask;" & _
            "dword dwVisibleMask;" & _
            "dword dwDamageMask;")

    Local $h_dc = DllCall("user32.dll", "hwnd", "GetDC", "hwnd", $hwnd)
    

    DllStructSetData($pfd, "nSize", DllStructGetSize($pfd))
    DllStructSetData($pfd, "nVersion", $GL_VERSION_1_1)
    DllStructSetData($pfd, "dwFlags", BitOR($PFD_DRAW_TO_WINDOW, $PFD_SUPPORT_OPENGL, $PFD_DOUBLEBUFFER))
    DllStructSetData($pfd, "iPixelType", $PFD_TYPE_RGBA)
    DllStructSetData($pfd, "cColorBits", 24)
    DllStructSetData($pfd, "cDepthBits", 32)
    DllStructSetData($pfd, "iLayerType", $PFD_MAIN_PLANE)

    DllOpen("gdi32.dll")
    DllOpen("opengl32.dll")

    Local $iFormat = DllCall("gdi32.dll", "int", "ChoosePixelFormat", "hwnd", $h_dc[0], "ptr", DllStructGetPtr($pfd))

    Local $iSetFormat = DllCall("gdi32.dll", "int", "SetPixelFormat", "hwnd", $h_dc[0], "int", $iFormat[0], "ptr", DllStructGetPtr($pfd))

    Local $h_cont = DllCall("opengl32.dll", "hwnd", "wglCreateContext", "hwnd", $h_dc[0])

    Local $iRet = DllCall("opengl32.dll", "int", "wglMakeCurrent", "int", $h_dc[0], "int", $h_cont[0])

    $hDC = $h_dc[0]

    Return 1

EndFunc   ;==>EnableOpenGL


Func glClearColor($red, $green, $blue, $alpha)
    DllCall("opengl32.dll", "none", "glClearColor", "float", $red, "float", $green, "float", $blue, "float", $alpha)
EndFunc   ;==>glClearColor



Func glBegin($mode)
    DllCall("opengl32.dll", "none", "glBegin", "uint", $mode)
EndFunc   ;==>glBegin


Func glClear($mask)
    DllCall("opengl32.dll", "none", "glClear", "uint", $mask)
EndFunc   ;==>glClear


Func glColor3f($red, $green, $blue)
    DllCall("opengl32.dll", "none", "glColor3f", "float", $red, "float", $green, "float", $blue)
EndFunc   ;==>glColor3f


Func glEnd()
    DllCall("opengl32.dll", "none", "glEnd")
EndFunc   ;==>glEnd


Func glMatrixMode($mode)
    DllCall("opengl32.dll", "none", "glMatrixMode", "uint", $mode)
EndFunc   ;==>glMatrixMode


Func glPopMatrix()
    DllCall("opengl32.dll", "none", "glPopMatrix")
EndFunc   ;==>glPopMatrix


Func glPushMatrix()
    DllCall("opengl32.dll", "none", "glPushMatrix")
EndFunc   ;==>glPushMatrix


Func glRotated($angle, $x, $y, $z)
    DllCall("opengl32.dll", "none", "glRotated", "double", $angle, "double", $x, "double", $y, "double", $z)
EndFunc   ;==>glRotated


Func glVertex3f($x, $y, $z)
    DllCall("opengl32.dll", "none", "glVertex3f", "float", $x, "float", $y, "float", $z)
EndFunc   ;==>glVertex3f


Func glViewport($x, $y, $width, $height)
    DllCall("opengl32.dll", "none", "glViewport", "int", $x, "int", $y, "int", $width, "int", $height)
EndFunc   ;==>glViewport


Func SwapBuffers($hDC)
    DllCall("gdi32.dll", "int", "SwapBuffers", "hwnd", $hDC)
EndFunc   ;==>SwapBuffers

Func Quit()
    Exit
EndFunc

edit

Opt("GUIOnEventMode", 1) is much more appropriate

Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

I like your way to do it. Nice! :mellow:

Edit: five stars added

Edited by A. Percy

Só o que posso lhe dizer, bom é quando faz mal!My work:Au3Irrlicht - Irrlicht for AutoItMsAgentLib - An UDF for MSAgentAu3GlPlugin T2 - A 3D plugin for AutoIt...OpenGl Plugin - The old version of Au3GlPlugin.MAC Address Changer - Changes the MAC AddressItCopter - A dragonfly R/C helicopter simulator[center]VW Bug user[/center]Pinheiral (Pinewood) city: http://pt.wikipedia.org/wiki/Pinheiral

Link to comment
Share on other sites

Here are my learning, experimental examples.

I added some functions from glut32.dll to make things easier.

There is a lot more to learn.

Global Const $GL_VERSION_1_1 = 1
Global Const $PFD_TYPE_RGBA = 0
Global Const $PFD_MAIN_PLANE = 0
Global Const $PFD_DOUBLEBUFFER = 1
Global Const $PFD_DRAW_TO_WINDOW = 4
Global Const $PFD_SUPPORT_OPENGL = 32
Global Const $GL_PROJECTION = 0x1701
Global Const $GL_COLOR_BUFFER_BIT = 0x00004000
Global Const $GL_TRIANGLES = 0x0004
Global Const $GL_QUADS = 0x0007
Global Const $GL_DEPTH_BUFFER_BIT = 0x00000100
Global Const $GL_SCISSOR_TEST = 0x0C11


; ======== Example Moving Quad ==================
Global $gui = GUICreate("OpenGL - Example Moving Quad", 250, 250)
GUISetBkColor(0x000000)
Global $dc, $m = 0.005, $f = 0.005
EnableOpenGL($gui, $dc)
glMatrixMode($GL_PROJECTION)
glViewport(0, 0, 250, 250)
GUISetState(@SW_SHOW)
While (GUIGetMsg() <> -3) 
    glClear($GL_COLOR_BUFFER_BIT)
    glBegin($GL_QUADS)  
    If $m > (1.9999) Or $m < Abs(0.0049) Then $f *= -1
    $m = Mod(($m + $f) * 10, 20) / 10
    
    ;ConsoleWrite("$m = " & $m & "   $f = " & $f & @CRLF)
    glColor3f(0, 1, 0) ;Green
    
    glVertex4f(-.25, .3, 0.2, $m * .5 + .2) ; 0.5) ;
    ;glVertex4f(-.25, .3, 0.2, 0.5) ;$m*.5+.2) ;
    
    glColor3f(1, 0, 0) ; Red
    glVertex4f(-0.15, -$m * .1, 0.2, 0.2);-0.15, -.1, 0.2,0.2) ;
    ;glVertex4f(-0.15, -.1, 0.2,0.2) ;-0.15, -$m*.1, 0.2,0.2);

    glColor3f(0, 0, 1) ;Blue
    glVertex4f(0.7, -.6, 1, $m - .3) ; 1,1);

    glColor3f(1, 1, 0) ;Yellow
    glVertex4f($m / 2, .75, .5, 1.2) ; 0.5, .75, .5,1.2)$m/2, .75, .5,1.2) ;
    ;glVertex4f(0.5, .75, .5,1.2)
    
    glEnd()
    SwapBuffers($dc)
    
WEnd
GUIDelete($gui)

; ======= Example Three Rectangles ============
Global $gui = GUICreate("OpenGL - Example Three Rectangles", 750, 550)
GUISetBkColor(0x000000)
Global $dc, $m = 0.005, $f = 0.005
EnableOpenGL($gui, $dc)
glMatrixMode($GL_PROJECTION)
glViewport(0, 0, 750, 550)
GUISetState(@SW_SHOW)
While GUIGetMsg() <> -3 
    glClearColor(0.0, 0.0, 1.0, 0.0);
glClear($GL_COLOR_BUFFER_BIT);
; Now set scissor to smaller red sub region
glClearColor(1.0, 0.0, 0.0, 0.0);
glScissor(100, 100, 600, 400);
glEnable($GL_SCISSOR_TEST);
glClear($GL_COLOR_BUFFER_BIT);
; Finally, an even smaller green rectangle
glClearColor(0.0, 1.0, 0.0, 0.0);
glScissor(200, 200, 400, 200);
glClear($GL_COLOR_BUFFER_BIT);
; Turn scissor back off for next render
glDisable($GL_SCISSOR_TEST);
SwapBuffers($dc);
    Sleep(10)
WEnd
GUIDelete($gui)

;===== Example Rotating Sphere =======
Global $gui = GUICreate("OpenGL - Example Rotating Sphere", 350, 350)
GUISetBkColor(0x000000)
Global $dc, $m = 0.005, $f = 0.005
EnableOpenGL($gui, $dc)
glMatrixMode($GL_PROJECTION)
glViewport(0, 0, 250, 250)
GUISetState(@SW_SHOW)
While GUIGetMsg() <> -3 
    glClear($GL_COLOR_BUFFER_BIT)   
    glColor3f(1, 1, 1)
    glutSolidSphere(0.9, 20, 20)
    glColor3f(0, 0, 0)
    glutWireSphere(0.9, 20, 20) 
    $m = Mod($m + 0.001, 360)
    ;ConsoleWrite("$m  =  " & $m & @CRLF)
    glRotated($m, 1, 0, 1)
    SwapBuffers($dc)
    Sleep(10)
WEnd
GUIDelete($gui)

;===Example Solid Cube =====
Global $gui = GUICreate("OpenGL - Example Solid Cube", 750, 550)
GUISetBkColor(0x000000)
Global $dc, $m = 0.005, $f = 0.005
EnableOpenGL($gui, $dc)
glMatrixMode($GL_PROJECTION)
glViewport(0, 0, 750, 550)
GUISetState(@SW_SHOW)
While GUIGetMsg() <> -3 
    glClearColor(0.0, 0.0, 1.0, 0.0);
    glClear($GL_COLOR_BUFFER_BIT);
    ;glTranslatef(0.0, 1.0, 0.0);
    glColor3f(1, 1, 1)
    glutSolidCube(0.9)
    glColor3f(0, 0, 0)
    glutWireCube(0.9)
    $m = Mod($m + 0.001, 360)
    ;ConsoleWrite("$m  =  " & $m & @CRLF)
    glRotated($m, 1, 0, 1)
    SwapBuffers($dc);
    Sleep(10)
WEnd


Func EnableOpenGL($hwnd, ByRef $hDC)
    Local $pfd = DllStructCreate("short nSize;" & _
            "short nVersion;" & _
            "dword dwFlags;" & _
            "byte  iPixelType;" & _
            "byte  cColorBits;" & _
            "byte  cRedBits;" & _
            "byte  cRedShift;" & _
            "byte  cGreenBits;" & _
            "byte  cGreenShift;" & _
            "byte  cBlueBits;" & _
            "byte  cBlueShift;" & _
            "byte  cAlphaBits;" & _
            "byte  cAlphaShift;" & _
            "byte  cAccumBits;" & _
            "byte  cAccumRedBits;" & _
            "byte  cAccumGreenBits;" & _
            "byte  cAccumBlueBits;" & _
            "byte  cAccumAlphaBits;" & _
            "byte  cDepthBits;" & _
            "byte  cStencilBits;" & _
            "byte  cAuxBuffers;" & _
            "byte  iLayerType;" & _
            "byte  bReserved;" & _
            "dword dwLayerMask;" & _
            "dword dwVisibleMask;" & _
            "dword dwDamageMask;")

    Local $h_dc = DllCall("user32.dll", "hwnd", "GetDC", "hwnd", $hwnd)

    DllStructSetData($pfd, "nSize", DllStructGetSize($pfd))
    DllStructSetData($pfd, "nVersion", $GL_VERSION_1_1)
    DllStructSetData($pfd, "dwFlags", BitOR($PFD_DRAW_TO_WINDOW, $PFD_SUPPORT_OPENGL, $PFD_DOUBLEBUFFER))
    DllStructSetData($pfd, "iPixelType", $PFD_TYPE_RGBA)
    DllStructSetData($pfd, "cColorBits", 24)
    DllStructSetData($pfd, "cDepthBits", 16)
    DllStructSetData($pfd, "iLayerType", $PFD_MAIN_PLANE)

    DllOpen("gdi32.dll")
    DllOpen("opengl32.dll")
    DllOpen("glut32.dll")
    Local $iFormat = DllCall("gdi32.dll", "int", "ChoosePixelFormat", "hwnd", $h_dc[0], "ptr", DllStructGetPtr($pfd))
    Local $iSetFormat = DllCall("gdi32.dll", "int", "SetPixelFormat", "hwnd", $h_dc[0], "int", $iFormat[0], "ptr", DllStructGetPtr($pfd))
    Local $h_cont = DllCall("opengl32.dll", "hwnd", "wglCreateContext", "hwnd", $h_dc[0])
    Local $iRet = DllCall("opengl32.dll", "int", "wglMakeCurrent", "int", $h_dc[0], "int", $h_cont[0])
    $hDC = $h_dc[0]
    Return 1 ; absolutley no error checking at this moment
EndFunc   ;==>EnableOpenGL


Func glRotated($angle, $x, $y, $z)
    DllCall("opengl32.dll", "none", "glRotated", "double", $angle, "double", $x, "double", $y, "double", $z)
EndFunc   ;==>glRotated

Func glTranslatef($x, $y, $z)
    DllCall("opengl32.dll", "none", "glTranslatef", "float", $x, "float", $y, "float", $z)
EndFunc   ;==>glTranslatef

Func glDisable($cap)
    DllCall("opengl32.dll", "none", "glDisable", "uint", $cap)
EndFunc   ;==>glDisable

Func glEnable($cap)
    DllCall("opengl32.dll", "none", "glEnable", "uint", $cap)
EndFunc   ;==>glEnable

Func glScissor($x, $y, $width, $height)
    DllCall("opengl32.dll", "none", "glScissor", "int", $x, "int", $y, "int", $width, "int", $height)
EndFunc   ;==>glScissor

Func glClearColor($red, $green, $blue, $alpha)
    DllCall("opengl32.dll", "none", "glClearColor", "float", $red, "float", $green, "float", $blue, "float", $alpha)
EndFunc   ;==>glClearColor

Func glFlush()
    DllCall("opengl32.dll", "none", "glFlush")
EndFunc   ;==>glFlush

Func glutSwapBuffers($hDC)
    DllCall("glut32.dll", "long", "glutSwapBuffers", "hwnd", $hDC)
EndFunc   ;==>glutSwapBuffers

Func glutSolidCube($size)
    DllCall("glut32.dll", "none", "glutSolidCube", "double", $size)
EndFunc   ;==>glutSolidCube

Func glutWireCube($size)
    DllCall("glut32.dll", "none", "glutWireCube", "double", $size)
EndFunc   ;==>glutWireCube

Func glutWireSphere($radius, $slices, $stacks)
    DllCall("glut32.dll", "none", "glutWireSphere", "double", $radius, "long", $slices, "long", $stacks)
EndFunc   ;==>glutWireSphere

Func glutSolidSphere($radius, $slices, $stacks)
    DllCall("glut32.dll", "none", "glutSolidSphere", "double", $radius, "long", $slices, "long", $stacks)
EndFunc   ;==>glutSolidSphere

Func glVertex3d($x, $y, $z)
    DllCall("opengl32.dll", "none", "glVertex3d", "double", $x, "double", $y, "double", $z)
EndFunc   ;==>glVertex3d

Func glColor3ub($red, $green, $blue)
    DllCall("opengl32.dll", "none", "glColor3ub", "ubyte", $red, "ubyte", $green, "ubyte", $blue)
EndFunc   ;==>glColor3ub

Func glColor4f($red, $green, $blue, $alpha)
    DllCall("opengl32.dll", "none", "glColor4f", "float", $red, "float", $green, "float", $blue, "float", $alpha)
EndFunc   ;==>glColor4f

Func glVertex4f($x, $y, $z, $w)
    DllCall("opengl32.dll", "none", "glVertex4f", "float", $x, "float", $y, "float", $z, "float", $w)
EndFunc   ;==>glVertex4f

Func glBegin($mode)
    DllCall("opengl32.dll", "none", "glBegin", "uint", $mode)
EndFunc   ;==>glBegin

Func glClear($mask)
    DllCall("opengl32.dll", "none", "glClear", "uint", $mask)
EndFunc   ;==>glClear

Func glColor3f($red, $green, $blue)
    DllCall("opengl32.dll", "none", "glColor3f", "float", $red, "float", $green, "float", $blue)
EndFunc   ;==>glColor3f

Func glEnd()
    DllCall("opengl32.dll", "none", "glEnd")
EndFunc   ;==>glEnd

Func glMatrixMode($mode)
    DllCall("opengl32.dll", "none", "glMatrixMode", "uint", $mode)
EndFunc   ;==>glMatrixMode

Func glVertex3f($x, $y, $z)
    DllCall("opengl32.dll", "none", "glVertex3f", "float", $x, "float", $y, "float", $z)
EndFunc   ;==>glVertex3f

Func glViewport($x, $y, $width, $height)
    DllCall("opengl32.dll", "none", "glViewport", "int", $x, "int", $y, "int", $width, "int", $height)
EndFunc   ;==>glViewport

Func SwapBuffers($hDC)
    DllCall("gdi32.dll", "int", "SwapBuffers", "hwnd", $hDC)
EndFunc   ;==>SwapBuffers
Link to comment
Share on other sites

Here are my learning, experimental examples.

I added some functions from glut32.dll to make things easier.

There is a lot more to learn.

Nice examples.

glut32.dll is not standard windows dll. You should use glu32.dll and functions gluNewQuadric() and gluSphere() for spheres.

Opt("GUIOnEventMode", 1) should be used also to avoid cpu usage influence (gain "fluidity").

Why do you have glut32.dll on your system?

btw, glu functions --> must clean on exit?

edit:

How could we clean on exit?

Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

You need glut32.dll e.g download from http://www.dll-files.com/dllindex/pop.php?glut32

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

I'd recommend using functions for standard dlls.

glu32.dll can be used for rounds.

Opt("GUIOnEventMode", 1)

Global Const $GL_VERSION_1_1 = 1
Global Const $PFD_TYPE_RGBA = 0
Global Const $PFD_MAIN_PLANE = 0
Global Const $PFD_DOUBLEBUFFER = 1
Global Const $PFD_DRAW_TO_WINDOW = 4
Global Const $PFD_SUPPORT_OPENGL = 32
Global Const $GL_PROJECTION = 0x1701
Global Const $GL_COLOR_BUFFER_BIT = 0x00004000
Global Const $GL_DEPTH_BUFFER_BIT = 0x00000100


Global $gui = GUICreate("OpenGL", 350, 350)
GUISetBkColor(0xFFFFFF)

Global $dc
EnableOpenGL($gui, $dc)
glMatrixMode($GL_PROJECTION)
glViewport(0, 0, 350, 350)
glClear(BitOR($GL_COLOR_BUFFER_BIT, $GL_DEPTH_BUFFER_BIT)) ; initially cleaning buffers
GUISetState(@SW_SHOW)
GUISetOnEvent(-3, "Quit")

Global $h_quadric = gluNewQuadric()
Global $m = 3

While 1
    
    glClearColor(1, 1, 1, 1) ; background
    glClear($GL_COLOR_BUFFER_BIT)

    If $m > 50 Then $m = 3
    
    glColor3f(1, .4, .7)
    gluSphere($h_quadric, 0.75, $m, 20)
    
    SwapBuffers($dc)
    Sleep(100)
    $m += 1
    
WEnd



Func EnableOpenGL($hwnd, ByRef $hDC)
    
    Local $pfd = DllStructCreate("short nSize;" & _
            "short nVersion;" & _
            "dword dwFlags;" & _
            "byte  iPixelType;" & _
            "byte  cColorBits;" & _
            "byte  cRedBits;" & _
            "byte  cRedShift;" & _
            "byte  cGreenBits;" & _
            "byte  cGreenShift;" & _
            "byte  cBlueBits;" & _
            "byte  cBlueShift;" & _
            "byte  cAlphaBits;" & _
            "byte  cAlphaShift;" & _
            "byte  cAccumBits;" & _
            "byte  cAccumRedBits;" & _
            "byte  cAccumGreenBits;" & _
            "byte  cAccumBlueBits;" & _
            "byte  cAccumAlphaBits;" & _
            "byte  cDepthBits;" & _
            "byte  cStencilBits;" & _
            "byte  cAuxBuffers;" & _
            "byte  iLayerType;" & _
            "byte  bReserved;" & _
            "dword dwLayerMask;" & _
            "dword dwVisibleMask;" & _
            "dword dwDamageMask;")

    Local $h_dc = DllCall("user32.dll", "hwnd", "GetDC", "hwnd", $hwnd)

    DllStructSetData($pfd, "nSize", DllStructGetSize($pfd))
    DllStructSetData($pfd, "nVersion", $GL_VERSION_1_1)
    DllStructSetData($pfd, "dwFlags", BitOR($PFD_DRAW_TO_WINDOW, $PFD_SUPPORT_OPENGL, $PFD_DOUBLEBUFFER))
    DllStructSetData($pfd, "iPixelType", $PFD_TYPE_RGBA)
    DllStructSetData($pfd, "cColorBits", 24)
    DllStructSetData($pfd, "cDepthBits", 32)
    DllStructSetData($pfd, "iLayerType", $PFD_MAIN_PLANE)

    DllOpen("gdi32.dll")
    DllOpen("opengl32.dll")
    DllOpen("glu32.dll")
    
    Local $iFormat = DllCall("gdi32.dll", "int", "ChoosePixelFormat", "hwnd", $h_dc[0], "ptr", DllStructGetPtr($pfd))
    Local $iSetFormat = DllCall("gdi32.dll", "int", "SetPixelFormat", "hwnd", $h_dc[0], "int", $iFormat[0], "ptr", DllStructGetPtr($pfd))
    Local $h_cont = DllCall("opengl32.dll", "hwnd", "wglCreateContext", "hwnd", $h_dc[0])
    Local $iRet = DllCall("opengl32.dll", "int", "wglMakeCurrent", "int", $h_dc[0], "int", $h_cont[0])
    $hDC = $h_dc[0]
    
    Return 1
    
EndFunc   ;==>EnableOpenGL


Func glClear($mask)
    DllCall("opengl32.dll", "none", "glClear", "uint", $mask)
EndFunc   ;==>glClear

Func glClearColor($red, $green, $blue, $alpha)
    DllCall("opengl32.dll", "none", "glClearColor", "float", $red, "float", $green, "float", $blue, "float", $alpha)
EndFunc   ;==>glClearColor

Func gluNewQuadric()
    $h_qu = DllCall("glu32.dll", "hwnd", "gluNewQuadric")
    Return $h_qu[0]
EndFunc   ;==>gluNewQuadric

Func gluSphere($h_q, $radius, $slices, $stacks)
    DllCall("glu32.dll", "none", "gluSphere", "hwnd", $h_q, "double", $radius, "int", $slices, "int", $stacks)
EndFunc   ;==>gluSphere

Func glColor3f($red, $green, $blue)
    DllCall("opengl32.dll", "none", "glColor3f", "float", $red, "float", $green, "float", $blue)
EndFunc   ;==>glColor3f

Func glMatrixMode($mode)
    DllCall("opengl32.dll", "none", "glMatrixMode", "uint", $mode)
EndFunc   ;==>glMatrixMode

Func glViewport($x, $y, $width, $height)
    DllCall("opengl32.dll", "none", "glViewport", "int", $x, "int", $y, "int", $width, "int", $height)
EndFunc   ;==>glViewport

Func SwapBuffers($hDC)
    DllCall("gdi32.dll", "int", "SwapBuffers", "hwnd", $hDC)
EndFunc   ;==>SwapBuffers

Func Quit()
    Exit
EndFunc   ;==>Quit
Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

How do you call this? Sprinkler?

(Cleaning on exit and added monocereses $WM_PAINT that I read today)

#NoTrayIcon
Opt("GUIOnEventMode", 1)

Global Const $GL_VERSION_1_1 = 1
Global Const $PFD_TYPE_RGBA = 0
Global Const $PFD_MAIN_PLANE = 0
Global Const $PFD_DOUBLEBUFFER = 1
Global Const $PFD_DRAW_TO_WINDOW = 4
Global Const $PFD_SUPPORT_OPENGL = 32
Global Const $GL_PROJECTION = 0x1701
Global Const $GL_COLOR_BUFFER_BIT = 0x00004000
Global Const $GL_LINES = 0x0001
Global Const $GL_SRC_COLOR = 0x0300
Global Const $GL_DST_COLOR = 0x0306
Global Const $GL_BLEND = 0x0BE2
Global Const $GL_MODELVIEW = 0x1700
Global Const $GL_DEPTH_BUFFER_BIT = 0x00000100

Global $gui = GUICreate("OpenGL", 445, 445)

GUISetBkColor(0x000000)

Global $dc, $rc
EnableOpenGL($gui, $dc, $rc)
glClear(BitOR($GL_COLOR_BUFFER_BIT, $GL_DEPTH_BUFFER_BIT)) ; initially cleaning buffers
glBlendFunc($GL_SRC_COLOR, $GL_DST_COLOR)
glEnable($GL_BLEND)
glViewport(0, 0, 445, 445)

GUISetState(@SW_SHOW, $gui)
GUIRegisterMsg(0x000F, "Preserve"); $WM_PAINT

GUISetOnEvent(-3, "Quit")

Global $m


While 1
   
    GLDraw()
    $m += .0003
    Sleep(10)

WEnd


Func GLDraw()
   
    glClear(BitOR($GL_COLOR_BUFFER_BIT, $GL_DEPTH_BUFFER_BIT))
   
    glBegin($GL_LINES)
   
    For $i = 1 To 10
       
       $i += 2 * ($m > .08) + 3 * ($m > .1)
      
        If $m < .12 Then
            $s = Random(-9, 9, 1) / 32
            $t = Random(-9, 9, 1) / 35
           
            glColor3f(1, 0, 0)
            glVertex2d(-$m, -2 * $m)

            glColor3f(0, 1, 1)
            glVertex2d($s - $m, $t - 2 * $m)
           
            If Not Mod(1000 * $m, 35) Then
                glColor3f(1, 0, 0)
                glVertex2d(-$m, -2 * $m)

                glColor3f(0, 1, 1)
                glVertex2d(2 * $s - $m, 2 * $t - 2 * $m)
            EndIf
        EndIf
       
    Next
   
    glColor3f(1, .3, 0)
    glVertex2d(0, 0)
    glColor3f(0, 0, 1)
    glVertex2d(-.25, -.5)
   
    glEnd()
   
    SwapBuffers($dc)
   
EndFunc   ;==>GLDraw



Func EnableOpenGL($hwnd, ByRef $hDC, ByRef $hRC)

    Local $pfd = DllStructCreate("short nSize;" & _
            "short nVersion;" & _
            "dword dwFlags;" & _
            "byte  iPixelType;" & _
            "byte  cColorBits;" & _
            "byte  cRedBits;" & _
            "byte  cRedShift;" & _
            "byte  cGreenBits;" & _
            "byte  cGreenShift;" & _
            "byte  cBlueBits;" & _
            "byte  cBlueShift;" & _
            "byte  cAlphaBits;" & _
            "byte  cAlphaShift;" & _
            "byte  cAccumBits;" & _
            "byte  cAccumRedBits;" & _
            "byte  cAccumGreenBits;" & _
            "byte  cAccumBlueBits;" & _
            "byte  cAccumAlphaBits;" & _
            "byte  cDepthBits;" & _
            "byte  cStencilBits;" & _
            "byte  cAuxBuffers;" & _
            "byte  iLayerType;" & _
            "byte  bReserved;" & _
            "dword dwLayerMask;" & _
            "dword dwVisibleMask;" & _
            "dword dwDamageMask;")

    Local $h_dc = DllCall("user32.dll", "hwnd", "GetDC", "hwnd", $hwnd)
   

    DllStructSetData($pfd, "nSize", DllStructGetSize($pfd))
    DllStructSetData($pfd, "nVersion", $GL_VERSION_1_1)
    DllStructSetData($pfd, "dwFlags", BitOR($PFD_DRAW_TO_WINDOW, $PFD_SUPPORT_OPENGL, $PFD_DOUBLEBUFFER))
    DllStructSetData($pfd, "iPixelType", $PFD_TYPE_RGBA)
    DllStructSetData($pfd, "cColorBits", 24)
    DllStructSetData($pfd, "cDepthBits", 32)
    DllStructSetData($pfd, "iLayerType", $PFD_MAIN_PLANE)

    DllOpen("gdi32.dll")
    DllOpen("opengl32.dll")

    Local $iFormat = DllCall("gdi32.dll", "int", "ChoosePixelFormat", "hwnd", $h_dc[0], "ptr", DllStructGetPtr($pfd))

    Local $iSetFormat = DllCall("gdi32.dll", "int", "SetPixelFormat", "hwnd", $h_dc[0], "int", $iFormat[0], "ptr", DllStructGetPtr($pfd))

    Local $h_cont = DllCall("opengl32.dll", "hwnd", "wglCreateContext", "hwnd", $h_dc[0])

    Local $iRet = DllCall("opengl32.dll", "int", "wglMakeCurrent", "int", $h_dc[0], "int", $h_cont[0])

    $hDC = $h_dc[0]
    $hRC = $h_cont[0]
   
    Return 1

EndFunc   ;==>EnableOpenGL


Func glVertex2d($x, $y)
    DllCall("opengl32.dll", "none", "glVertex2d", "double", $x, "double", $y)
EndFunc   ;==>glVertex2d

Func glBegin($mode)
    DllCall("opengl32.dll", "none", "glBegin", "uint", $mode)
EndFunc   ;==>glBegin

Func glClear($mask)
    DllCall("opengl32.dll", "none", "glClear", "uint", $mask)
EndFunc   ;==>glClear

Func glColor3f($red, $green, $blue)
    DllCall("opengl32.dll", "none", "glColor3f", "float", $red, "float", $green, "float", $blue)
EndFunc   ;==>glColor3f

Func glEnd()
    DllCall("opengl32.dll", "none", "glEnd")
EndFunc   ;==>glEnd

Func glViewport($x, $y, $width, $height)
    DllCall("opengl32.dll", "none", "glViewport", "int", $x, "int", $y, "int", $width, "int", $height)
EndFunc   ;==>glViewport

Func glEnable($cap)
    DllCall("opengl32.dll", "none", "glEnable", "uint", $cap)
EndFunc   ;==>glEnable

Func glBlendFunc($sfactor, $dfactor)
    DllCall("opengl32.dll", "none", "glBlendFunc", "uint", $sfactor, "uint", $dfactor)
EndFunc   ;==>glBlendFunc

Func SwapBuffers($hDC)
    DllCall("gdi32.dll", "int", "SwapBuffers", "hwnd", $hDC)
EndFunc   ;==>SwapBuffers

Func Quit()
    DllCall("opengl32.dll", "int", "wglMakeCurrent", "int", 0, "int", 0)
    DllCall("opengl32.dll", "hwnd", "wglDeleteContext", "hwnd", $rc)
    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $gui, "hwnd", $dc)
    Exit
EndFunc   ;==>Quit

Func Preserve()
    SwapBuffers($dc)
EndFunc   ;==>Preserve

edit; corrected $WM_PAINT constant

Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

  • 3 months later...

This is really a nice library. I modified it and put the "EnableOpenGL" function into the "OpenGLfunctions.au3" file along with the "SwapBuffers" command because they were in the example scripts but you really need them no matter what. :) I also changed your rotating triangle a bit (just playing around with it really). I have it going up and down the rgb scale with r changing by 0.01, g changing by 0.001, and b changing by 0.005. Rather hypnotic. :)

Truly a great library/addon for AutoIt! ^_^

Edited by Enigma
Link to comment
Share on other sites

I was much "greener" when I wrote that. I just went through functions in OpenGLfunctions.au3 and saw that some of them are not correct. Ah, well... it happens :)

Now I would do that sparkler like this:

#NoTrayIcon
Opt("GUIOnEventMode", 1)

Global Const $GL_VERSION_1_1 = 1
Global Const $PFD_TYPE_RGBA = 0
Global Const $PFD_MAIN_PLANE = 0
Global Const $PFD_DOUBLEBUFFER = 1
Global Const $PFD_DRAW_TO_WINDOW = 4
Global Const $PFD_SUPPORT_OPENGL = 32
Global Const $GL_PROJECTION = 0x1701
Global Const $GL_COLOR_BUFFER_BIT = 0x00004000
Global Const $GL_LINES = 0x0001
Global Const $GL_SRC_COLOR = 0x0300
Global Const $GL_DST_COLOR = 0x0306
Global Const $GL_BLEND = 0x0BE2
Global Const $GL_MODELVIEW = 0x1700
Global Const $GL_DEPTH_BUFFER_BIT = 0x00000100

Global $hGUI = GUICreate("OpenGL Sparkler", 445, 445)

GUISetBkColor(0x000000)

Global $hDC, $hRC ; device context and rendering context

If Not _EnableOpenGL($hGUI, $hDC, $hRC) Then
    MsgBox(48, "Error", "Error initializing usage of OpenGL functions" & @CRLF & "Error code: " & @error)
    Exit
EndIf

_glClear(BitOR($GL_COLOR_BUFFER_BIT, $GL_DEPTH_BUFFER_BIT)) ; initially cleaning buffers in case something is left there
_glEnable($GL_BLEND)
_glBlendFunc($GL_SRC_COLOR, $GL_DST_COLOR)
_glViewport(0, 0, 445, 445)

GUIRegisterMsg(133, "_Preserve") ; WM_NCPAINT
GUISetOnEvent(-3, "_Quit") ; on exit

GUISetState(@SW_SHOW, $hGUI)

Global $m

While 1

    _GLDraw()
    $m += .0003
    Sleep(10)

WEnd




Func _GLDraw()

    _glClear(BitOR($GL_COLOR_BUFFER_BIT, $GL_DEPTH_BUFFER_BIT)) ; cleaning buffers

    _glBegin($GL_LINES) ; gonna draw lines

    For $i = 1 To 10

        $i += 2 * ($m > .08) + 3 * ($m > .1) ; blowing out 
        $m *= ($m < .14) ; looping

        If $m < .12 Then
            $s = Random(-9, 9, 1) / 32
            $t = Random(-9, 9, 1) / 35

            _glColor3f(1, 0, 0) ; begin with this color
            _glVertex2d(-$m, -2 * $m) ; start line here

            _glColor3f(0, 1, 1) ; end with this color
            _glVertex2d($s - $m, $t - 2 * $m) ; end line here

            If Not Mod(1000 * $m, 35) Then ; few flashes to make it more real
                _glColor3f(1, 0, 0) ; begin with this color
                _glVertex2d(-$m, -2 * $m) ; start line here

                _glColor3f(0, 1, 1) ; end with this color
                _glVertex2d(2 * $s - $m, 2 * $t - 2 * $m) ; end line here
            EndIf
        EndIf

    Next

    _glColor3f(1, .3, 0) ; stick color on the one side
    _glVertex2d(0, 0) ; stick starts here
    _glColor3f(0, 0, 1) ; stick color on the other side
    _glVertex2d(-.25, -.5) ; stick ends here

    _glEnd() ; end drawing

    _SwapBuffers($hDC) ; "refresh"

EndFunc   ;==>_GLDraw



Func _EnableOpenGL($hWnd, ByRef $hDeviceContext, ByRef $hOpenGLRenderingContext)

    Local $tPIXELFORMATDESCRIPTOR = DllStructCreate("ushort Size;" & _
            "ushort Version;" & _
            "dword Flags;" & _
            "ubyte PixelType;" & _
            "ubyte ColorBits;" & _
            "ubyte RedBits;" & _
            "ubyte RedShift;" & _
            "ubyte GreenBits;" & _
            "ubyte GreenShift;" & _
            "ubyte BlueBits;" & _
            "ubyte BlueShift;" & _
            "ubyte AlphaBits;" & _
            "ubyte AlphaShift;" & _
            "ubyte AccumBits;" & _
            "ubyte AccumRedBits;" & _
            "ubyte AccumGreenBits;" & _
            "ubyte AccumBlueBits;" & _
            "ubyte AccumAlphaBits;" & _
            "ubyte DepthBits;" & _
            "ubyte StencilBits;" & _
            "ubyte AuxBuffers;" & _
            "ubyte LayerType;" & _
            "ubyte Reserved;" & _
            "dword LayerMask;" & _
            "dword VisibleMask;" & _
            "dword DamageMask")

    DllStructSetData($tPIXELFORMATDESCRIPTOR, "Size", DllStructGetSize($tPIXELFORMATDESCRIPTOR))
    DllStructSetData($tPIXELFORMATDESCRIPTOR, "Version", $GL_VERSION_1_1)
    DllStructSetData($tPIXELFORMATDESCRIPTOR, "Flags", BitOR($PFD_DRAW_TO_WINDOW, $PFD_SUPPORT_OPENGL, $PFD_DOUBLEBUFFER))
    DllStructSetData($tPIXELFORMATDESCRIPTOR, "PixelType", $PFD_TYPE_RGBA)
    DllStructSetData($tPIXELFORMATDESCRIPTOR, "ColorBits", 24)
    DllStructSetData($tPIXELFORMATDESCRIPTOR, "DepthBits", 32)
    DllStructSetData($tPIXELFORMATDESCRIPTOR, "LayerType", $PFD_MAIN_PLANE)

    Local $a_hCall = DllCall("kernel32.dll", "hwnd", "GetModuleHandleW", "wstr", "opengl32.dll")
    If @error Then
        Return SetError(1, 0, 0) ; what???
    EndIf

    If Not $a_hCall[0] Then
        If DllOpen("opengl32.dll") = -1 Then
            Return SetError(2, 0, 0) ; could not open opengl32.dll
        EndIf
    EndIf

    $a_hCall = DllCall("user32.dll", "hwnd", "GetDC", "hwnd", $hWnd)

    If @error Or Not $a_hCall[0] Then
        Return SetError(3, 0, 0) ; could not retrieve a handle to a device context
    EndIf

    $hDeviceContext = $a_hCall[0]

    Local $a_iCall = DllCall("gdi32.dll", "int", "ChoosePixelFormat", "hwnd", $hDeviceContext, "ptr", DllStructGetPtr($tPIXELFORMATDESCRIPTOR))
    If @error Or Not $a_iCall[0] Then
        Return SetError(4, 0, 0) ; could not match an appropriate pixel format
    EndIf
    Local $iFormat = $a_iCall[0]

    $a_iCall = DllCall("gdi32.dll", "int", "SetPixelFormat", "hwnd", $hDeviceContext, "int", $iFormat, "ptr", DllStructGetPtr($tPIXELFORMATDESCRIPTOR))
    If @error Or Not $a_iCall[0] Then
        Return SetError(5, 0, 0) ; could not set the pixel format of the specified device context to the specified format
    EndIf

    $a_hCall = DllCall("opengl32.dll", "hwnd", "wglCreateContext", "hwnd", $hDeviceContext)
    If @error Or Not $a_hCall[0] Then
        Return SetError(6, 0, 0) ; could not create a rendering context
    EndIf

    $hOpenGLRenderingContext = $a_hCall[0]

    $a_iCall = DllCall("opengl32.dll", "int", "wglMakeCurrent", "hwnd", $hDeviceContext, "hwnd", $hOpenGLRenderingContext)
    If @error Or Not $a_iCall[0] Then
        Return SetError(7, 0, 0) ; failed to make the specified rendering context the calling thread's current rendering context
    EndIf

    Return SetError(0, 0, 1) ; all OK!

EndFunc   ;==>_EnableOpenGL



Func _DisableOpenGL($hWnd, $hDeviceContext, $hOpenGLRenderingContext)

    ; No point in doing error checking if this is done on exit. Will just call the cleaning functions.

    DllCall("opengl32.dll", "int", "wglMakeCurrent", "hwnd", $hDeviceContext, "hwnd", 0)
    DllCall("opengl32.dll", "int", "wglDeleteContext", "hwnd", $hOpenGLRenderingContext)
    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $hWnd, "hwnd", $hDeviceContext)
    DllCall("gdi32.dll", "int", "DeleteDC", "hwnd", $hDeviceContext)

EndFunc   ;==>_DisableOpenGL



Func _glVertex2d($x, $y)
    DllCall("opengl32.dll", "none", "glVertex2d", "double", $x, "double", $y)
EndFunc   ;==>_glVertex2d


Func _glBegin($mode)
    DllCall("opengl32.dll", "none", "glBegin", "dword", $mode)
EndFunc   ;==>_glBegin


Func _glClear($mask)
    DllCall("opengl32.dll", "none", "glClear", "dword", $mask)
EndFunc   ;==>_glClear


Func _glColor3f($red, $green, $blue)
    DllCall("opengl32.dll", "none", "glColor3f", "float", $red, "float", $green, "float", $blue)
EndFunc   ;==>_glColor3f


Func _glEnd()
    DllCall("opengl32.dll", "none", "glEnd")
EndFunc   ;==>_glEnd


Func _glViewport($x, $y, $width, $height)
    DllCall("opengl32.dll", "none", "glViewport", "int", $x, "int", $y, "int", $width, "int", $height)
EndFunc   ;==>_glViewport


Func _glEnable($cap)
    DllCall("opengl32.dll", "none", "glEnable", "dword", $cap)
EndFunc   ;==>_glEnable


Func _glBlendFunc($sfactor, $dfactor)
    DllCall("opengl32.dll", "none", "glBlendFunc", "uint", $sfactor, "dword", $dfactor)
EndFunc   ;==>_glBlendFunc


Func _SwapBuffers($hDC)
    DllCall("gdi32.dll", "int", "SwapBuffers", "hwnd", $hDC)
EndFunc   ;==>_SwapBuffers


Func _Preserve()
    _SwapBuffers($hDC)
EndFunc   ;==>_Preserve


Func _Quit()
    _DisableOpenGL($hGUI, $hDC, $hRC)
    Exit
EndFunc

I would love to see more examples and new OpenGLfunctions.au3

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

  • 4 months later...

Thank you! I'm planning to rewrite one of my apps from GDI to OpenGL.

Is there a reason for you not to preload DLLs? (makes it run MUCH faster)

Like so:

Global $g=DllOpen("gdi32.dll")
Global $o=DllOpen("opengl32.dll")

Func glColor3f($red, $green, $blue)
    DllCall($o, "none", "glColor3f", "float", $red, "float", $green, "float", $blue)
EndFunc  ;==>glColor3f


Func glVertex2d($x, $y)
    DllCall($o, "none", "glVertex2d", "double", $x, "double", $y)
EndFunc  ;==>glVertex2d

Func glClear($mask)
    DllCall($o, "none", "glClear", "uint", $mask)
EndFunc  ;==>glClear


Func glBegin($mode)
    DllCall($o, "none", "glBegin", "uint", $mode)
EndFunc  ;==>glBegin


Func glViewport($x, $y, $width, $height)
    DllCall($o, "none", "glViewport", "int", $x, "int", $y, "int", $width, "int", $height)
EndFunc  ;==>glViewport

Func glEnd()
    DllCall($o, "none", "glEnd")
EndFunc  ;==>glEnd


Func glMatrixMode($mode)
    DllCall($o, "none", "glMatrixMode", "uint", $mode)
EndFunc  ;==>glMatrixMode


Func glPopMatrix()
    DllCall($o, "none", "glPopMatrix")
EndFunc  ;==>glPopMatrix


Func glPushMatrix()
    DllCall($o, "none", "glPushMatrix")
EndFunc  ;==>glPushMatrix


Func glRotated($angle, $x, $y, $z)
    DllCall($o, "none", "glRotated", "double", $angle, "double", $x, "double", $y, "double", $z)
EndFunc  ;==>glRotated

Func SwapBuffers($hDC)
    DllCall($g, "int", "SwapBuffers", "hwnd", $hDC)
EndFunc  ;==>SwapBuffers
Link to comment
Share on other sites

Thank you! I'm planning to rewrite one of my apps from GDI to OpenGL.

Is there a reason for you not to preload DLLs? (makes it run MUCH faster)

...

Modules are 'preloaded'.

You mean why am I not passing 'handles' to DllCall() functions. Is that it?

If you can demonstrate the difference in speed (or any else) I be willing to.

I don't like introducing global variables from within UDFs nor for them.

Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

What about DirectX? Is that also possible to use with AutoIt? :)

I didn't find any code snippet using DirectX :)

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Modules are 'preloaded'.

You mean why am I not passing 'handles' to DllCall() functions. Is that it?

If you can demonstrate the difference in speed (or any else) I be willing to.

I don't like introducing global variables from within UDFs nor for them.

I am not sure if it practical or better but its a bit faster. I ran the code from post#16 both methods. "passing handles" turns out to be 2-8 times faster. I know Globals are tricky from time too time but its worth it in some cases. Edited by dexto
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...