Jump to content

OpenGL


trancexx
 Share

Recommended Posts

Thanx for nice example 3D_Rotation_Example1.

This is variation of your example - 3D_Rotation of 4 Planes.

It uses modified function _GLDraw() and shows basic color mixing.

; Main drawing function
Func _GLDraw()

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

    $nM -= 0.5 ; decreasing. To rotate otherwise do increasing

    _glPopMatrix()
    _glPushMatrix()

    ; Rotate
    _glRotatef($nM, 1, 1, 1)

    ; Start red square
    _glBegin($GL_QUADS)
    _glColor3f(0.9, 0.3, 0) ; red

    _glVertex3f(0.75, 0.75, 0.075)
    _glVertex3f(0.75, -0.25, 0.075)
    _glVertex3f(-0.25, -0.25, 0.075)
    _glVertex3f(-0.25, 0.75, 0.075)
    _glEnd()

    ; Start green square
    _glBegin($GL_QUADS)
    _glColor3f(0, 0.9, 0.3)

    _glVertex3f(0.75, 0.25, 0.025)
    _glVertex3f(0.75, -0.75, 0.025)
    _glVertex3f(-0.25, -0.75, 0.025)
    _glVertex3f(-0.25, 0.25, 0.025)
    _glEnd()

    ; Start blue square
    _glBegin($GL_QUADS)
    _glColor3f(0.3, 0, 0.9)

    _glVertex3f(0.25, 0.75, -0.025)
    _glVertex3f(0.25, -0.25, -0.025)
    _glVertex3f(-0.75, -0.25, -0.025)
    _glVertex3f(-0.75, 0.75, -0.025)
    _glEnd()

    ; Start yellow square
    _glBegin($GL_QUADS)
    _glColor3f(0.85, 0.85, 0.6)

    _glVertex3f(0.25, 0.25, -0.075)
    _glVertex3f(0.25, -0.75, -0.075)
    _glVertex3f(-0.75, -0.75, -0.075)
    _glVertex3f(-0.75, 0.25, -0.075)
    _glEnd()

    ; Replace old with the new one
    _SwapBuffers($hDC)

EndFunc   ;==>_GLDraw

The point of world view

Link to comment
Share on other sites

Color mixing is that way because of used blending function ($GL_ONE, $GL_ONE).

Somewhere more natural look (my opinion) is with _glBlendFunc($GL_SRC_ALPHA, $GL_ONE_MINUS_SRC_ALPHA) with added tranparency _glColor4f(0.9, 0.3, 0, 0.7) for red in your case.

Alpha 0.7 is what's important - for all colors this way.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

I have been mucking about with the examples....

#NoTrayIcon

Opt("GUIOnEventMode", 1)
Opt("MustDeclareVars", 1)


; Used Dlls
Global Const $hUSER32 = DllOpen("user32.dll")
Global Const $hGDI32 = DllOpen("gdi32.dll")
Global Const $hOPENGL32 = DllOpen("opengl32.dll")

; General constants
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

; Used GL constants. See OpenGLConstants.au3
Global Const $GL_VERSION_1_1 = 1
Global Const $GL_COLOR_BUFFER_BIT = 0x00004000
Global Const $GL_QUADS = 0x0007
Global Const $GL_BLEND = 0x0BE2
Global Const $GL_ONE = 1
Global Const $GL_DEPTH_BUFFER_BIT = 0x00000100
Global Const $GL_ALL_ATTRIB_BITS = 0x000FFFFF
Global Const $GL_TRANSFORM_BIT = 0x00001000
Global Const $GL_VIEWPORT_BIT = 0x00000800
Global Const $GL_LIST_BIT = 0x00020000
Global Const $GL_UNSIGNED_BYTE = 0x1401

; Create GUI
Global $iWidth = 450
Global $iHeight = 450
Global $hGUI = GUICreate("OpenGL 3D rotation and font demo", $iWidth, $iHeight)

GUISetBkColor(0) ; black


; Enable OpenGL
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

; Font
Global $hFontList = _CreateOpenGLFont(20, 400, 256, "Segoe UI")

; Prepare things
_glClear(BitOR($GL_COLOR_BUFFER_BIT, $GL_DEPTH_BUFFER_BIT)) ; initially cleaning buffers in case something is left there

; About blending (not needed but to show it)
_glEnable($GL_BLEND) ; enable GL_BLEND
_glBlendFunc($GL_ONE, $GL_ONE) ; blending fashion

_glViewport(0, 0, $iWidth, $iHeight) ; position the view


; To keep it 'full' all the time
GUIRegisterMsg(133, "_Preserve") ; WM_NCPAINT

; Handle exit
GUISetOnEvent(-3, "_Quit") ; on exit


; Show GUI
GUISetState(@SW_SHOW, $hGUI)


Global $nM ; this to be used for rotation


; Loop and draw till exit
While 1

    _GLDraw()
    Sleep(25)

WEnd
; USED FUNCTIONS

