Passing dll names to DllCall() loads and unloads the dll each time. This is a huge performance hit if you're doing thousands of dll calls to the same dll. You should definitely use DllOpen() / DllClose() and pass handles (it's in the documentation too).

Passing dll names to DllCall() loads and unloads the dll each time. This is a huge performance hit if you're doing thousands of dll calls to the same dll. You should definitely use DllOpen() / DllClose() and pass handles (it's in the documentation too).

Even though I call the function with the dll path the dll is only loaded once, the other times the reference count for the dll will only be incremented (this could be considered a small performance hit as well).

This is also why the optional parameter in _IsPressed() is pretty useless since it wants a handle to user32.dll which is always loaded into autoit processes anyway.

But yes, if the openGL libraries haven't even been opened at least once, it will load/unload the dll each time.

Other thing is dinamically loaded modules (made up term). Windows through LoadLibraryEx (called by LoadLibrary called by DllOpen) deals with the subject in a very subtle way. Reference count is very important part of that. You are right there. It's faster not to call by string.
But still, this is the worst mix (often seen):

I haven't looked at your UDF source, and I was replying specifically to monoceres' hypothetical. Calling DllOpen() then DllCall() with the string anyway shows an incomplete knowledge of the language, period. If you know better and do it anyway, I'm not sure what to say to that.

I agree with what both of you said about the performance hit regarding modules already loaded by AutoIt, miniscule. But this discussion was about a dll that's not loaded already by AutoIt, so the difference is significant.

@trancexx
I only mentioned because on Win7, it doesn't error out, it would actually run for the 6 hours. Setting freq to 500 and duration to 0 yields the correct results.

But no, I wasn't surprised by the results, as I said I agree with you that the performance hit in doing that is minimal. It's the same situation with base dll's like kernel32 as with monoceres' example where he calls DllOpen() first, then DllCall() with strings. It doesn't make it right though, and I don't see a reason not to do it the right way. After looking at your UDF I see you actually did it that way, so I see why you took the above comments personally. Not my intent.

In practice difference is anything but small.
Again, I'm not trying to prove you or anyone wrong if fact I don't care just an observation on my part.
I learned that actually when looking at your "OpenGL Sparkler".

Original (CPU using 0.76-12%):

AutoIt

#NoTrayIconOpt("GUIOnEventMode",1)GlobalConst$GL_VERSION_1_1=1GlobalConst$PFD_TYPE_RGBA=0GlobalConst$PFD_MAIN_PLANE=0GlobalConst$PFD_DOUBLEBUFFER=1GlobalConst$PFD_DRAW_TO_WINDOW=4GlobalConst$PFD_SUPPORT_OPENGL=32GlobalConst$GL_PROJECTION=0x1701GlobalConst$GL_COLOR_BUFFER_BIT=0x00004000GlobalConst$GL_LINES=0x0001GlobalConst$GL_SRC_COLOR=0x0300GlobalConst$GL_DST_COLOR=0x0306GlobalConst$GL_BLEND=0x0BE2GlobalConst$GL_MODELVIEW=0x1700GlobalConst$GL_DEPTH_BUFFER_BIT=0x00000100Global$hGUI=GUICreate("OpenGL Sparkler",445,445)GUISetBkColor(0x000000)Global$hDC,$hRC; device context and rendering contextIfNot_EnableOpenGL($hGUI,$hDC,$hRC)ThenMsgBox(48,"Error","Error initializing usage of OpenGL functions"&@CRLF&"Error code: "&@error)ExitEndIf_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_NCPAINTGUISetOnEvent(-3,"_Quit"); on exitGUISetState(@SW_SHOW,$hGUI)Global$mWhile1_GLDraw()$m+=.0003Sleep(10)WEndFunc_GLDraw()_glClear(BitOR($GL_COLOR_BUFFER_BIT,$GL_DEPTH_BUFFER_BIT)); cleaning buffers_glBegin($GL_LINES); gonna draw linesFor$i=1To10$i+=2*($m>.08)+3*($m>.1); blowing out$m*=($m<.14); loopingIf$m<.12Then$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 hereIfNotMod(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 hereEndIfEndIfNext_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;==>_GLDrawFunc_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@errorThenReturnSetError(1,0,0); what???EndIfIfNot$a_hCall[0]ThenIfDllOpen("opengl32.dll")=-1ThenReturnSetError(2,0,0); could not open opengl32.dllEndIfEndIf$a_hCall=DllCall("user32.dll","hwnd","GetDC","hwnd",$hWnd)If@errorOrNot$a_hCall[0]ThenReturnSetError(3,0,0); could not retrieve a handle to a device contextEndIf$hDeviceContext=$a_hCall[0]Local$a_iCall=DllCall("gdi32.dll","int","ChoosePixelFormat","hwnd",$hDeviceContext,"ptr",DllStructGetPtr($tPIXELFORMATDESCRIPTOR))If@errorOrNot$a_iCall[0]ThenReturnSetError(4,0,0); could not match an appropriate pixel formatEndIfLocal$iFormat=$a_iCall[0]$a_iCall=DllCall("gdi32.dll","int","SetPixelFormat","hwnd",$hDeviceContext,"int",$iFormat,"ptr",DllStructGetPtr($tPIXELFORMATDESCRIPTOR))If@errorOrNot$a_iCall[0]ThenReturnSetError(5,0,0); could not set the pixel format of the specified device context to the specified formatEndIf$a_hCall=DllCall("opengl32.dll","hwnd","wglCreateContext","hwnd",$hDeviceContext)If@errorOrNot$a_hCall[0]ThenReturnSetError(6,0,0); could not create a rendering contextEndIf$hOpenGLRenderingContext=$a_hCall[0]$a_iCall=DllCall("opengl32.dll","int","wglMakeCurrent","hwnd",$hDeviceContext,"hwnd",$hOpenGLRenderingContext)If@errorOrNot$a_iCall[0]ThenReturnSetError(7,0,0); failed to make the specified rendering context the calling thread's current rendering contextEndIfReturnSetError(0,0,1); all OK!EndFunc;==>_EnableOpenGLFunc_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;==>_DisableOpenGLFunc_glVertex2d($x,$y)DllCall("opengl32.dll","none","glVertex2d","double",$x,"double",$y)EndFunc;==>_glVertex2dFunc_glBegin($mode)DllCall("opengl32.dll","none","glBegin","dword",$mode)EndFunc;==>_glBeginFunc_glClear($mask)DllCall("opengl32.dll","none","glClear","dword",$mask)EndFunc;==>_glClearFunc_glColor3f($red,$green,$blue)DllCall("opengl32.dll","none","glColor3f","float",$red,"float",$green,"float",$blue)EndFunc;==>_glColor3fFunc_glEnd()DllCall("opengl32.dll","none","glEnd")EndFunc;==>_glEndFunc_glViewport($x,$y,$width,$height)DllCall("opengl32.dll","none","glViewport","int",$x,"int",$y,"int",$width,"int",$height)EndFunc;==>_glViewportFunc_glEnable($cap)DllCall("opengl32.dll","none","glEnable","dword",$cap)EndFunc;==>_glEnableFunc_glBlendFunc($sfactor,$dfactor)DllCall("opengl32.dll","none","glBlendFunc","uint",$sfactor,"dword",$dfactor)EndFunc;==>_glBlendFuncFunc_SwapBuffers($hDC)DllCall("gdi32.dll","int","SwapBuffers","hwnd",$hDC)EndFunc;==>_SwapBuffersFunc_Preserve()_SwapBuffers($hDC)EndFunc;==>_PreserveFunc_Quit()_DisableOpenGL($hGUI,$hDC,$hRC)ExitEndFunc

DllCall with reference(using CPU 0.76-3.04%):

AutoIt