; This is needed for initialization
Func _EnableOpenGL($hWnd, ByRef $hDeviceContext, ByRef $hOPENGL32RenderingContext)

    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($hUSER32, "hwnd", "GetDC", "hwnd", $hWnd)

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

    $hDeviceContext = $a_hCall[0]

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

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

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

    $hOPENGL32RenderingContext = $a_hCall[0]

    $a_iCall = DllCall($hOPENGL32, "int", "wglMakeCurrent", "hwnd", $hDeviceContext, "hwnd", $hOPENGL32RenderingContext)
    If @error Or Not $a_iCall[0] Then
        Return SetError(5, 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



; This is cleaning function
Func _DisableOpenGL($hWnd, $hDeviceContext, $hOPENGL32RenderingContext)

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

    DllCall($hOPENGL32, "int", "wglMakeCurrent", "hwnd", 0, "hwnd", 0)
    DllCall($hOPENGL32, "int", "wglDeleteContext", "hwnd", $hOPENGL32RenderingContext)
    DllCall($hUSER32, "int", "ReleaseDC", "hwnd", $hWnd, "hwnd", $hDeviceContext)

EndFunc   ;==>_DisableOpenGL



; Used GL functions (and few not used too)
Func _glBegin($iMode)
    DllCall($hOPENGL32, "none", "glBegin", "dword", $iMode)
EndFunc   ;==>_glBegin

Func _glBlendFunc($iSfactor, $iDfactor)
    DllCall($hOPENGL32, "none", "glBlendFunc", "dword", $iSfactor, "dword", $iDfactor)
EndFunc   ;==>_glBlendFunc

Func _glCallListsChar($iSize, $iType, $pList)
    DllCall($hOPENGL32, "none", "glCallLists", "dword", $iSize, "dword", $iType, "str", $pList)
EndFunc   ;==>_glCallListsChar

Func _glClear($iMask)
    DllCall($hOPENGL32, "none", "glClear", "dword", $iMask)
EndFunc   ;==>_glClear

Func _glClearColor($nRed, $nGreen, $nBlue, $nAlpha)
    DllCall($hOPENGL32, "none", "glClearColor", "float", $nRed, "float", $nGreen, "float", $nBlue, "float", $nAlpha)
EndFunc   ;==>_glClearColor

Func _glColor3f($nRed, $nGreen, $nBlue)
    DllCall($hOPENGL32, "none", "glColor3f", "float", $nRed, "float", $nGreen, "float", $nBlue)
EndFunc   ;==>_glColor3f

Func _glColor4f($nRed, $nGreen, $nBlue, $nAlpha)
    DllCall($hOPENGL32, "none", "glColor4f", "float", $nRed, "float", $nGreen, "float", $nBlue, "float", $nAlpha)
EndFunc   ;==>_glColor4f

Func _glEnable($iCap)
    DllCall($hOPENGL32, "none", "glEnable", "dword", $iCap)
EndFunc   ;==>_glEnable

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

Func _glListBase($iBase)
    DllCall($hOPENGL32, "none", "glListBase", "dword", $iBase)
EndFunc   ;==>_glListBase

Func _glLoadIdentity()
    DllCall($hOPENGL32, "none", "glLoadIdentity")
EndFunc   ;==>_glLoadIdentity

Func _glPopAttrib()
    DllCall($hOPENGL32, "none", "glPopAttrib")
EndFunc   ;==>_glPopAttrib

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

Func _glPushAttrib($iMask)
    DllCall($hOPENGL32, "none", "glPushAttrib", "dword", $iMask)
EndFunc   ;==>_glPushAttrib

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

Func _glRotatef($nAngle, $nX, $nY, $nZ)
    DllCall($hOPENGL32, "none", "glRotatef", "float", $nAngle, "float", $nX, "float", $nY, "float", $nZ)
EndFunc   ;==>_glRotatef

Func _glRasterPos2f($nX, $nY)
    DllCall($hOPENGL32, "none", "glRasterPos2f", "float", $nX, "float", $nY)
EndFunc   ;==>_glRasterPos2f

Func _glTranslatef($nX, $nY, $nZ)
    DllCall($hOPENGL32, "none", "glTranslatef", "float", $nX, "float", $nY, "float", $nZ)
EndFunc   ;==>_glTranslatef

Func _glVertex3f($nX, $nY, $nZ)
    DllCall($hOPENGL32, "none", "glVertex3f", "float", $nX, "float", $nY, "float", $nZ)
EndFunc   ;==>_glVertex3f

Func _glViewport($iX, $iY, $iWidth, $iHeight)
    DllCall($hOPENGL32, "none", "glViewport", "int", $iX, "int", $iY, "dword", $iWidth, "dword", $iHeight)
EndFunc   ;==>_glViewport




; Other functions
Func _SwapBuffers($hDC)
    DllCall($hGDI32, "int", "SwapBuffers", "hwnd", $hDC)
EndFunc   ;==>_SwapBuffers


; Few more used functions (wrappers)

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


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


Func _glDrawText($iXcoordinate, $iYcoordinate, $sString, $hFontList)

    _glPushMatrix()
    _glRasterPos2f($iXcoordinate, $iYcoordinate)
    _glPushAttrib($GL_ALL_ATTRIB_BITS)
    _glListBase($hFontList)
    _glCallListsChar(StringLen($sString), $GL_UNSIGNED_BYTE, $sString) ; this function is in such form that it receives strings only (deliberately)
    _glPopAttrib()
    _glPopMatrix()

EndFunc   ;==>_glDrawText

; Font function
Func _CreateOpenGLFont($iSize = 8.5, $iWeight = 400, $iAttribute = 256, $sFontName = "", $hFontList = 0, $iNumberOf = 1)

    ; Get current DC (DC is global variable so this in not strictly necessary. But still... to have more freedom)
    Local $aCall = DllCall($hOPENGL32, "hwnd", "wglGetCurrentDC")

    If @error Or Not $aCall[0] Then
        Return SetError(1, 0, 0)
    EndIf

    Local $hDC = $aCall[0]

    ; This is needed to propery determine the size of the new font
    $aCall = DllCall($hGDI32, "int", "GetDeviceCaps", _
            "hwnd", $hDC, _
            "int", 90) ; LOGPIXELSY

    If @error Or Not $aCall[0] Then
        Return SetError(2, 0, 0)
    EndIf

    Local $iDCaps = $aCall[0]

    ; $iAttribute is complex. Contains more than one passed data.
    Local $iItalic = BitAND($iAttribute, 2)
    Local $iUnderline = BitAND($iAttribute, 4)
    Local $iStrikeout = BitAND($iAttribute, 8)

    Local $iQuality
    If BitAND($iAttribute, 16) Then
        $iQuality = 1 ; DRAFT_QUALITY
    ElseIf BitAND($iAttribute, 32) Then
        $iQuality = 2 ; PROOF_QUALITY
    ElseIf BitAND($iAttribute, 64) Then
        $iQuality = 3 ; NONANTIALIASED_QUALITY
    ElseIf BitAND($iAttribute, 128) Then
        $iQuality = 4 ; ANTIALIASED_QUALITY
    ElseIf BitAND($iAttribute, 256) Then
        $iQuality = 5 ; CLEARTYPE_QUALITY
    ElseIf BitAND($iAttribute, 512) Then
        $iQuality = 6 ; CLEARTYPE_COMPAT_QUALITY
    EndIf

    ; Create new font
    $aCall = DllCall($hGDI32, "ptr", "CreateFontW", _
            "int", -$iSize * $iDCaps / 72, _
            "int", 0, _
            "int", 0, _
            "int", 0, _
            "int", $iWeight, _
            "dword", $iItalic, _
            "dword", $iUnderline, _
            "dword", $iStrikeout, _
            "dword", 0, _
            "dword", 0, _
            "dword", 0, _
            "dword", $iQuality, _
            "dword", 0, _
            "wstr", $sFontName)

    If @error Or Not $aCall[0] Then
        Return SetError(3, 0, 0)
    EndIf

    Local $hFont = $aCall[0]

    ; New font to DC
    $aCall = DllCall($hGDI32, "hwnd", "SelectObject", "hwnd", $hDC, "hwnd", $hFont)

    If @error Or Not $aCall[0] Then
        DllCall($hGDI32, "int", "DeleteObject", "hwnd", $hFont)
        Return SetError(4, 0, 0)
    EndIf

    ; This was before
    Local $hOldFont = $aCall[0]

    ; If old FontList is passed delete it to free memory.
    If $hFontList Then DllCall($hOPENGL32, "dword", "glDeleteLists", "dword", $hFontList, "dword", $iNumberOf)

    ; Generate empty display list
    $aCall = DllCall($hOPENGL32, "dword", "glGenLists", "dword", 1)

    If @error Or Not $aCall[0] Then
        DllCall($hGDI32, "int", "DeleteObject", "hwnd", $hFont)
        Return SetError(5, 0, 0)
    EndIf

    $hFontList = $aCall[0]

    ; Make glyph bitmaps
    $aCall = DllCall($hOPENGL32, "int", "wglUseFontBitmapsW", _
            "ptr", $hDC, _
            "dword", 0, _
            "dword", 256, _
            "ptr", $hFontList)

    If @error Or Not $aCall[0] Then
        DllCall($hGDI32, "int", "DeleteObject", "hwnd", $hFont)
        Return SetError(6, 0, 0)
    EndIf

    ; There can be only one. Delete old font.
    DllCall($hGDI32, "int", "DeleteObject", "hwnd", $hOldFont)

    ; All OK. Return FontList
    Return SetError(0, 0, $hFontList)

EndFunc   ;==>_CreateOpenGLFont

Func _GLDraw()

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

    $nM -= 1.2 ; decreasing. To rotate otherwise do increasing

    _glPopMatrix()
    _glPushMatrix()

    ; Rotate
    _glRotatef($nM, .3, .3, .3)

    ; Start red square
    _glBegin($GL_QUADS)
    _glColor3f(0.5, 0, 0) ; red

    _glVertex3f(.3, .3, .3)
    _glVertex3f(.3, .3, -.3)
    _glVertex3f(.3, -.3, -.3)
    _glVertex3f(.3, -.3, .3)
    _glEnd()

    ; Start green square
    _glBegin($GL_QUADS)
    _glColor3f(0, 0.5, 0)

    _glVertex3f(-.3, .3, .3)
    _glVertex3f(-.3, .3, -.3)
    _glVertex3f(-.3, -.3, -.3)
    _glVertex3f(-.3, -.3, .3)
    _glEnd()

    ; Start blue square
    _glBegin($GL_QUADS)
    _glColor3f(0, 0, 0.5)

    _glVertex3f(-.3, .3, .3)
    _glVertex3f(-.3, .3, -.3)
    _glVertex3f(.3, .3, -.3)
    _glVertex3f(.3, .3, .3)
    _glEnd()

    ; Start yellow square
    _glBegin($GL_QUADS)
    _glColor3f(0.5, 0.5, 0)

    _glVertex3f(-.3, -.3, .3)
    _glVertex3f(-.3, -.3, -.3)
    _glVertex3f(.3, -.3, -.3)
    _glVertex3f(.3, -.3, .3)
    _glEnd()

    _glBegin($GL_QUADS)
    _glColor3f(0, 0.5, 0.5)

    _glVertex3f(-.3, .3, .3)
    _glVertex3f(-.3, -.3, .3)
    _glVertex3f(.3, -.3, .3)
    _glVertex3f(.3, .3, .3)
    _glEnd()

    _glBegin($GL_QUADS)
    _glColor3f(0.5, 0, 0.5)

    _glVertex3f(-.3, .3, -.3)
    _glVertex3f(-.3, -.3, -.3)
    _glVertex3f(.3, -.3, -.3)
    _glVertex3f(.3, .3, -.3)
    _glEnd()

    ; Replace old with the new one
    _SwapBuffers($hDC)

EndFunc   ;==>_GLDraw

How would I make it rotate from the user moving the mouse instead of a constant rate?

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

I have been mucking about with the examples....

#NoTrayIcon

Opt("GUIOnEventMode", 1)
Opt("MustDeclareVars", 1)


; Used Dlls
Global Const $hUSER32 = DllOpen("user32.dll")
Global Const $hGDI32 = DllOpen("gdi32.dll")
Global Const $hOPENGL32 = DllOpen("opengl32.dll")

; General constants
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

; Used GL constants. See OpenGLConstants.au3
Global Const $GL_VERSION_1_1 = 1
Global Const $GL_COLOR_BUFFER_BIT = 0x00004000
Global Const $GL_QUADS = 0x0007
Global Const $GL_BLEND = 0x0BE2
Global Const $GL_ONE = 1
Global Const $GL_DEPTH_BUFFER_BIT = 0x00000100
Global Const $GL_ALL_ATTRIB_BITS = 0x000FFFFF
Global Const $GL_TRANSFORM_BIT = 0x00001000
Global Const $GL_VIEWPORT_BIT = 0x00000800
Global Const $GL_LIST_BIT = 0x00020000
Global Const $GL_UNSIGNED_BYTE = 0x1401

; Create GUI
Global $iWidth = 450
Global $iHeight = 450
Global $hGUI = GUICreate("OpenGL 3D rotation and font demo", $iWidth, $iHeight)

GUISetBkColor(0) ; black


; Enable OpenGL
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

; Font
Global $hFontList = _CreateOpenGLFont(20, 400, 256, "Segoe UI")

; Prepare things
_glClear(BitOR($GL_COLOR_BUFFER_BIT, $GL_DEPTH_BUFFER_BIT)) ; initially cleaning buffers in case something is left there

; About blending (not needed but to show it)
_glEnable($GL_BLEND) ; enable GL_BLEND
_glBlendFunc($GL_ONE, $GL_ONE) ; blending fashion

_glViewport(0, 0, $iWidth, $iHeight) ; position the view


; To keep it 'full' all the time
GUIRegisterMsg(133, "_Preserve") ; WM_NCPAINT

; Handle exit
GUISetOnEvent(-3, "_Quit") ; on exit


; Show GUI
GUISetState(@SW_SHOW, $hGUI)


Global $nM ; this to be used for rotation


; Loop and draw till exit
While 1

    _GLDraw()
    Sleep(25)

WEnd
; USED FUNCTIONS

; This is needed for initialization
Func _EnableOpenGL($hWnd, ByRef $hDeviceContext, ByRef $hOPENGL32RenderingContext)

    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($hUSER32, "hwnd", "GetDC", "hwnd", $hWnd)

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

    $hDeviceContext = $a_hCall[0]

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

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

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

    $hOPENGL32RenderingContext = $a_hCall[0]

    $a_iCall = DllCall($hOPENGL32, "int", "wglMakeCurrent", "hwnd", $hDeviceContext, "hwnd", $hOPENGL32RenderingContext)
    If @error Or Not $a_iCall[0] Then
        Return SetError(5, 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



; This is cleaning function
Func _DisableOpenGL($hWnd, $hDeviceContext, $hOPENGL32RenderingContext)

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

    DllCall($hOPENGL32, "int", "wglMakeCurrent", "hwnd", 0, "hwnd", 0)
    DllCall($hOPENGL32, "int", "wglDeleteContext", "hwnd", $hOPENGL32RenderingContext)
    DllCall($hUSER32, "int", "ReleaseDC", "hwnd", $hWnd, "hwnd", $hDeviceContext)

EndFunc   ;==>_DisableOpenGL



; Used GL functions (and few not used too)
Func _glBegin($iMode)
    DllCall($hOPENGL32, "none", "glBegin", "dword", $iMode)
EndFunc   ;==>_glBegin

Func _glBlendFunc($iSfactor, $iDfactor)
    DllCall($hOPENGL32, "none", "glBlendFunc", "dword", $iSfactor, "dword", $iDfactor)
EndFunc   ;==>_glBlendFunc

Func _glCallListsChar($iSize, $iType, $pList)
    DllCall($hOPENGL32, "none", "glCallLists", "dword", $iSize, "dword", $iType, "str", $pList)
EndFunc   ;==>_glCallListsChar

Func _glClear($iMask)
    DllCall($hOPENGL32, "none", "glClear", "dword", $iMask)
EndFunc   ;==>_glClear

Func _glClearColor($nRed, $nGreen, $nBlue, $nAlpha)
    DllCall($hOPENGL32, "none", "glClearColor", "float", $nRed, "float", $nGreen, "float", $nBlue, "float", $nAlpha)
EndFunc   ;==>_glClearColor

Func _glColor3f($nRed, $nGreen, $nBlue)
    DllCall($hOPENGL32, "none", "glColor3f", "float", $nRed, "float", $nGreen, "float", $nBlue)
EndFunc   ;==>_glColor3f

Func _glColor4f($nRed, $nGreen, $nBlue, $nAlpha)
    DllCall($hOPENGL32, "none", "glColor4f", "float", $nRed, "float", $nGreen, "float", $nBlue, "float", $nAlpha)
EndFunc   ;==>_glColor4f

Func _glEnable($iCap)
    DllCall($hOPENGL32, "none", "glEnable", "dword", $iCap)
EndFunc   ;==>_glEnable

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

Func _glListBase($iBase)
    DllCall($hOPENGL32, "none", "glListBase", "dword", $iBase)
EndFunc   ;==>_glListBase

Func _glLoadIdentity()
    DllCall($hOPENGL32, "none", "glLoadIdentity")
EndFunc   ;==>_glLoadIdentity

Func _glPopAttrib()
    DllCall($hOPENGL32, "none", "glPopAttrib")
EndFunc   ;==>_glPopAttrib

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

Func _glPushAttrib($iMask)
    DllCall($hOPENGL32, "none", "glPushAttrib", "dword", $iMask)
EndFunc   ;==>_glPushAttrib

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

Func _glRotatef($nAngle, $nX, $nY, $nZ)
    DllCall($hOPENGL32, "none", "glRotatef", "float", $nAngle, "float", $nX, "float", $nY, "float", $nZ)
EndFunc   ;==>_glRotatef

Func _glRasterPos2f($nX, $nY)
    DllCall($hOPENGL32, "none", "glRasterPos2f", "float", $nX, "float", $nY)
EndFunc   ;==>_glRasterPos2f

Func _glTranslatef($nX, $nY, $nZ)
    DllCall($hOPENGL32, "none", "glTranslatef", "float", $nX, "float", $nY, "float", $nZ)
EndFunc   ;==>_glTranslatef

Func _glVertex3f($nX, $nY, $nZ)
    DllCall($hOPENGL32, "none", "glVertex3f", "float", $nX, "float", $nY, "float", $nZ)
EndFunc   ;==>_glVertex3f

Func _glViewport($iX, $iY, $iWidth, $iHeight)
    DllCall($hOPENGL32, "none", "glViewport", "int", $iX, "int", $iY, "dword", $iWidth, "dword", $iHeight)
EndFunc   ;==>_glViewport




; Other functions
Func _SwapBuffers($hDC)
    DllCall($hGDI32, "int", "SwapBuffers", "hwnd", $hDC)
EndFunc   ;==>_SwapBuffers


; Few more used functions (wrappers)

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


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


Func _glDrawText($iXcoordinate, $iYcoordinate, $sString, $hFontList)

    _glPushMatrix()
    _glRasterPos2f($iXcoordinate, $iYcoordinate)
    _glPushAttrib($GL_ALL_ATTRIB_BITS)
    _glListBase($hFontList)
    _glCallListsChar(StringLen($sString), $GL_UNSIGNED_BYTE, $sString) ; this function is in such form that it receives strings only (deliberately)
    _glPopAttrib()
    _glPopMatrix()

EndFunc   ;==>_glDrawText

; Font function
Func _CreateOpenGLFont($iSize = 8.5, $iWeight = 400, $iAttribute = 256, $sFontName = "", $hFontList = 0, $iNumberOf = 1)

    ; Get current DC (DC is global variable so this in not strictly necessary. But still... to have more freedom)
    Local $aCall = DllCall($hOPENGL32, "hwnd", "wglGetCurrentDC")

    If @error Or Not $aCall[0] Then
        Return SetError(1, 0, 0)
    EndIf

    Local $hDC = $aCall[0]

    ; This is needed to propery determine the size of the new font
    $aCall = DllCall($hGDI32, "int", "GetDeviceCaps", _
            "hwnd", $hDC, _
            "int", 90) ; LOGPIXELSY

    If @error Or Not $aCall[0] Then
        Return SetError(2, 0, 0)
    EndIf

    Local $iDCaps = $aCall[0]

    ; $iAttribute is complex. Contains more than one passed data.
    Local $iItalic = BitAND($iAttribute, 2)
    Local $iUnderline = BitAND($iAttribute, 4)
    Local $iStrikeout = BitAND($iAttribute, 8)

    Local $iQuality
    If BitAND($iAttribute, 16) Then
        $iQuality = 1 ; DRAFT_QUALITY
    ElseIf BitAND($iAttribute, 32) Then
        $iQuality = 2 ; PROOF_QUALITY
    ElseIf BitAND($iAttribute, 64) Then
        $iQuality = 3 ; NONANTIALIASED_QUALITY
    ElseIf BitAND($iAttribute, 128) Then
        $iQuality = 4 ; ANTIALIASED_QUALITY
    ElseIf BitAND($iAttribute, 256) Then
        $iQuality = 5 ; CLEARTYPE_QUALITY
    ElseIf BitAND($iAttribute, 512) Then
        $iQuality = 6 ; CLEARTYPE_COMPAT_QUALITY
    EndIf

    ; Create new font
    $aCall = DllCall($hGDI32, "ptr", "CreateFontW", _
            "int", -$iSize * $iDCaps / 72, _
            "int", 0, _
            "int", 0, _
            "int", 0, _
            "int", $iWeight, _
            "dword", $iItalic, _
            "dword", $iUnderline, _
            "dword", $iStrikeout, _
            "dword", 0, _
            "dword", 0, _
            "dword", 0, _
            "dword", $iQuality, _
            "dword", 0, _
            "wstr", $sFontName)

    If @error Or Not $aCall[0] Then
        Return SetError(3, 0, 0)
    EndIf

    Local $hFont = $aCall[0]

    ; New font to DC
    $aCall = DllCall($hGDI32, "hwnd", "SelectObject", "hwnd", $hDC, "hwnd", $hFont)

    If @error Or Not $aCall[0] Then
        DllCall($hGDI32, "int", "DeleteObject", "hwnd", $hFont)
        Return SetError(4, 0, 0)
    EndIf

    ; This was before
    Local $hOldFont = $aCall[0]

    ; If old FontList is passed delete it to free memory.
    If $hFontList Then DllCall($hOPENGL32, "dword", "glDeleteLists", "dword", $hFontList, "dword", $iNumberOf)

    ; Generate empty display list
    $aCall = DllCall($hOPENGL32, "dword", "glGenLists", "dword", 1)

    If @error Or Not $aCall[0] Then
        DllCall($hGDI32, "int", "DeleteObject", "hwnd", $hFont)
        Return SetError(5, 0, 0)
    EndIf

    $hFontList = $aCall[0]

    ; Make glyph bitmaps
    $aCall = DllCall($hOPENGL32, "int", "wglUseFontBitmapsW", _
            "ptr", $hDC, _
            "dword", 0, _
            "dword", 256, _
            "ptr", $hFontList)

    If @error Or Not $aCall[0] Then
        DllCall($hGDI32, "int", "DeleteObject", "hwnd", $hFont)
        Return SetError(6, 0, 0)
    EndIf

    ; There can be only one. Delete old font.
    DllCall($hGDI32, "int", "DeleteObject", "hwnd", $hOldFont)

    ; All OK. Return FontList
    Return SetError(0, 0, $hFontList)

EndFunc   ;==>_CreateOpenGLFont

Func _GLDraw()

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

    $nM -= 1.2 ; decreasing. To rotate otherwise do increasing

    _glPopMatrix()
    _glPushMatrix()

    ; Rotate
    _glRotatef($nM, .3, .3, .3)

    ; Start red square
    _glBegin($GL_QUADS)
    _glColor3f(0.5, 0, 0) ; red

    _glVertex3f(.3, .3, .3)
    _glVertex3f(.3, .3, -.3)
    _glVertex3f(.3, -.3, -.3)
    _glVertex3f(.3, -.3, .3)
    _glEnd()

    ; Start green square
    _glBegin($GL_QUADS)
    _glColor3f(0, 0.5, 0)

    _glVertex3f(-.3, .3, .3)
    _glVertex3f(-.3, .3, -.3)
    _glVertex3f(-.3, -.3, -.3)
    _glVertex3f(-.3, -.3, .3)
    _glEnd()

    ; Start blue square
    _glBegin($GL_QUADS)
    _glColor3f(0, 0, 0.5)

    _glVertex3f(-.3, .3, .3)
    _glVertex3f(-.3, .3, -.3)
    _glVertex3f(.3, .3, -.3)
    _glVertex3f(.3, .3, .3)
    _glEnd()

    ; Start yellow square
    _glBegin($GL_QUADS)
    _glColor3f(0.5, 0.5, 0)

    _glVertex3f(-.3, -.3, .3)
    _glVertex3f(-.3, -.3, -.3)
    _glVertex3f(.3, -.3, -.3)
    _glVertex3f(.3, -.3, .3)
    _glEnd()

    _glBegin($GL_QUADS)
    _glColor3f(0, 0.5, 0.5)

    _glVertex3f(-.3, .3, .3)
    _glVertex3f(-.3, -.3, .3)
    _glVertex3f(.3, -.3, .3)
    _glVertex3f(.3, .3, .3)
    _glEnd()

    _glBegin($GL_QUADS)
    _glColor3f(0.5, 0, 0.5)

    _glVertex3f(-.3, .3, -.3)
    _glVertex3f(-.3, -.3, -.3)
    _glVertex3f(.3, -.3, -.3)
    _glVertex3f(.3, .3, -.3)
    _glEnd()

    ; Replace old with the new one
    _SwapBuffers($hDC)

EndFunc   ;==>_GLDraw

How would I make it rotate from the user moving the mouse instead of a constant rate?

Maybe someing like this:

#NoTrayIcon

Opt("GUIOnEventMode", 1)
Opt("MustDeclareVars", 1)


; Used Dlls
Global Const $hUSER32 = DllOpen("user32.dll")
Global Const $hGDI32 = DllOpen("gdi32.dll")
Global Const $hOPENGL32 = DllOpen("opengl32.dll")

; General constants
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

; Used GL constants. See OpenGLConstants.au3
Global Const $GL_VERSION_1_1 = 1
Global Const $GL_COLOR_BUFFER_BIT = 0x00004000
Global Const $GL_QUADS = 0x0007
Global Const $GL_BLEND = 0x0BE2
Global Const $GL_SRC_ALPHA = 0x0302
Global Const $GL_ONE_MINUS_SRC_ALPHA = 0x0303
Global Const $GL_DEPTH_BUFFER_BIT = 0x00000100
Global Const $GL_ALL_ATTRIB_BITS = 0x000FFFFF
Global Const $GL_TRANSFORM_BIT = 0x00001000
Global Const $GL_VIEWPORT_BIT = 0x00000800
Global Const $GL_LIST_BIT = 0x00020000
Global Const $GL_UNSIGNED_BYTE = 0x1401

; corgano related
Global $aCursorPosGlobal[2]

; Create GUI
Global $iWidth = 450
Global $iHeight = 450
Global $hGUI = GUICreate("OpenGL", $iWidth, $iHeight)

GUISetBkColor(0) ; black


; Enable OpenGL
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

; Prepare things
_glClear(BitOR($GL_COLOR_BUFFER_BIT, $GL_DEPTH_BUFFER_BIT)) ; initially cleaning buffers in case something is left there

; About blending (not needed but to show it)
_glEnable($GL_BLEND) ; enable GL_BLEND
_glBlendFunc($GL_SRC_ALPHA, $GL_ONE_MINUS_SRC_ALPHA)



_glViewport(0, 0, $iWidth, $iHeight) ; position the view


; To keep it 'full' all the time
GUIRegisterMsg(133, "_Preserve") ; WM_NCPAINT

; Handle exit
GUISetOnEvent(-3, "_Quit") ; on exit

Global $nM ; this to be used for rotation

; corgano related
GUIRegisterMsg(512, "_ChangeSpeed") ; WM_MOUSEMOVE

; Show GUI
GUISetState(@SW_SHOW, $hGUI)


; Loop and draw till exit
While 1

    _GLDraw()
    Sleep(25)

WEnd
; USED FUNCTIONS

; This is needed for initialization
Func _EnableOpenGL($hWnd, ByRef $hDeviceContext, ByRef $hOPENGL32RenderingContext)

    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($hUSER32, "hwnd", "GetDC", "hwnd", $hWnd)

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

    $hDeviceContext = $a_hCall[0]

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

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

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

    $hOPENGL32RenderingContext = $a_hCall[0]

    $a_iCall = DllCall($hOPENGL32, "int", "wglMakeCurrent", "hwnd", $hDeviceContext, "hwnd", $hOPENGL32RenderingContext)
    If @error Or Not $a_iCall[0] Then
        Return SetError(5, 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



; This is cleaning function
Func _DisableOpenGL($hWnd, $hDeviceContext, $hOPENGL32RenderingContext)

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

    DllCall($hOPENGL32, "int", "wglMakeCurrent", "hwnd", 0, "hwnd", 0)
    DllCall($hOPENGL32, "int", "wglDeleteContext", "hwnd", $hOPENGL32RenderingContext)
    DllCall($hUSER32, "int", "ReleaseDC", "hwnd", $hWnd, "hwnd", $hDeviceContext)

EndFunc   ;==>_DisableOpenGL



; Used GL functions (and few not used too)
Func _glBegin($iMode)
    DllCall($hOPENGL32, "none", "glBegin", "dword", $iMode)
EndFunc   ;==>_glBegin

Func _glBlendFunc($iSfactor, $iDfactor)
    DllCall($hOPENGL32, "none", "glBlendFunc", "dword", $iSfactor, "dword", $iDfactor)
EndFunc   ;==>_glBlendFunc

Func _glCallListsChar($iSize, $iType, $pList)
    DllCall($hOPENGL32, "none", "glCallLists", "dword", $iSize, "dword", $iType, "str", $pList)
EndFunc   ;==>_glCallListsChar

Func _glClear($iMask)
    DllCall($hOPENGL32, "none", "glClear", "dword", $iMask)
EndFunc   ;==>_glClear

Func _glClearColor($nRed, $nGreen, $nBlue, $nAlpha)
    DllCall($hOPENGL32, "none", "glClearColor", "float", $nRed, "float", $nGreen, "float", $nBlue, "float", $nAlpha)
EndFunc   ;==>_glClearColor

Func _glColor3f($nRed, $nGreen, $nBlue)
    DllCall($hOPENGL32, "none", "glColor3f", "float", $nRed, "float", $nGreen, "float", $nBlue)
EndFunc   ;==>_glColor3f

Func _glColor4f($nRed, $nGreen, $nBlue, $nAlpha)
    DllCall($hOPENGL32, "none", "glColor4f", "float", $nRed, "float", $nGreen, "float", $nBlue, "float", $nAlpha)
EndFunc   ;==>_glColor4f

Func _glEnable($iCap)
    DllCall($hOPENGL32, "none", "glEnable", "dword", $iCap)
EndFunc   ;==>_glEnable

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

Func _glListBase($iBase)
    DllCall($hOPENGL32, "none", "glListBase", "dword", $iBase)
EndFunc   ;==>_glListBase

Func _glLoadIdentity()
    DllCall($hOPENGL32, "none", "glLoadIdentity")
EndFunc   ;==>_glLoadIdentity

Func _glPopAttrib()
    DllCall($hOPENGL32, "none", "glPopAttrib")
EndFunc   ;==>_glPopAttrib

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

Func _glPushAttrib($iMask)
    DllCall($hOPENGL32, "none", "glPushAttrib", "dword", $iMask)
EndFunc   ;==>_glPushAttrib

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

Func _glRotatef($nAngle, $nX, $nY, $nZ)
    DllCall($hOPENGL32, "none", "glRotatef", "float", $nAngle, "float", $nX, "float", $nY, "float", $nZ)
EndFunc   ;==>_glRotatef

Func _glRasterPos2f($nX, $nY)
    DllCall($hOPENGL32, "none", "glRasterPos2f", "float", $nX, "float", $nY)
EndFunc   ;==>_glRasterPos2f

Func _glTranslatef($nX, $nY, $nZ)
    DllCall($hOPENGL32, "none", "glTranslatef", "float", $nX, "float", $nY, "float", $nZ)
EndFunc   ;==>_glTranslatef

Func _glVertex3f($nX, $nY, $nZ)
    DllCall($hOPENGL32, "none", "glVertex3f", "float", $nX, "float", $nY, "float", $nZ)
EndFunc   ;==>_glVertex3f

Func _glViewport($iX, $iY, $iWidth, $iHeight)
    DllCall($hOPENGL32, "none", "glViewport", "int", $iX, "int", $iY, "dword", $iWidth, "dword", $iHeight)
EndFunc   ;==>_glViewport




; Other functions
Func _SwapBuffers($hDC)
    DllCall($hGDI32, "int", "SwapBuffers", "hwnd", $hDC)
EndFunc   ;==>_SwapBuffers


; Few more used functions (wrappers)

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


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


Func _ChangeSpeed($hWnd, $iMsg, $wParam, $lParam)

    ; dealing with AU3Check.exe
    #forceref $hWnd, $iMsg, $wParam

    ; Cursor position
    Local $aCursorPos[2] = [BitAND($lParam, 65535), BitShift($lParam, 16)]

    ; Mouse 'speed'
    Local $iMouseSpeed = Sqrt(($aCursorPos[0] - $aCursorPosGlobal[0]) ^ 2 + ($aCursorPos[1] - $aCursorPosGlobal[1]) ^ 2)

    ; adjust rotating factor
    If $aCursorPos[0] - $aCursorPosGlobal[0] < 0 Or $aCursorPos[1] - $aCursorPosGlobal[1] < 0 Then
        $nM += $iMouseSpeed / 2
    Else
        $nM -= $iMouseSpeed / 2
    EndIf

    ; Global cursor position
    $aCursorPosGlobal[0] = $aCursorPos[0]
    $aCursorPosGlobal[1] = $aCursorPos[1]


EndFunc   ;==>_ChangeSpeed





Func _GLDraw()

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

    $nM -= 1.2 ; decreasing. To rotate otherwise do increasing

    _glPopMatrix()
    _glPushMatrix()

    ; Rotate
    _glRotatef($nM, .3, .3, .3)

    ; Start red square
    _glBegin($GL_QUADS)
    _glColor4f(1, 0, 0, 0.9) ; red

    _glVertex3f(.3, .3, .3)
    _glVertex3f(.3, .3, -.3)
    _glVertex3f(.3, -.3, -.3)
    _glVertex3f(.3, -.3, .3)
    ;_glEnd()

    ; Start green square
    ;_glBegin($GL_QUADS)
    _glColor4f(0, 1, 0, 0.9) ; green

    _glVertex3f(-.3, .3, .3)
    _glVertex3f(-.3, .3, -.3)
    _glVertex3f(-.3, -.3, -.3)
    _glVertex3f(-.3, -.3, .3)
    ;_glEnd()

    ; Start blue square
    ;_glBegin($GL_QUADS)
    _glColor4f(0, 0, 1, 0.9) ; blue

    _glVertex3f(-.3, .3, .3)
    _glVertex3f(-.3, .3, -.3)
    _glVertex3f(.3, .3, -.3)
    _glVertex3f(.3, .3, .3)
    ;_glEnd()

    ; Start yellow square
    ;_glBegin($GL_QUADS)
    _glColor4f(1, 1, 0, 0.9) ; yelow

    _glVertex3f(-.3, -.3, .3)
    _glVertex3f(-.3, -.3, -.3)
    _glVertex3f(.3, -.3, -.3)
    _glVertex3f(.3, -.3, .3)
    ;_glEnd()

    ;_glBegin($GL_QUADS)
    _glColor4f(0, 1, 1, 0.9) ; aqua

    _glVertex3f(-.3, .3, .3)
    _glVertex3f(-.3, -.3, .3)
    _glVertex3f(.3, -.3, .3)
    _glVertex3f(.3, .3, .3)
    ;_glEnd()

    ;_glBegin($GL_QUADS)
    _glColor4f(1, 0, 1, 0.9) ; fuchsia

    _glVertex3f(-.3, .3, -.3)
    _glVertex3f(-.3, -.3, -.3)
    _glVertex3f(.3, -.3, -.3)
    _glVertex3f(.3, .3, -.3)


    _glEnd()

    ; Replace old with the new one
    _SwapBuffers($hDC)

EndFunc   ;==>_GLDraw
Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Link to comment
Share on other sites

How do I make it rotate around different axes?

Rotation is done using function glRotatef. You can read about it if click this.

It's very 'transparent'. All you need to do is say what angle you want and to define the vector about which the rotation will be done. Vector starts at coordinates 0,0,0 (*).

So if you have something like this:

_glRotatef($nM, 1, 0, 0)

that is saying: Rotate by $nM degrees about the X coordinate axis.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

this is very well done! I would love to see this become an included UDF for autoit's next release.

#NoTrayIcon

Opt("GUIOnEventMode", 1)
Opt("MustDeclareVars", 1)


; Used Dlls
Global Const $hUSER32 = DllOpen("user32.dll")
Global Const $hGDI32 = DllOpen("gdi32.dll")
Global Const $hOPENGL32 = DllOpen("opengl32.dll")

; General constants
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

; Used GL constants. See OpenGLConstants.au3
Global Const $GL_VERSION_1_1 = 1
Global Const $GL_COLOR_BUFFER_BIT = 0x00004000
Global Const $GL_QUADS = 0x0007
Global Const $GL_BLEND = 0x0BE2
Global Const $GL_SRC_ALPHA = 0x0302
Global Const $GL_ONE_MINUS_SRC_ALPHA = 0x0303
Global Const $GL_DEPTH_BUFFER_BIT = 0x00000100
Global Const $GL_ALL_ATTRIB_BITS = 0x000FFFFF
Global Const $GL_TRANSFORM_BIT = 0x00001000
Global Const $GL_VIEWPORT_BIT = 0x00000800
Global Const $GL_LIST_BIT = 0x00020000
Global Const $GL_UNSIGNED_BYTE = 0x1401

; corgano related
Global $aCursorPosGlobal[2]

; Create GUI
Global $iWidth = 450
Global $iHeight = 450
Global $hGUI = GUICreate("OpenGL", $iWidth, $iHeight)

GUISetBkColor(0) ; black


; Enable OpenGL
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

; Prepare things
_glClear(BitOR($GL_COLOR_BUFFER_BIT, $GL_DEPTH_BUFFER_BIT)) ; initially cleaning buffers in case something is left there

; About blending (not needed but to show it)
_glEnable($GL_BLEND) ; enable GL_BLEND
_glBlendFunc($GL_SRC_ALPHA, $GL_ONE_MINUS_SRC_ALPHA)



_glViewport(0, 0, $iWidth, $iHeight) ; position the view


; To keep it 'full' all the time
GUIRegisterMsg(133, "_Preserve") ; WM_NCPAINT

; Handle exit
GUISetOnEvent(-3, "_Quit") ; on exit

Global $nMx, $nMy ; this to be used for rotation

; corgano related
GUIRegisterMsg(512, "_ChangeSpeed") ; WM_MOUSEMOVE

; Show GUI
GUISetState(@SW_SHOW, $hGUI)


; Loop and draw till exit
While 1

    _GLDraw()
    Sleep(25)

WEnd
; USED FUNCTIONS

; This is needed for initialization
Func _EnableOpenGL($hWnd, ByRef $hDeviceContext, ByRef $hOPENGL32RenderingContext)

    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($hUSER32, "hwnd", "GetDC", "hwnd", $hWnd)

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

    $hDeviceContext = $a_hCall[0]

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

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

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

    $hOPENGL32RenderingContext = $a_hCall[0]

    $a_iCall = DllCall($hOPENGL32, "int", "wglMakeCurrent", "hwnd", $hDeviceContext, "hwnd", $hOPENGL32RenderingContext)
    If @error Or Not $a_iCall[0] Then
        Return SetError(5, 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



; This is cleaning function
Func _DisableOpenGL($hWnd, $hDeviceContext, $hOPENGL32RenderingContext)

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

    DllCall($hOPENGL32, "int", "wglMakeCurrent", "hwnd", 0, "hwnd", 0)
    DllCall($hOPENGL32, "int", "wglDeleteContext", "hwnd", $hOPENGL32RenderingContext)
    DllCall($hUSER32, "int", "ReleaseDC", "hwnd", $hWnd, "hwnd", $hDeviceContext)

EndFunc   ;==>_DisableOpenGL



; Used GL functions (and few not used too)
Func _glBegin($iMode)
    DllCall($hOPENGL32, "none", "glBegin", "dword", $iMode)
EndFunc   ;==>_glBegin

Func _glBlendFunc($iSfactor, $iDfactor)
    DllCall($hOPENGL32, "none", "glBlendFunc", "dword", $iSfactor, "dword", $iDfactor)
EndFunc   ;==>_glBlendFunc

Func _glCallListsChar($iSize, $iType, $pList)
    DllCall($hOPENGL32, "none", "glCallLists", "dword", $iSize, "dword", $iType, "str", $pList)
EndFunc   ;==>_glCallListsChar

Func _glClear($iMask)
    DllCall($hOPENGL32, "none", "glClear", "dword", $iMask)
EndFunc   ;==>_glClear

Func _glClearColor($nRed, $nGreen, $nBlue, $nAlpha)
    DllCall($hOPENGL32, "none", "glClearColor", "float", $nRed, "float", $nGreen, "float", $nBlue, "float", $nAlpha)
EndFunc   ;==>_glClearColor

Func _glColor3f($nRed, $nGreen, $nBlue)
    DllCall($hOPENGL32, "none", "glColor3f", "float", $nRed, "float", $nGreen, "float", $nBlue)
EndFunc   ;==>_glColor3f

Func _glColor4f($nRed, $nGreen, $nBlue, $nAlpha)
    DllCall($hOPENGL32, "none", "glColor4f", "float", $nRed, "float", $nGreen, "float", $nBlue, "float", $nAlpha)
EndFunc   ;==>_glColor4f

Func _glEnable($iCap)
    DllCall($hOPENGL32, "none", "glEnable", "dword", $iCap)
EndFunc   ;==>_glEnable

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

Func _glListBase($iBase)
    DllCall($hOPENGL32, "none", "glListBase", "dword", $iBase)
EndFunc   ;==>_glListBase

Func _glLoadIdentity()
    DllCall($hOPENGL32, "none", "glLoadIdentity")
EndFunc   ;==>_glLoadIdentity

Func _glPopAttrib()
    DllCall($hOPENGL32, "none", "glPopAttrib")
EndFunc   ;==>_glPopAttrib

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

Func _glPushAttrib($iMask)
    DllCall($hOPENGL32, "none", "glPushAttrib", "dword", $iMask)
EndFunc   ;==>_glPushAttrib

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

Func _glRotatef($nAngle, $nX, $nY, $nZ)
    DllCall($hOPENGL32, "none", "glRotatef", "float", $nAngle, "float", $nX, "float", $nY, "float", $nZ)
EndFunc   ;==>_glRotatef

Func _glRasterPos2f($nX, $nY)
    DllCall($hOPENGL32, "none", "glRasterPos2f", "float", $nX, "float", $nY)
EndFunc   ;==>_glRasterPos2f

Func _glTranslatef($nX, $nY, $nZ)
    DllCall($hOPENGL32, "none", "glTranslatef", "float", $nX, "float", $nY, "float", $nZ)
EndFunc   ;==>_glTranslatef

Func _glVertex3f($nX, $nY, $nZ)
    DllCall($hOPENGL32, "none", "glVertex3f", "float", $nX, "float", $nY, "float", $nZ)
EndFunc   ;==>_glVertex3f

Func _glViewport($iX, $iY, $iWidth, $iHeight)
    DllCall($hOPENGL32, "none", "glViewport", "int", $iX, "int", $iY, "dword", $iWidth, "dword", $iHeight)
EndFunc   ;==>_glViewport




; Other functions
Func _SwapBuffers($hDC)
    DllCall($hGDI32, "int", "SwapBuffers", "hwnd", $hDC)
EndFunc   ;==>_SwapBuffers


; Few more used functions (wrappers)

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


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


Func _ChangeSpeed($hWnd, $iMsg, $wParam, $lParam)

    ; dealing with AU3Check.exe
    #forceref $hWnd, $iMsg, $wParam

    ; Cursor position
    Local $aCursorPos[2] = [BitAND($lParam, 65535), BitShift($lParam, 16)]

    ; Mouse 'speed'
    Local $iMouseSpeed = Sqrt(($aCursorPos[0] - $aCursorPosGlobal[0]) ^ 2 + ($aCursorPos[1] - $aCursorPosGlobal[1]) ^ 2)

    ; adjust rotating factor
    If $aCursorPos[0] - $aCursorPosGlobal[0] < 0 Then
        $nMx += $iMouseSpeed / 2
    ElseIf $aCursorPos[0] - $aCursorPosGlobal[0] > 0 Then
        $nMx -= $iMouseSpeed / 2
    EndIf

    If $aCursorPos[1] - $aCursorPosGlobal[1] < 0 Then
        $nMy += $iMouseSpeed / 2
    ElseIf $aCursorPos[1] - $aCursorPosGlobal[1] > 0 Then
        $nMy -= $iMouseSpeed / 2
    EndIf

    ; Global cursor position
    $aCursorPosGlobal[0] = $aCursorPos[0]
    $aCursorPosGlobal[1] = $aCursorPos[1]


EndFunc   ;==>_ChangeSpeed





Func _GLDraw()

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

;~     $nM -= 1.2 ; decreasing. To rotate otherwise do increasing

    _glPopMatrix()
    _glPushMatrix()

    ; Rotate
    _glRotatef($nMx, 0, 1, 0)
    _glRotatef($nMy, 1, 0, 0)

    ; Start red square
    _glBegin($GL_QUADS)
    _glColor4f(1, 0, 0, 0.9) ; red

    _glVertex3f(.3, .3, .3)
    _glVertex3f(.3, .3, -.3)
    _glVertex3f(.3, -.3, -.3)
    _glVertex3f(.3, -.3, .3)
    ;_glEnd()

    ; Start green square
    ;_glBegin($GL_QUADS)
    _glColor4f(0, 1, 0, 0.9) ; green

    _glVertex3f(-.3, .3, .3)
    _glVertex3f(-.3, .3, -.3)
    _glVertex3f(-.3, -.3, -.3)
    _glVertex3f(-.3, -.3, .3)
    ;_glEnd()

    ; Start blue square
    ;_glBegin($GL_QUADS)
    _glColor4f(0, 0, 1, 0.9) ; blue

    _glVertex3f(-.3, .3, .3)
    _glVertex3f(-.3, .3, -.3)
    _glVertex3f(.3, .3, -.3)
    _glVertex3f(.3, .3, .3)
    ;_glEnd()

    ; Start yellow square
    ;_glBegin($GL_QUADS)
    _glColor4f(1, 1, 0, 0.9) ; yelow

    _glVertex3f(-.3, -.3, .3)
    _glVertex3f(-.3, -.3, -.3)
    _glVertex3f(.3, -.3, -.3)
    _glVertex3f(.3, -.3, .3)
    ;_glEnd()

    ;_glBegin($GL_QUADS)
    _glColor4f(0, 1, 1, 0.9) ; aqua

    _glVertex3f(-.3, .3, .3)
    _glVertex3f(-.3, -.3, .3)
    _glVertex3f(.3, -.3, .3)
    _glVertex3f(.3, .3, .3)
    ;_glEnd()

    ;_glBegin($GL_QUADS)
    _glColor4f(1, 0, 1, 0.9) ; fuchsia

    _glVertex3f(-.3, .3, -.3)
    _glVertex3f(-.3, -.3, -.3)
    _glVertex3f(.3, -.3, -.3)
    _glVertex3f(.3, .3, -.3)


    _glEnd()

    ; Replace old with the new one
    _SwapBuffers($hDC)

EndFunc   ;==>_GLDraw

Got it. I had fun with this. How would I set how transparent each piece is? Say I had 4 blue squares in front of each other, how would i make it so i could see all of them as if they were transparent?

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

_glColor4f(0.9, 0.3, 0, 0.7)

Yes, this _glColor4f is better than _glColor3f.

Got it. I had fun with this

I'm too. Maybe this one has just more realistic colors for dice:

Func _GLDraw()

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

;~     $nM -= 1.2 ; decreasing. To rotate otherwise do increasing

    _glPopMatrix()
    _glPushMatrix()

    ; Rotate
    _glRotatef($nMx, 0, 1, 0)
    _glRotatef($nMy, 1, 0, 0)

    ; Start red square
    _glBegin($GL_QUADS)
    _glColor4f(1, 0.5, 0.5, 0.5) ; red

    _glVertex3f(.3, .3, .3)
    _glVertex3f(.3, .3, -.3)
    _glVertex3f(.3, -.3, -.3)
    _glVertex3f(.3, -.3, .3)
    ;_glEnd()

    ; Start green square
    ;_glBegin($GL_QUADS)
    _glColor4f(0.5, 1, 0.5, 0.5) ; green

    _glVertex3f(-.3, .3, .3)
    _glVertex3f(-.3, .3, -.3)
    _glVertex3f(-.3, -.3, -.3)
    _glVertex3f(-.3, -.3, .3)
    ;_glEnd()

    ; Start blue square
    ;_glBegin($GL_QUADS)
    _glColor4f(0.5, 0.5, 1, 0.5) ; blue

    _glVertex3f(-.3, .3, .3)
    _glVertex3f(-.3, .3, -.3)
    _glVertex3f(.3, .3, -.3)
    _glVertex3f(.3, .3, .3)
    ;_glEnd()

    ; Start yellow square
    ;_glBegin($GL_QUADS)
    _glColor4f(1, 1, 0.5, 0.5) ; yelow

    _glVertex3f(-.3, -.3, .3)
    _glVertex3f(-.3, -.3, -.3)
    _glVertex3f(.3, -.3, -.3)
    _glVertex3f(.3, -.3, .3)
    ;_glEnd()

    ;_glBegin($GL_QUADS)
    _glColor4f(0.5, 1, 1, 0.5) ; aqua

    _glVertex3f(-.3, .3, .3)
    _glVertex3f(-.3, -.3, .3)
    _glVertex3f(.3, -.3, .3)
    _glVertex3f(.3, .3, .3)
    ;_glEnd()

    ;_glBegin($GL_QUADS)
    _glColor4f(1, 0.5, 1, 0.5) ; fuchsia

    _glVertex3f(-.3, .3, -.3)
    _glVertex3f(-.3, -.3, -.3)
    _glVertex3f(.3, -.3, -.3)
    _glVertex3f(.3, .3, -.3)

    _glEnd()

    ; Replace old with the new one
    _SwapBuffers($hDC)

EndFunc   ;==>_GLDraw

But how can I draw any labels on cubic's planes?

The point of world view

Link to comment
Share on other sites

This one shows two kinds of rotation:

1. Auto rotation of planes (color fiters)

2. Manual rotation of cubic (body connected to mouse)

Func _GLDraw()
Global $nM ; this to be used for rotation

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

    $nM -= 0.5 ; decreasing. To rotate otherwise do increasing

    _glPopMatrix()
    _glPushMatrix()

    ; Auto Rotation 
    _glRotatef($nM, 1, 1, 1)

    ; Start red square
    _glBegin($GL_QUADS)
    _glColor4f(1, 0.5, 0.5, 0.5) ; red

    _glVertex3f(0.75, 0.75, 0.075)
    _glVertex3f(0.75, -0.25, 0.075)
    _glVertex3f(-0.25, -0.25, 0.075)
    _glVertex3f(-0.25, 0.75, 0.075)
    _glEnd()

    ; Start green square
    _glBegin($GL_QUADS)
    _glColor4f(0.5, 1, 0.5, 0.5) ; green

    _glVertex3f(0.75, 0.25, 0.025)
    _glVertex3f(0.75, -0.75, 0.025)
    _glVertex3f(-0.25, -0.75, 0.025)
    _glVertex3f(-0.25, 0.25, 0.025)
    _glEnd()

    ; Start blue square
    _glBegin($GL_QUADS)
    _glColor4f(0.5, 0.5, 1, 0.5) ; blue

    _glVertex3f(0.25, 0.75, -0.025)
    _glVertex3f(0.25, -0.25, -0.025)
    _glVertex3f(-0.75, -0.25, -0.025)
    _glVertex3f(-0.75, 0.75, -0.025)
    _glEnd()

    ; Start yellow square
    _glBegin($GL_QUADS)
    _glColor4f(1, 1, 0.5, 0.5) ; yelow

    _glVertex3f(0.25, 0.25, -0.075)
    _glVertex3f(0.25, -0.75, -0.075)
    _glVertex3f(-0.75, -0.75, -0.075)
    _glVertex3f(-0.75, 0.25, -0.075)
    _glEnd()

    ; Manual rotation
    _glRotatef($nMx, 0, 1, 0)
    _glRotatef($nMy, 1, 0, 0)

    ; Start red square
    _glBegin($GL_QUADS)
    _glColor4f(1, 0.5, 0.5, 0.5) ; red

    _glVertex3f(.3, .3, .3)
    _glVertex3f(.3, .3, -.3)
    _glVertex3f(.3, -.3, -.3)
    _glVertex3f(.3, -.3, .3)
    ;_glEnd()

    ; Start green square
    ;_glBegin($GL_QUADS)
    _glColor4f(0.5, 1, 0.5, 0.5) ; green

    _glVertex3f(-.3, .3, .3)
    _glVertex3f(-.3, .3, -.3)
    _glVertex3f(-.3, -.3, -.3)
    _glVertex3f(-.3, -.3, .3)
    ;_glEnd()

    ; Start blue square
    ;_glBegin($GL_QUADS)
    _glColor4f(0.5, 0.5, 1, 0.5) ; blue

    _glVertex3f(-.3, .3, .3)
    _glVertex3f(-.3, .3, -.3)
    _glVertex3f(.3, .3, -.3)
    _glVertex3f(.3, .3, .3)
    ;_glEnd()

    ; Start yellow square
    ;_glBegin($GL_QUADS)
    _glColor4f(1, 1, 0.5, 0.5) ; yelow

    _glVertex3f(-.3, -.3, .3)
    _glVertex3f(-.3, -.3, -.3)
    _glVertex3f(.3, -.3, -.3)
    _glVertex3f(.3, -.3, .3)
    ;_glEnd()

    ;_glBegin($GL_QUADS)
    _glColor4f(0.5, 1, 1, 0.5) ; aqua

    _glVertex3f(-.3, .3, .3)
    _glVertex3f(-.3, -.3, .3)
    _glVertex3f(.3, -.3, .3)
    _glVertex3f(.3, .3, .3)
    ;_glEnd()

    ;_glBegin($GL_QUADS)
    _glColor4f(1, 0.5, 1, 0.5) ; fuchsia

    _glVertex3f(-.3, .3, -.3)
    _glVertex3f(-.3, -.3, -.3)
    _glVertex3f(.3, -.3, -.3)
    _glVertex3f(.3, .3, -.3)

    _glEnd()

    ; Replace old with the new one
    _SwapBuffers($hDC)

EndFunc   ;==>_GLDraw

You can set position of cubic by mouse in respect to planes and release mouse button.

The point of world view

Link to comment
Share on other sites

This is a nice collection of examples we have here. How would it I embed it in a gui so i could use other controls with it ? (like adding buttons beside it and making them do stuff, using guictrlcreatebutton()

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

This is a nice collection of examples we have here. How would it I embed it in a gui so i could use other controls with it ? (like adding buttons beside it and making them do stuff, using guictrlcreatebutton()

You mean to have it as another control?

Like this maybe:

#NoTrayIcon

Opt("GUIOnEventMode", 1)
Opt("MustDeclareVars", 1)

; Used Dlls
Global Const $hUSER32 = DllOpen("user32.dll")
Global Const $hGDI32 = DllOpen("gdi32.dll")
Global Const $hOPENGL32 = DllOpen("opengl32.dll")

; General constants
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

; Used GL constants. See OpenGLConstants.au3
Global Const $GL_VERSION_1_1 = 1
Global Const $GL_COLOR_BUFFER_BIT = 0x00004000
Global Const $GL_QUADS = 0x0007
Global Const $GL_BLEND = 0x0BE2
Global Const $GL_SRC_ALPHA = 0x0302
Global Const $GL_ONE_MINUS_SRC_ALPHA = 0x0303
Global Const $GL_DEPTH_BUFFER_BIT = 0x00000100
Global Const $GL_ALL_ATTRIB_BITS = 0x000FFFFF
Global Const $GL_TRANSFORM_BIT = 0x00001000
Global Const $GL_VIEWPORT_BIT = 0x00000800
Global Const $GL_LIST_BIT = 0x00020000
Global Const $GL_UNSIGNED_BYTE = 0x1401

Global $aCursorPosGlobal[2]

; Create GUI
Global $iWidth = 450
Global $iHeight = 450
Global $hGUI = GUICreate("OpenGL", $iWidth, $iHeight)
Global $hButton = GUICtrlCreateButton("Button", 100, 270, 100, 30)
GUICtrlSetOnEvent($hButton, "_ButtonFunction")
;GUISetBkColor(0) ; black

Global $hPic = GUICtrlCreatePic("", 20, 20, 200, 200)
GUICtrlSetTip($hPic, "OpenGL")
Global $hOpenGLControl = GUICtrlGetHandle($hPic)

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

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

; Prepare things
_glClear(BitOR($GL_COLOR_BUFFER_BIT, $GL_DEPTH_BUFFER_BIT)) ; initially cleaning buffers in case something is left there

; About blending (not needed but to show it)
_glEnable($GL_BLEND) ; enable GL_BLEND
_glBlendFunc($GL_SRC_ALPHA, $GL_ONE_MINUS_SRC_ALPHA)

_glViewport(0, 0, 200, 200) ; position the view

; Font
Global $hFontList = _CreateOpenGLFont(12, 500, 256)

; To keep it 'full' all the time
GUIRegisterMsg(133, "_Preserve") ; WM_NCPAINT

; Handle exit
GUISetOnEvent(-3, "_Quit") ; on exit

Global $nMx, $nMy ; this to be used for rotation
Global $nM ; this to be used for rotation of the cube

GUIRegisterMsg(512, "_ChangeSpeed") ; WM_MOUSEMOVE

; Show GUI
GUISetState(@SW_SHOW, $hGUI)

; Loop and draw till exit
While 1

    _GLDraw()
    Sleep(25)

WEnd


; USED FUNCTIONS

; This is needed for initialization
Func _EnableOpenGL($hWnd, ByRef $hDeviceContext, ByRef $hOPENGL32RenderingContext)

    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($hUSER32, "hwnd", "GetDC", "hwnd", $hWnd)

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

    $hDeviceContext = $a_hCall[0]

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

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

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

    $hOPENGL32RenderingContext = $a_hCall[0]

    $a_iCall = DllCall($hOPENGL32, "int", "wglMakeCurrent", "hwnd", $hDeviceContext, "hwnd", $hOPENGL32RenderingContext)
    If @error Or Not $a_iCall[0] Then
        Return SetError(5, 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


; This is cleaning function
Func _DisableOpenGL($hWnd, $hDeviceContext, $hOPENGL32RenderingContext)

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

    DllCall($hOPENGL32, "int", "wglMakeCurrent", "hwnd", 0, "hwnd", 0)
    DllCall($hOPENGL32, "int", "wglDeleteContext", "hwnd", $hOPENGL32RenderingContext)
    DllCall($hUSER32, "int", "ReleaseDC", "hwnd", $hWnd, "hwnd", $hDeviceContext)

EndFunc   ;==>_DisableOpenGL


; Used GL functions (and few not used too)
Func _glBegin($iMode)
    DllCall($hOPENGL32, "none", "glBegin", "dword", $iMode)
EndFunc   ;==>_glBegin

Func _glBlendFunc($iSfactor, $iDfactor)
    DllCall($hOPENGL32, "none", "glBlendFunc", "dword", $iSfactor, "dword", $iDfactor)
EndFunc   ;==>_glBlendFunc

Func _glCallListsChar($iSize, $iType, $pList)
    DllCall($hOPENGL32, "none", "glCallLists", "dword", $iSize, "dword", $iType, "str", $pList)
EndFunc   ;==>_glCallListsChar

Func _glClear($iMask)
    DllCall($hOPENGL32, "none", "glClear", "dword", $iMask)
EndFunc   ;==>_glClear

Func _glClearColor($nRed, $nGreen, $nBlue, $nAlpha)
    DllCall($hOPENGL32, "none", "glClearColor", "float", $nRed, "float", $nGreen, "float", $nBlue, "float", $nAlpha)
EndFunc   ;==>_glClearColor

Func _glColor3f($nRed, $nGreen, $nBlue)
    DllCall($hOPENGL32, "none", "glColor3f", "float", $nRed, "float", $nGreen, "float", $nBlue)
EndFunc   ;==>_glColor3f

Func _glColor4f($nRed, $nGreen, $nBlue, $nAlpha)
    DllCall($hOPENGL32, "none", "glColor4f", "float", $nRed, "float", $nGreen, "float", $nBlue, "float", $nAlpha)
EndFunc   ;==>_glColor4f

Func _glEnable($iCap)
    DllCall($hOPENGL32, "none", "glEnable", "dword", $iCap)
EndFunc   ;==>_glEnable

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

Func _glListBase($iBase)
    DllCall($hOPENGL32, "none", "glListBase", "dword", $iBase)
EndFunc   ;==>_glListBase

Func _glLoadIdentity()
    DllCall($hOPENGL32, "none", "glLoadIdentity")
EndFunc   ;==>_glLoadIdentity

Func _glPopAttrib()
    DllCall($hOPENGL32, "none", "glPopAttrib")
EndFunc   ;==>_glPopAttrib

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

Func _glPushAttrib($iMask)
    DllCall($hOPENGL32, "none", "glPushAttrib", "dword", $iMask)
EndFunc   ;==>_glPushAttrib

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

Func _glRotatef($nAngle, $nX, $nY, $nZ)
    DllCall($hOPENGL32, "none", "glRotatef", "float", $nAngle, "float", $nX, "float", $nY, "float", $nZ)
EndFunc   ;==>_glRotatef

Func _glRasterPos2f($nX, $nY)
    DllCall($hOPENGL32, "none", "glRasterPos2f", "float", $nX, "float", $nY)
EndFunc   ;==>_glRasterPos2f

Func _glTranslatef($nX, $nY, $nZ)
    DllCall($hOPENGL32, "none", "glTranslatef", "float", $nX, "float", $nY, "float", $nZ)
EndFunc   ;==>_glTranslatef

Func _glVertex3f($nX, $nY, $nZ)
    DllCall($hOPENGL32, "none", "glVertex3f", "float", $nX, "float", $nY, "float", $nZ)
EndFunc   ;==>_glVertex3f

Func _glViewport($iX, $iY, $iWidth, $iHeight)
    DllCall($hOPENGL32, "none", "glViewport", "int", $iX, "int", $iY, "dword", $iWidth, "dword", $iHeight)
EndFunc   ;==>_glViewport


; Other functions

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


; Few more used functions (wrappers)

Func _glDrawText($iXcoordinate, $iYcoordinate, $sString)

    _glPushMatrix()
    _glRasterPos2f($iXcoordinate, $iYcoordinate)
    _glPushAttrib($GL_ALL_ATTRIB_BITS)
    _glListBase($hFontList)
    _glCallListsChar(StringLen($sString), $GL_UNSIGNED_BYTE, $sString)
    _glPopAttrib()
    _glPopMatrix()

EndFunc   ;==>_glDrawText


Func _CreateOpenGLFont($iSize = 8.5, $iWeight = 400, $iAttribute = 256, $sFontName = "", $hFontList = 0, $iNumberOf = 1)

    Local $aCall = DllCall($hOPENGL32, "hwnd", "wglGetCurrentDC")

    If @error Or Not $aCall[0] Then
        Return SetError(1, 0, 0)
    EndIf

    Local $hDC = $aCall[0]

    $aCall = DllCall($hGDI32, "int", "GetDeviceCaps", _
            "hwnd", $hDC, _
            "int", 90) ; LOGPIXELSY

    If @error Or Not $aCall[0] Then
        Return SetError(2, 0, 0)
    EndIf

    Local $iDCaps = $aCall[0]

    Local $iItalic = BitAND($iAttribute, 2)
    Local $iUnderline = BitAND($iAttribute, 4)
    Local $iStrikeout = BitAND($iAttribute, 8)

    Local $iQuality
    If BitAND($iAttribute, 16) Then
        $iQuality = 1 ; DRAFT_QUALITY
    ElseIf BitAND($iAttribute, 32) Then
        $iQuality = 2 ; PROOF_QUALITY
    ElseIf BitAND($iAttribute, 64) Then
        $iQuality = 3 ; NONANTIALIASED_QUALITY
    ElseIf BitAND($iAttribute, 128) Then
        $iQuality = 4 ; ANTIALIASED_QUALITY
    ElseIf BitAND($iAttribute, 256) Then
        $iQuality = 5 ; CLEARTYPE_QUALITY
    ElseIf BitAND($iAttribute, 512) Then
        $iQuality = 6 ; CLEARTYPE_COMPAT_QUALITY
    EndIf

    $aCall = DllCall($hGDI32, "ptr", "CreateFontW", _
            "int", -$iSize * $iDCaps / 72, _
            "int", 0, _
            "int", 0, _
            "int", 0, _
            "int", $iWeight, _
            "dword", $iItalic, _
            "dword", $iUnderline, _
            "dword", $iStrikeout, _
            "dword", 0, _
            "dword", 0, _
            "dword", 0, _
            "dword", $iQuality, _
            "dword", 0, _
            "wstr", $sFontName)

    If @error Or Not $aCall[0] Then
        Return SetError(3, 0, 0)
    EndIf

    Local $hFont = $aCall[0]

    $aCall = DllCall($hGDI32, "hwnd", "SelectObject", "hwnd", $hDC, "hwnd", $hFont)

    If @error Or Not $aCall[0] Then
        DllCall($hGDI32, "int", "DeleteObject", "hwnd", $hFont)
        Return SetError(4, 0, 0)
    EndIf

    ; This was before
    Local $hOldFont = $aCall[0]

    If $hFontList Then DllCall($hOPENGL32, "dword", "glDeleteLists", "dword", $hFontList, "dword", $iNumberOf)

    ; Generate empty display list
    $aCall = DllCall($hOPENGL32, "dword", "glGenLists", "dword", 1)

    If @error Or Not $aCall[0] Then
        DllCall($hGDI32, "int", "DeleteObject", "hwnd", $hFont)
        Return SetError(5, 0, 0)
    EndIf

    $hFontList = $aCall[0]

    $aCall = DllCall($hOPENGL32, "int", "wglUseFontBitmaps", _
            "ptr", $hDC, _
            "dword", 0, _
            "dword", 256, _
            "ptr", $hFontList)

    If @error Or Not $aCall[0] Then
        DllCall($hGDI32, "int", "DeleteObject", "hwnd", $hFont)
        Return SetError(6, 0, 0)
    EndIf

    ; There can be only one
    DllCall($hGDI32, "int", "DeleteObject", "hwnd", $hOldFont)

    Return SetError(0, 0, $hFontList)

EndFunc   ;==>_CreateOpenGLFont


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


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


Func _ChangeSpeed($hWnd, $iMsg, $wParam, $lParam)

    ; dealing with AU3Check.exe
    #forceref $hWnd, $iMsg, $wParam

    ; Cursor position
    Local $aCursorPos[2] = [BitAND($lParam, 65535), BitShift($lParam, 16)]

    ; Mouse 'speed'
    Local $iMouseSpeed = Sqrt(($aCursorPos[0] - $aCursorPosGlobal[0]) ^ 2 + ($aCursorPos[1] - $aCursorPosGlobal[1]) ^ 2)

    ; adjust rotating factor
    If $aCursorPos[0] - $aCursorPosGlobal[0] < 0 Then
        $nMx += $iMouseSpeed / 2
    ElseIf $aCursorPos[0] - $aCursorPosGlobal[0] > 0 Then
        $nMx -= $iMouseSpeed / 2
    EndIf

    If $aCursorPos[1] - $aCursorPosGlobal[1] < 0 Then
        $nMy += $iMouseSpeed / 2
    ElseIf $aCursorPos[1] - $aCursorPosGlobal[1] > 0 Then
        $nMy -= $iMouseSpeed / 2
    EndIf

    ; Global cursor position
    $aCursorPosGlobal[0] = $aCursorPos[0]
    $aCursorPosGlobal[1] = $aCursorPos[1]


EndFunc   ;==>_ChangeSpeed


Func _ButtonFunction()
    MsgBox(0, "Title", "Text", 0, $hGUI)
EndFunc   ;==>_ButtonFunction



Func _GLDraw()

    ;_glClear($GL_COLOR_BUFFER_BIT) ; cleaning buffers

    $nM -= 2.5 ; decreasing. To rotate otherwise do increasing

    _glPopMatrix()
    _glPushMatrix()

    _glColor3f(0, 0, 1) ; color of text
    _glDrawText(-0.65, -0.7, "OpenGL Control")

    ; Auto Rotation
    _glRotatef($nM, 1, 1, 1)

    _glBegin($GL_QUADS)
    _glColor4f(1, 0.5, 0.5, 0.5) ; red

    _glVertex3f(0.75, 0.75, 0.075)
    _glVertex3f(0.75, -0.25, 0.075)
    _glVertex3f(-0.25, -0.25, 0.075)
    _glVertex3f(-0.25, 0.75, 0.075)

    _glColor4f(0.5, 1, 0.5, 0.5) ; green

    _glVertex3f(0.75, 0.25, 0.025)
    _glVertex3f(0.75, -0.75, 0.025)
    _glVertex3f(-0.25, -0.75, 0.025)
    _glVertex3f(-0.25, 0.25, 0.025)

    _glColor4f(0.5, 0.5, 1, 0.5) ; blue

    _glVertex3f(0.25, 0.75, -0.025)
    _glVertex3f(0.25, -0.25, -0.025)
    _glVertex3f(-0.75, -0.25, -0.025)
    _glVertex3f(-0.75, 0.75, -0.025)

    _glColor4f(1, 1, 0.5, 0.5) ; yelow

    _glVertex3f(0.25, 0.25, -0.075)
    _glVertex3f(0.25, -0.75, -0.075)
    _glVertex3f(-0.75, -0.75, -0.075)
    _glVertex3f(-0.75, 0.25, -0.075)

    _glEnd()

    ; Manual rotation
    _glRotatef($nMx, 0, 1, 0)
    _glRotatef($nMy, 1, 0, 0)

    _glBegin($GL_QUADS)
    _glColor4f(1, 0.5, 0.5, 0.5) ; red

    _glVertex3f(0.3, 0.3, 0.3)
    _glVertex3f(0.3, 0.3, -0.3)
    _glVertex3f(0.3, -0.3, -0.3)
    _glVertex3f(0.3, -0.3, 0.3)

    _glColor4f(0.5, 1, 0.5, 0.5) ; green

    _glVertex3f(-0.3, 0.3, 0.3)
    _glVertex3f(-0.3, 0.3, -0.3)
    _glVertex3f(-0.3, -0.3, -0.3)
    _glVertex3f(-0.3, -0.3, 0.3)

    _glColor4f(0.5, 0.5, 1, 0.5) ; blue

    _glVertex3f(-0.3, 0.3, 0.3)
    _glVertex3f(-0.3, 0.3, -0.3)
    _glVertex3f(0.3, 0.3, -0.3)
    _glVertex3f(0.3, 0.3, 0.3)

    _glColor4f(1, 1, 0.5, 0.5) ; yelow

    _glVertex3f(-0.3, -0.3, 0.3)
    _glVertex3f(-0.3, -0.3, -0.3)
    _glVertex3f(0.3, -0.3, -0.3)
    _glVertex3f(0.3, -0.3, 0.3)

    _glColor4f(0.5, 1, 1, 0.5) ; aqua

    _glVertex3f(-0.3, 0.3, 0.3)
    _glVertex3f(-0.3, -0.3, 0.3)
    _glVertex3f(0.3, -0.3, 0.3)
    _glVertex3f(0.3, 0.3, 0.3)

    _glColor4f(1, 0.5, 1, 0.5) ; fuchsia

    _glVertex3f(-0.3, 0.3, -0.3)
    _glVertex3f(-0.3, -0.3, -0.3)
    _glVertex3f(0.3, -0.3, -0.3)
    _glVertex3f(0.3, 0.3, -0.3)

    _glEnd()

    ; Replace old with the new one
    _SwapBuffers($hDC)

EndFunc   ;==>_GLDraw
Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Forgot to declare a few vars...

I get a graphics glitch.

It will also not react to the mouse if I move it over the box.

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

Forgot to declare a few vars...

I get a graphics glitch.

It will also not react to the mouse if I move it over the box.

That is intentional, see code; for example _glClear() is commented out.

What's not declared?

edit:

PNG = Portable Network Graphics. Lossless compression included. Use that. BMP is for something else.

Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

  • 2 weeks later...

Trancexx, I think this is pretty awesome work. Sure there's enough c code, but autoit's ease/speed to code has it beat by a mile making this just what I need to at minimum, prototype something.

Thanks a ton >_<

Toying around with your first couple examples - second one with the colored triangle reminds me of the one that came with bloodshed c++. Getting mouse interaction isn't bad - just needs a little translation.

On later examples i'm seeing use of gdi32.dll - is this standard with opengl? I've noticed several "gdi" discussions here, but they seem to be using an autoit library I can't find anywhere.

How did you figure out the dll calls? Any ideas on fonts/text in general? Maybe freetype?

Danke!

Beomagi

Link to comment
Share on other sites

Trancexx, I think this is pretty awesome work. Sure there's enough c code, but autoit's ease/speed to code has it beat by a mile making this just what I need to at minimum, prototype something.

Thanks a ton :(

Toying around with your first couple examples - second one with the colored triangle reminds me of the one that came with bloodshed c++. Getting mouse interaction isn't bad - just needs a little translation.

On later examples i'm seeing use of gdi32.dll - is this standard with opengl? I've noticed several "gdi" discussions here, but they seem to be using an autoit library I can't find anywhere.

How did you figure out the dll calls? Any ideas on fonts/text in general? Maybe freetype?

Danke!

Beomagi

Yes, you need to use gdi32.dll if on windows. I'm not sure what you mean with the second sentence in that pasus.

As for fonts. Function I'm using is just a suggestion of course. There are other ways of writing text (maybe even better, only I'm not too familiar with them >_< )

Figuring the calls is not too hard if you have an idea what you want. Btw, I used google a lot. It's all there actually.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

This one shows new objects of rotation:

1. Auto rotation of circular planes (color fiters)

2. Manual rotation of cubic (body connected to mouse)

Func _GLDraw()
global $nM ; this to be used for rotation
local $R = 0.8 

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

    $nM -= 0.5 ; decreasing. To rotate otherwise do increasing

    _glPopMatrix()
    _glPushMatrix()

    ; Auto Rotation 
    _glRotatef($nM, 1, 1, 1)

    ; Start red circle
    Circle ($R,-$R/2,+$R/2, 0.075, 1, 0.5, 0.5)

    ; Start green circle
    Circle ($R,+$R/2,+$R/2, 0.025, 0.5, 1, 0.5)

    ; Start blue circle
    Circle ($R,+$R/2,-$R/2, -0.025, 0.5, 0.5, 1)

    ; Start yellow circle
    Circle ($R,-$R/2,-$R/2, -0.075, 1, 1, 0.5)

    ; Manual rotation
    _glRotatef($nMx, 0, 1, 0)
    _glRotatef($nMy, 1, 0, 0)

    ; Start red square
    _glBegin($GL_QUADS)
    _glColor4f(1, 0.5, 0.5, 0.5) ; red

    _glVertex3f(.3, .3, .3)
    _glVertex3f(.3, .3, -.3)
    _glVertex3f(.3, -.3, -.3)
    _glVertex3f(.3, -.3, .3)
    ;_glEnd()

    ; Start green square
    ;_glBegin($GL_QUADS)
    _glColor4f(0.5, 1, 0.5, 0.5) ; green

    _glVertex3f(-.3, .3, .3)
    _glVertex3f(-.3, .3, -.3)
    _glVertex3f(-.3, -.3, -.3)
    _glVertex3f(-.3, -.3, .3)
    ;_glEnd()

    ; Start blue square
    ;_glBegin($GL_QUADS)
    _glColor4f(0.5, 0.5, 1, 0.5) ; blue

    _glVertex3f(-.3, .3, .3)
    _glVertex3f(-.3, .3, -.3)
    _glVertex3f(.3, .3, -.3)
    _glVertex3f(.3, .3, .3)
    ;_glEnd()

    ; Start yellow square
    ;_glBegin($GL_QUADS)
    _glColor4f(1, 1, 0.5, 0.5) ; yelow

    _glVertex3f(-.3, -.3, .3)
    _glVertex3f(-.3, -.3, -.3)
    _glVertex3f(.3, -.3, -.3)
    _glVertex3f(.3, -.3, .3)
    ;_glEnd()

    ;_glBegin($GL_QUADS)
    _glColor4f(0.5, 1, 1, 0.5) ; aqua

    _glVertex3f(-.3, .3, .3)
    _glVertex3f(-.3, -.3, .3)
    _glVertex3f(.3, -.3, .3)
    _glVertex3f(.3, .3, .3)
    ;_glEnd()

    ;_glBegin($GL_QUADS)
    _glColor4f(1, 0.5, 1, 0.5) ; fuchsia

    _glVertex3f(-.3, .3, -.3)
    _glVertex3f(-.3, -.3, -.3)
    _glVertex3f(.3, -.3, -.3)
    _glVertex3f(.3, .3, -.3)

    _glEnd()

    ; Replace old with the new one
    _SwapBuffers($hDC)

EndFunc   ;==>_GLDraw

;=====================
;Circle create
Func Circle ($R, $x, $y, $z, $cR, $cG, $cB)
local $GL_POLYGON = 0x0009
local $i, $fi, $a = 3.14/30

  _glBegin($GL_POLYGON)
  _glColor4f($cR, $cG, $cB, 0.5)
  For $i = 0 to 60
   $fi = $a*$i
   _glVertex3f($R*Cos($fi)+$x, $R*Sin($fi)+$y, $z)
  Next
  _glEnd();
Endfunc

It has function Circle, too.

$R - radius

$x, $y, $z - center

$cR, $cG, $cB - colors

The point of world view

Link to comment
Share on other sites

Yes, you need to use gdi32.dll if on windows. I'm not sure what you mean with the second sentence in that pasus.

As for fonts. Function I'm using is just a suggestion of course. There are other ways of writing text (maybe even better, only I'm not too familiar with them >_< )

Figuring the calls is not too hard if you have an idea what you want. Btw, I used google a lot. It's all there actually.

Eh, most of the examples I used or found way back were old c - though, for some reason, your autoit library is just that much easier to follow. I really like this language.

NVM about the gdi bit - turns out my nas backup of autoit3 was rather old and errored out with a bunch of examples around here.

Did have an idea, using an off screen buffer to write text gdiplus style, and figuring out if that can be used as an open gl texture. Do have ideas, just wondering about efficiency. Worst case, I define models and call them. Guess that would be useful anyway.

One thing bugging me in my tinkering, is when calling lists to display models, it doesn't appear that the z axis has much bearing on which model is above what.

- I know this is more an opengl question than an autoit question...

e.g.

glPushMatrix();

glTranslate(0,0,z1);

glCallList(model);

glPopMatrix();

glPushMatrix();

glTranslate(0,0,z2);

glCallList(model);

glPopMatrix();

Regardless of what I use for z1/z2, the second model drawing is always on top the first model.

Is there something that has to be turned on for depth to work?

Arigato!

Beomagi

Link to comment
Share on other sites

Eh, most of the examples I used or found way back were old c - though, for some reason, your autoit library is just that much easier to follow. I really like this language.

NVM about the gdi bit - turns out my nas backup of autoit3 was rather old and errored out with a bunch of examples around here.

Did have an idea, using an off screen buffer to write text gdiplus style, and figuring out if that can be used as an open gl texture. Do have ideas, just wondering about efficiency. Worst case, I define models and call them. Guess that would be useful anyway.

One thing bugging me in my tinkering, is when calling lists to display models, it doesn't appear that the z axis has much bearing on which model is above what.

- I know this is more an opengl question than an autoit question...

e.g.

glPushMatrix();

glTranslate(0,0,z1);

glCallList(model);

glPopMatrix();

glPushMatrix();

glTranslate(0,0,z2);

glCallList(model);

glPopMatrix();

Regardless of what I use for z1/z2, the second model drawing is always on top the first model.

Is there something that has to be turned on for depth to work?

Arigato!

Beomagi

Not that I know of and that wasn't used in posted examples. Though, sometimes you have to change the view, do static rotation, if you want to see depth.

I'm pretty (and) sure there are openGL gurus hanging around but they are obviously not posting here. They have all the answers.

If you have some nice code please post, we'll all learn from that. Who knows, maybe even become gurus some day.

Domo arigato, Mr. Roboto!

(I couldn't resist)

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Well here's what I'm playing around with. It's based off your triangle example and of course those neat libraries you made. first model triangle will follow the mouse, rotation flips on holding down mouse button one.

For convenience, all three files can be snagged here http://beomagi.ath.cx/random/ogltest4.zip

Or if you prefer, here's the code, just the main file.

#include <OpenGLconstants.au3>
#include <OpenGLfunctions.au3>

Opt("GUIOnEventMode", 1)

Global Const $screenWidth = 400
Global Const $screenHeight = 300

Global $shh = $screenHeight/2;computed ahead for speed
Global $swh = $screenwidth/2
Global $swi = 1/$swh;no future division
Global $shi = 1/$shh

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 $gui = GUICreate("OpenGLtest4", $screenWidth, $screenHeight)
GUISetBkColor(0x000000)
Global $dc
EnableOpenGL($gui, $dc)
glMatrixMode($GL_PROJECTION)
glViewport(0, 0, $screenWidth, $screenHeight)

GUISetState(@SW_SHOW)

GUISetOnEvent(-3, "Quit")

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

$mousex = 0
$mousey = 0

    glNewList(1,$GL_COMPILE) ; **future** make loading function
    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();
    glEndList();

While 1         
    $a = GUIGetCursorInfo()
    $rv = 1
    if IsArray($a) Then
        $mousex = $a[0]
        $mousey = $a[1]
        If $a[2] = 1 Then
            $rv = -1;
        EndIf
    EndIf
    glClear(BitOR($GL_COLOR_BUFFER_BIT, $GL_DEPTH_BUFFER_BIT));
    
    $m -= 1*$rv ; 0.1
    
    glPushMatrix()  
    glPushMatrix()  
    gltranslatef(($mousex-$swh)*$swi,($shh-$mousey)*$shi,0);
    glRotated($m, 0, 0, 1)
    glCallList(1);
    glPopMatrix()

    glPushMatrix()  
    gltranslatef(0,0,1)
    glRotated($m-10, 0, 0, -1)  
    glCallList(1);
    glPopMatrix()
    glPopMatrix()

    SwapBuffers($dc)
    
    Sleep(33); **future** subtract timer difference for one pass of loop

WEnd



Func EnableOpenGL($hwnd, ByRef $hDC) ; **future** move to library

    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 SwapBuffers($hDC) ; **future** move to library
    DllCall("gdi32.dll", "int", "SwapBuffers", "hwnd", $hDC)
EndFunc   ;==>SwapBuffers

Func Quit()
    Exit
EndFunc

Sidenote : Holy crap firefox is slow on these forums on a netbook - though chrome flies! Took several minutes to respond on just a login >_<

Xie xie!

Beomagi

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...