#NoTrayIconOpt("GUIOnEventMode",1)Global$g=DllOpen("gdi32.dll")Global$o=DllOpen("opengl32.dll")Global$u=DllOpen("user32.dll")Global$k=DllOpen("kernel32.dll")GlobalConst$GL_VERSION_1_1=1GlobalConst$PFD_TYPE_RGBA=0GlobalConst$PFD_MAIN_PLANE=0GlobalConst$PFD_DOUBLEBUFFER=1GlobalConst$PFD_DRAW_TO_WINDOW=4GlobalConst$PFD_SUPPORT_OPENGL=32GlobalConst$GL_PROJECTION=0x1701GlobalConst$GL_COLOR_BUFFER_BIT=0x00004000GlobalConst$GL_LINES=0x0001GlobalConst$GL_SRC_COLOR=0x0300GlobalConst$GL_DST_COLOR=0x0306GlobalConst$GL_BLEND=0x0BE2GlobalConst$GL_MODELVIEW=0x1700GlobalConst$GL_DEPTH_BUFFER_BIT=0x00000100Global$hGUI=GUICreate("OpenGL Sparkler",445,445)GUISetBkColor(0x000000)Global$hDC,$hRC; device context and rendering contextIfNot_EnableOpenGL($hGUI,$hDC,$hRC)ThenMsgBox(48,"Error","Error initializing usage of OpenGL functions"&@CRLF&"Error code: "&@error)ExitEndIf_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_NCPAINTGUISetOnEvent(-3,"_Quit"); on exitGUISetState(@SW_SHOW,$hGUI)Global$mWhile1_GLDraw()$m+=.0003;Sleep(10)WEndFunc_GLDraw()_glClear(BitOR($GL_COLOR_BUFFER_BIT,$GL_DEPTH_BUFFER_BIT)); cleaning buffers_glBegin($GL_LINES); gonna draw linesFor$i=1To10$i+=2*($m>.08)+3*($m>.1); blowing out$m*=($m<.14); loopingIf$m<.12Then$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 hereIfNotMod(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 hereEndIfEndIfNext_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;==>_GLDrawFunc_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($k,"hwnd","GetModuleHandleW","wstr",$o)If@errorThenReturnSetError(1,0,0); what???EndIf;If Not $a_hCall[0] Then; If DllOpen($o) = -1 Then; Return SetError(2, 0, 0) ; could not open opengl32.dll; EndIf;EndIf$a_hCall=DllCall($u,"hwnd","GetDC","hwnd",$hWnd)If@errorOrNot$a_hCall[0]ThenReturnSetError(3,0,0); could not retrieve a handle to a device contextEndIf$hDeviceContext=$a_hCall[0]Local$a_iCall=DllCall($g,"int","ChoosePixelFormat","hwnd",$hDeviceContext,"ptr",DllStructGetPtr($tPIXELFORMATDESCRIPTOR))If@errorOrNot$a_iCall[0]ThenReturnSetError(4,0,0); could not match an appropriate pixel formatEndIfLocal$iFormat=$a_iCall[0]$a_iCall=DllCall($g,"int","SetPixelFormat","hwnd",$hDeviceContext,"int",$iFormat,"ptr",DllStructGetPtr($tPIXELFORMATDESCRIPTOR))If@errorOrNot$a_iCall[0]ThenReturnSetError(5,0,0); could not set the pixel format of the specified device context to the specified formatEndIf$a_hCall=DllCall($o,"hwnd","wglCreateContext","hwnd",$hDeviceContext)If@errorOrNot$a_hCall[0]ThenReturnSetError(6,0,0); could not create a rendering contextEndIf$hOpenGLRenderingContext=$a_hCall[0]$a_iCall=DllCall($o,"int","wglMakeCurrent","hwnd",$hDeviceContext,"hwnd",$hOpenGLRenderingContext)If@errorOrNot$a_iCall[0]ThenReturnSetError(7,0,0); failed to make the specified rendering context the calling thread's current rendering contextEndIfReturnSetError(0,0,1); all OK!EndFunc;==>_EnableOpenGLFunc_DisableOpenGL($hWnd,$hDeviceContext,$hOpenGLRenderingContext); No point in doing error checking if this is done on exit. Will just call the cleaning functions.DllCall($o,"int","wglMakeCurrent","hwnd",$hDeviceContext,"hwnd",0)DllCall($o,"int","wglDeleteContext","hwnd",$hOpenGLRenderingContext)DllCall($u,"int","ReleaseDC","hwnd",$hWnd,"hwnd",$hDeviceContext)DllCall($g,"int","DeleteDC","hwnd",$hDeviceContext)EndFunc;==>_DisableOpenGLFunc_glVertex2d($x,$y)DllCall($o,"none","glVertex2d","double",$x,"double",$y)EndFunc;==>_glVertex2dFunc_glBegin($mode)DllCall($o,"none","glBegin","dword",$mode)EndFunc;==>_glBeginFunc_glClear($mask)DllCall($o,"none","glClear","dword",$mask)EndFunc;==>_glClearFunc_glColor3f($red,$green,$blue)DllCall($o,"none","glColor3f","float",$red,"float",$green,"float",$blue)EndFunc;==>_glColor3fFunc_glEnd()DllCall($o,"none","glEnd")EndFunc;==>_glEndFunc_glViewport($x,$y,$width,$height)DllCall($o,"none","glViewport","int",$x,"int",$y,"int",$width,"int",$height)EndFunc;==>_glViewportFunc_glEnable($cap)DllCall($o,"none","glEnable","dword",$cap)EndFunc;==>_glEnableFunc_glBlendFunc($sfactor,$dfactor)DllCall($o,"none","glBlendFunc","uint",$sfactor,"dword",$dfactor)EndFunc;==>_glBlendFuncFunc_SwapBuffers($hDC)DllCall($g,"int","SwapBuffers","hwnd",$hDC)EndFunc;==>_SwapBuffersFunc_Preserve()_SwapBuffers($hDC)EndFunc;==>_PreserveFunc_Quit()_DisableOpenGL($hGUI,$hDC,$hRC)DllClose($g)DllClose($o)DllClose($u)DllClose($k)ExitEndFunc;==>_Quit

I know what you mean about Global vars. When i program i am always aware of what variable names i am using and i have unwritten rules for myself to prevent the conflicts or unwanted interactions.
It is rewarding enough to optimize the code with Globals. I learn from experience more then I do from anything else and from what I seen so far no matter C++ or Autoit Globals are faster.

Here's another OpenGL example in AutoIt.
It's 3D rotation.
Will draw square pyramid and do rotation (not the way it's expected - to make it more interesting).

AutoIt

#NoTrayIconOpt("GUIOnEventMode",1)Opt("MustDeclareVars",1); Used DllsGlobalConst$hUSER32=DllOpen("user32.dll")GlobalConst$hGDI32=DllOpen("gdi32.dll")GlobalConst$hOPENGL32=DllOpen("opengl32.dll"); General constantsGlobalConst$PFD_TYPE_RGBA=0GlobalConst$PFD_MAIN_PLANE=0GlobalConst$PFD_DOUBLEBUFFER=1GlobalConst$PFD_DRAW_TO_WINDOW=4GlobalConst$PFD_SUPPORT_OPENGL=32; Used GL constants. See OpenGLConstants.au3GlobalConst$GL_VERSION_1_1=1GlobalConst$GL_COLOR_BUFFER_BIT=0x00004000GlobalConst$GL_TRIANGLES=0x0004GlobalConst$GL_BLEND=0x0BE2GlobalConst$GL_ONE=1GlobalConst$GL_DEPTH_BUFFER_BIT=0x00000100; Create GUIGlobal$iWidth=450Global$iHeight=450Global$hGUI=GUICreate("OpenGL 3D Rotation",$iWidth,$iHeight)GUISetBkColor(0); black; Enable OpenGLGlobal$hDC,$hRC; device context and rendering contextIfNot_EnableOpenGL($hGUI,$hDC,$hRC)ThenMsgBox(48,"Error","Error initializing usage of OpenGL functions"&@CRLF&"Error code: "&@error)ExitEndIf; 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 timeGUIRegisterMsg(133,"_Preserve"); WM_NCPAINT; Handle exitGUISetOnEvent(-3,"_Quit"); on exit; Show GUIGUISetState(@SW_SHOW,$hGUI)Global$nM; this to use for rotation; Loop and draw till exitWhile1_GLDraw()Sleep(20)WEnd; Main drawing functionFunc_GLDraw()_glClear(BitOR($GL_COLOR_BUFFER_BIT,$GL_DEPTH_BUFFER_BIT)); cleaning buffers$nM-=0.5; decreasing. To rotate otherwise do increasing_glPopMatrix()_glPushMatrix()_glRotatef($nM,1,1,1); this is actual rotation_glBegin($GL_TRIANGLES); draw triangle; Will make square pyramid_glColor3f(0.5,0,0); red nuance_glVertex3f(0,0.5,0); front top_glColor3f(0,0.5,0); green nuance_glVertex3f(-0.5,-0.5,0.5); front left_glColor3f(0,0,0.5); blue nuance_glVertex3f(0.5,-0.5,0.5); front right_glColor3f(0.5,0,0); red nuance_glVertex3f(0,0.5,0); top right_glColor3f(0,0,0.5); blue nuance_glVertex3f(0.5,-0.5,0.5); left right_glColor3f(0,0.5,0); green nuance_glVertex3f(0.5,-0.5,-0.5); right right_glColor3f(0.5,0,0); red nuance_glVertex3f(0,0.5,0); top back_glColor3f(0,0.5,0); green nuance_glVertex3f(0.5,-0.5,-0.5); left back_glColor3f(0,0,0.5); blue nuance_glVertex3f(-0.5,-0.5,-0.5); right back_glColor3f(0.5,0,0); red nuance_glVertex3f(0,0.5,0); top left_glColor3f(0,0,0.5); blue nuance_glVertex3f(-0.5,-0.5,-0.5); left left_glColor3f(0,0.5,0); green nuance_glVertex3f(-0.5,-0.5,0.5); right left; That's it_glEnd(); end drawing_SwapBuffers($hDC); "refresh"EndFunc;==>_GLDraw; USED FUNCTIONS; This is needed for initializationFunc_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@errorOrNot$a_hCall[0]ThenReturnSetError(1,0,0); could not retrieve a handle to a device contextEndIf$hDeviceContext=$a_hCall[0]Local$a_iCall=DllCall($hGDI32,"int","ChoosePixelFormat","hwnd",$hDeviceContext,"ptr",DllStructGetPtr($tPIXELFORMATDESCRIPTOR))If@errorOrNot$a_iCall[0]ThenReturnSetError(2,0,0); could not match an appropriate pixel formatEndIfLocal$iFormat=$a_iCall[0]$a_iCall=DllCall($hGDI32,"int","SetPixelFormat","hwnd",$hDeviceContext,"int",$iFormat,"ptr",DllStructGetPtr($tPIXELFORMATDESCRIPTOR))If@errorOrNot$a_iCall[0]ThenReturnSetError(3,0,0); could not set the pixel format of the specified device context to the specified formatEndIf$a_hCall=DllCall($hOPENGL32,"hwnd","wglCreateContext","hwnd",$hDeviceContext)If@errorOrNot$a_hCall[0]ThenReturnSetError(4,0,0); could not create a rendering contextEndIf$hOPENGL32RenderingContext=$a_hCall[0]$a_iCall=DllCall($hOPENGL32,"int","wglMakeCurrent","hwnd",$hDeviceContext,"hwnd",$hOPENGL32RenderingContext)If@errorOrNot$a_iCall[0]ThenReturnSetError(5,0,0); failed to make the specified rendering context the calling thread's current rendering contextEndIfReturnSetError(0,0,1); all OK!EndFunc;==>_EnableOpenGL; This is cleaning functionFunc_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 functionsFunc_glBegin($iMode)DllCall($hOPENGL32,"none","glBegin","dword",$iMode)EndFunc;==>_glBeginFunc_glBlendFunc($iSfactor,$iDfactor)DllCall($hOPENGL32,"none","glBlendFunc","dword",$iSfactor,"dword",$iDfactor)EndFunc;==>_glBlendFuncFunc_glClear($iMask)DllCall($hOPENGL32,"none","glClear","dword",$iMask)EndFunc;==>_glClearFunc_glColor3f($red,$green,$blue)DllCall($hOPENGL32,"none","glColor3f","float",$red,"float",$green,"float",$blue)EndFunc;==>_glColor3fFunc_glEnable($iCap)DllCall($hOPENGL32,"none","glEnable","dword",$iCap)EndFunc;==>_glEnableFunc_glEnd()DllCall($hOPENGL32,"none","glEnd")EndFunc;==>_glEndFunc_glLoadIdentity()DllCall($hOPENGL32,"none","glLoadIdentity")EndFunc;==>_glLoadIdentityFunc_glPopMatrix()DllCall($hOPENGL32,"none","glPopMatrix")EndFunc;==>_glPopMatrixFunc_glPushMatrix()DllCall($hOPENGL32,"none","glPushMatrix")EndFunc;==>_glPushMatrixFunc_glRotatef($nAngle,$nX,$nY,$nZ)DllCall($hOPENGL32,"none","glRotatef","float",$nAngle,"float",$nX,"float",$nY,"float",$nZ)EndFunc;==>_glRotatefFunc_glVertex3f($x,$y,$z)DllCall($hOPENGL32,"none","glVertex3f","float",$x,"float",$y,"float",$z)EndFunc;==>_glVertex3fFunc_glViewport($iX,$iY,$iWidth,$iHeight)DllCall($hOPENGL32,"none","glViewport","int",$iX,"int",$iY,"dword",$iWidth,"dword",$iHeight)EndFunc;==>_glViewportFunc_glClearColor($nRed,$nGreen,$nBlue,$nAlpha)DllCall($hOPENGL32,"none","glClearColor","float",$nRed,"float",$nGreen,"float",$nBlue,"float",$nAlpha)EndFunc;==>_glClearColor; Other functionsFunc_SwapBuffers($hDC)DllCall($hGDI32,"int","SwapBuffers","hwnd",$hDC)EndFunc;==>_SwapBuffers; Two more used functions (wrappers)Func_Preserve()_SwapBuffers($hDC)EndFunc;==>_PreserveFunc_Quit()_DisableOpenGL($hGUI,$hDC,$hRC)ExitEndFunc;==>_Quit

Here's one more. This time two parallel planes are manipulated. What's really new is drawing text.

AutoIt

#NoTrayIconOpt("GUIOnEventMode",1)Opt("MustDeclareVars",1); Used DllsGlobalConst$hUSER32=DllOpen("user32.dll")GlobalConst$hGDI32=DllOpen("gdi32.dll")GlobalConst$hOPENGL32=DllOpen("opengl32.dll"); General constantsGlobalConst$PFD_TYPE_RGBA=0GlobalConst$PFD_MAIN_PLANE=0GlobalConst$PFD_DOUBLEBUFFER=1GlobalConst$PFD_DRAW_TO_WINDOW=4GlobalConst$PFD_SUPPORT_OPENGL=32; Used GL constants. See OpenGLConstants.au3GlobalConst$GL_VERSION_1_1=1GlobalConst$GL_COLOR_BUFFER_BIT=0x00004000GlobalConst$GL_QUADS=0x0007GlobalConst$GL_BLEND=0x0BE2GlobalConst$GL_ONE=1GlobalConst$GL_DEPTH_BUFFER_BIT=0x00000100GlobalConst$GL_ALL_ATTRIB_BITS=0x000FFFFFGlobalConst$GL_TRANSFORM_BIT=0x00001000GlobalConst$GL_VIEWPORT_BIT=0x00000800GlobalConst$GL_LIST_BIT=0x00020000GlobalConst$GL_UNSIGNED_BYTE=0x1401; Create GUIGlobal$iWidth=450Global$iHeight=450Global$hGUI=GUICreate("OpenGL 3D rotation and font demo",$iWidth,$iHeight)GUISetBkColor(0); black; Enable OpenGLGlobal$hDC,$hRC; device context and rendering contextIfNot_EnableOpenGL($hGUI,$hDC,$hRC)ThenMsgBox(48,"Error","Error initializing usage of OpenGL functions"&@CRLF&"Error code: "&@error)ExitEndIf; FontGlobal$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 timeGUIRegisterMsg(133,"_Preserve"); WM_NCPAINT; Handle exitGUISetOnEvent(-3,"_Quit"); on exit; Show GUIGUISetState(@SW_SHOW,$hGUI)Global$nM; this to be used for rotation; Loop and draw till exitWhile1_GLDraw()Sleep(25)WEnd; Main drawing functionFunc_GLDraw()_glClear(BitOR($GL_COLOR_BUFFER_BIT,$GL_DEPTH_BUFFER_BIT)); cleaning buffers$nM-=0.5; decreasing. To rotate otherwise do increasing_glPopMatrix()_glPushMatrix();Draw text_glColor3f(0.2,0.3,0.9); color of text_glDrawText(-0.8,-0.3,"3D rotation/translation of two",$hFontList)_glColor3f(0.8,0.8,0.2); new color_glDrawText(-0.45,-0.5,"parallel planes",$hFontList); Rotate_glRotatef($nM,1,1,1); Start drawing_glBegin($GL_QUADS); Will make plane_glColor3f(0.7,0,0); red nuance_glVertex3f(0.5,0.5,0); front top_glColor3f(0.7,0.7,0); yellow nuance_glVertex3f(0.5,-0.5,0); front right_glColor3f(0,0.7,0); green nuance_glVertex3f(-0.5,-0.5,0); front left_glColor3f(0,0,0.7); blue nuance_glVertex3f(-0.5,0.5,0); front top; That's it; End drawing_glEnd(); Dislocate it_glTranslatef(0.1,0.1,0.3); Start drawing again_glBegin($GL_QUADS); Will make new plane_glColor3f(0.7,0,0); red nuance_glVertex3f(0.5,0.5,0); front top_glColor3f(0.7,0.7,0); yellow nuance_glVertex3f(0.5,-0.5,0); front right_glColor3f(0,0.7,0); green nuance_glVertex3f(-0.5,-0.5,0); front left_glColor3f(0,0,0.7); blue nuance_glVertex3f(-0.5,0.5,0); front top; That's it; End drawing_glEnd(); Replace old with the new one_SwapBuffers($hDC)EndFunc;==>_GLDraw; USED FUNCTIONS; This is needed for initializationFunc_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@errorOrNot$a_hCall[0]ThenReturnSetError(1,0,0); could not retrieve a handle to a device contextEndIf$hDeviceContext=$a_hCall[0]Local$a_iCall=DllCall($hGDI32,"int","ChoosePixelFormat","hwnd",$hDeviceContext,"ptr",DllStructGetPtr($tPIXELFORMATDESCRIPTOR))If@errorOrNot$a_iCall[0]ThenReturnSetError(2,0,0); could not match an appropriate pixel formatEndIfLocal$iFormat=$a_iCall[0]$a_iCall=DllCall($hGDI32,"int","SetPixelFormat","hwnd",$hDeviceContext,"int",$iFormat,"ptr",DllStructGetPtr($tPIXELFORMATDESCRIPTOR))If@errorOrNot$a_iCall[0]ThenReturnSetError(3,0,0); could not set the pixel format of the specified device context to the specified formatEndIf$a_hCall=DllCall($hOPENGL32,"hwnd","wglCreateContext","hwnd",$hDeviceContext)If@errorOrNot$a_hCall[0]ThenReturnSetError(4,0,0); could not create a rendering contextEndIf$hOPENGL32RenderingContext=$a_hCall[0]$a_iCall=DllCall($hOPENGL32,"int","wglMakeCurrent","hwnd",$hDeviceContext,"hwnd",$hOPENGL32RenderingContext)If@errorOrNot$a_iCall[0]ThenReturnSetError(5,0,0); failed to make the specified rendering context the calling thread's current rendering contextEndIfReturnSetError(0,0,1); all OK!EndFunc;==>_EnableOpenGL; This is cleaning functionFunc_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;==>_glBeginFunc_glBlendFunc($iSfactor,$iDfactor)DllCall($hOPENGL32,"none","glBlendFunc","dword",$iSfactor,"dword",$iDfactor)EndFunc;==>_glBlendFuncFunc_glCallListsChar($iSize,$iType,$pList)DllCall($hOPENGL32,"none","glCallLists","dword",$iSize,"dword",$iType,"str",$pList)EndFunc;==>_glCallListsCharFunc_glClear($iMask)DllCall($hOPENGL32,"none","glClear","dword",$iMask)EndFunc;==>_glClearFunc_glClearColor($nRed,$nGreen,$nBlue,$nAlpha)DllCall($hOPENGL32,"none","glClearColor","float",$nRed,"float",$nGreen,"float",$nBlue,"float",$nAlpha)EndFunc;==>_glClearColorFunc_glColor3f($nRed,$nGreen,$nBlue)DllCall($hOPENGL32,"none","glColor3f","float",$nRed,"float",$nGreen,"float",$nBlue)EndFunc;==>_glColor3fFunc_glColor4f($nRed,$nGreen,$nBlue,$nAlpha)DllCall($hOPENGL32,"none","glColor4f","float",$nRed,"float",$nGreen,"float",$nBlue,"float",$nAlpha)EndFunc;==>_glColor4fFunc_glEnable($iCap)DllCall($hOPENGL32,"none","glEnable","dword",$iCap)EndFunc;==>_glEnableFunc_glEnd()DllCall($hOPENGL32,"none","glEnd")EndFunc;==>_glEndFunc_glListBase($iBase)DllCall($hOPENGL32,"none","glListBase","dword",$iBase)EndFunc;==>_glListBaseFunc_glLoadIdentity()DllCall($hOPENGL32,"none","glLoadIdentity")EndFunc;==>_glLoadIdentityFunc_glPopAttrib()DllCall($hOPENGL32,"none","glPopAttrib")EndFunc;==>_glPopAttribFunc_glPopMatrix()DllCall($hOPENGL32,"none","glPopMatrix")EndFunc;==>_glPopMatrixFunc_glPushAttrib($iMask)DllCall($hOPENGL32,"none","glPushAttrib","dword",$iMask)EndFunc;==>_glPushAttribFunc_glPushMatrix()DllCall($hOPENGL32,"none","glPushMatrix")EndFunc;==>_glPushMatrixFunc_glRotatef($nAngle,$nX,$nY,$nZ)DllCall($hOPENGL32,"none","glRotatef","float",$nAngle,"float",$nX,"float",$nY,"float",$nZ)EndFunc;==>_glRotatefFunc_glRasterPos2f($nX,$nY)DllCall($hOPENGL32,"none","glRasterPos2f","float",$nX,"float",$nY)EndFunc;==>_glRasterPos2fFunc_glTranslatef($nX,$nY,$nZ)DllCall($hOPENGL32,"none","glTranslatef","float",$nX,"float",$nY,"float",$nZ)EndFunc;==>_glTranslatefFunc_glVertex3f($nX,$nY,$nZ)DllCall($hOPENGL32,"none","glVertex3f","float",$nX,"float",$nY,"float",$nZ)EndFunc;==>_glVertex3fFunc_glViewport($iX,$iY,$iWidth,$iHeight)DllCall($hOPENGL32,"none","glViewport","int",$iX,"int",$iY,"dword",$iWidth,"dword",$iHeight)EndFunc;==>_glViewport; Other functionsFunc_SwapBuffers($hDC)DllCall($hGDI32,"int","SwapBuffers","hwnd",$hDC)EndFunc;==>_SwapBuffers; Few more used functions (wrappers)Func_Preserve()_SwapBuffers($hDC)EndFunc;==>_PreserveFunc_Quit()_DisableOpenGL($hGUI,$hDC,$hRC)ExitEndFunc;==>_QuitFunc_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 functionFunc_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@errorOrNot$aCall[0]ThenReturnSetError(1,0,0)EndIfLocal$hDC=$aCall[0]; This is needed to propery determine the size of the new font$aCall=DllCall($hGDI32,"int","GetDeviceCaps",_"hwnd",$hDC,_"int",90); LOGPIXELSYIf@errorOrNot$aCall[0]ThenReturnSetError(2,0,0)EndIfLocal$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$iQualityIfBitAND($iAttribute,16)Then$iQuality=1; DRAFT_QUALITYElseIfBitAND($iAttribute,32)Then$iQuality=2; PROOF_QUALITYElseIfBitAND($iAttribute,64)Then$iQuality=3; NONANTIALIASED_QUALITYElseIfBitAND($iAttribute,128)Then$iQuality=4; ANTIALIASED_QUALITYElseIfBitAND($iAttribute,256)Then$iQuality=5; CLEARTYPE_QUALITYElseIfBitAND($iAttribute,512)Then$iQuality=6; CLEARTYPE_COMPAT_QUALITYEndIf; 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@errorOrNot$aCall[0]ThenReturnSetError(3,0,0)EndIfLocal$hFont=$aCall[0]; New font to DC$aCall=DllCall($hGDI32,"hwnd","SelectObject","hwnd",$hDC,"hwnd",$hFont)If@errorOrNot$aCall[0]ThenDllCall($hGDI32,"int","DeleteObject","hwnd",$hFont)ReturnSetError(4,0,0)EndIf; This was beforeLocal$hOldFont=$aCall[0]; If old FontList is passed delete it to free memory.If$hFontListThenDllCall($hOPENGL32,"dword","glDeleteLists","dword",$hFontList,"dword",$iNumberOf); Generate empty display list$aCall=DllCall($hOPENGL32,"dword","glGenLists","dword",1)If@errorOrNot$aCall[0]ThenDllCall($hGDI32,"int","DeleteObject","hwnd",$hFont)ReturnSetError(5,0,0)EndIf$hFontList=$aCall[0]; Make glyph bitmaps$aCall=DllCall($hOPENGL32,"int","wglUseFontBitmapsW",_"ptr",$hDC,_"dword",0,_"dword",256,_"ptr",$hFontList)If@errorOrNot$aCall[0]ThenDllCall($hGDI32,"int","DeleteObject","hwnd",$hFont)ReturnSetError(6,0,0)EndIf; There can be only one. Delete old font.DllCall($hGDI32,"int","DeleteObject","hwnd",$hOldFont); All OK. Return FontListReturnSetError(0,0,$hFontList)EndFunc;==>_CreateOpenGLFont