Leaderboard
Popular Content
Showing content with the highest reputation on 05/08/2020 in all areas
-
I had this GIF animation script, but it was kind of slow when multiple GIFs were displayed. And then Bilgus posted a framework of how to use GDI+ Cached Bitmaps. I transformed my script and was very happy of the result. Hope you like it too. I enclosed the GIF, the UDF and the example into the zip file. ps. Hope KaFu won't mind as I used his avatar in the example Version 2023-08-15 * Added support for SetOnEvent GUI, while deletion of controls happens frequently * Optimized some minor code parts * Solved a possible stack overflow issue Version 2022-12-06 * Added support to transparent GIF over window background. The type of GIF that necessitate erasure between frames. Version 2022-04-07 * Added double buffering for all GIF * Added ability to erase each frame before repainting, thru a new optional parameter. This is required when the frames do not cover the whole area, leaving a trace of the previous frame. * Added support for the usage of the Default keyword for optional parameters Version 2020-12-20 * Changed frame delays from 0 to a minimum delay to prevent CPU overload Version 2020-12-02 * Reuse empty slots left by the deletion of GIF controls * Corrected bugs Version 2020-12-01 * Added support to delete a GIF control Version 2020-11-29 * Corrected bug on unregister adlib function (thanks to PixelSearch) Included in the zip file 2 examples. One with multiple GIF. Second with transparent GIF over a window background. Cached GIF Animation.zip3 points
-
I was inspired by a CSS example to create a procedural graphic without any shader or ray tracing technique. Here the result using GDI+ only: Blue Orb.au3 ;Inspired from https://codepen.io/bradleytaunt/details/VwvzKyb ;Coded by UEZ build 2020-05-07 #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> If @OSBuild < 7600 Then Exit MsgBox(BitOR($MB_TOPMOST, $MB_ICONERROR), "ERROR", "This demo requires GDIPlus v1.1", 10) _GDIPlus_Startup() Global Const $iW = 1200, $iH = 700, $iSize_globe = 450 Global Const $hGUI = GUICreate("GDI+ Procedural Gfx / Blue Orb v1.20 by UEZ", $iW, $iH, -1, -1, $WS_POPUP, $WS_EX_TOPMOST) Global Const $hCanvas = _GDIPlus_GraphicsCreateFromHWND($hGUI) Global Const $hImage = _GDIPlus_BitmapCreateFromScan0($iW, $iH) Global Const $hGfx = _GDIPlus_ImageGetGraphicsContext($hImage) _GDIPlus_GraphicsSetSmoothingMode($hGfx, $GDIP_SMOOTHINGMODE_ANTIALIAS8X8) ;~ _GDIPlus_GraphicsSetCompositingQuality($hGfx, $GDIP_COMPOSITINGQUALITYHIGHQUALITY) _GDIPlus_GraphicsSetInterpolationMode($hGfx, $GDIP_INTERPOLATIONMODE_HIGHQUALITYBICUBIC) _GDIPlus_GraphicsSetPixelOffsetMode($hGfx, $GDIP_PIXELOFFSETMODE_HALF) ;draw background Global Const $hBrush_bg = _GDIPlus_LineBrushCreate($iW / 2, 0, $iW / 2, $iH / 2, 0xFF1E88E5, 0xFF1565C0, 2) _GDIPlus_LineBrushSetSigmaBlend ($hBrush_bg, 0.95, 1) ;create blurry edge _GDIPlus_GraphicsFillRect($hGfx, 0, 0, $iW, $iH, $hBrush_bg) ;draw blurred text Global Const $hImage_text = _GDIPlus_BitmapCreateFromScan0($iW, $iH / 2) Global Const $hGfx_text = _GDIPlus_ImageGetGraphicsContext($hImage_text) Global Const $hPath_text = _GDIPlus_PathCreate() Global Const $hFamily = _GDIPlus_FontFamilyCreate("Impact") Global Const $hStringFormat = _GDIPlus_StringFormatCreate() Global Const $hBrush_txt = _GDIPlus_LineBrushCreate($iW / 2, 0, $iW / 2, $iH / 2, 0xE0FFFFFF, 0xA01A237E) ;_GDIPlus_BrushCreateSolid(0xF02E86FB) _GDIPlus_LineBrushSetSigmaBlend($hBrush_txt, 0.66, 1) Global Const $hPen_txt = _GDIPlus_PenCreate(0x801A237E, 1) _GDIPlus_StringFormatSetAlign($hStringFormat, 1) _GDIPlus_StringFormatSetLineAlign($hStringFormat, 1) _GDIPlus_GraphicsSetSmoothingMode($hGfx_text, $GDIP_SMOOTHINGMODE_ANTIALIAS8X8) _GDIPlus_GraphicsSetTextRenderingHint($hGfx_text, $GDIP_TextRenderingHintAntialias) _GDIPlus_GraphicsSetPixelOffsetMode($hGfx_text, $GDIP_PIXELOFFSETMODE_HALF) _GDIPlus_GraphicsSetCompositingQuality($hGfx_text, $GDIP_COMPOSITINGQUALITYHIGHQUALITY) Global $tLayout = _GDIPlus_RectFCreate() $tLayout.width = $iW $tLayout.height = $iH / 2 $tLayout.y = -$iH * 0.05 _GDIPlus_PathAddString($hPath_text, "AutoIt rulez!", $tLayout, $hFamily, 0, $iW / 8, $hStringFormat) _GDIPlus_GraphicsFillPath($hGfx_text, $hPath_text, $hBrush_txt) _GDIPlus_GraphicsDrawPath($hGfx_text, $hPath_text, $hPen_txt) Global Const $hEffect_blur_text = _GDIPlus_EffectCreateBlur(20) _GDIPlus_BitmapApplyEffect($hImage_text, $hEffect_blur_text) _GDIPlus_GraphicsDrawImageRect($hGfx, $hImage_text, 0, 0, $iW, $iH / 2) ;draw shadow of the text Global Const $hBrush_txt_shadow = _GDIPlus_BrushCreateSolid(0x40000000) _GDIPlus_GraphicsClear($hGfx_text, 0) _GDIPlus_PathReset($hPath_text) $tLayout.width = $iW $tLayout.height = $iH / 2 $tLayout.y = 0 _GDIPlus_PathAddString($hPath_text, "AutoIt rulez!", $tLayout, $hFamily, 0, $iW / 8, $hStringFormat) _GDIPlus_GraphicsFillPath($hGfx_text, $hPath_text, $hBrush_txt_shadow) Global Const $hEffect_blur_text_shadow = _GDIPlus_EffectCreateBlur(60) _GDIPlus_BitmapApplyEffect($hImage_text, $hEffect_blur_text_shadow) _GDIPlus_GraphicsDrawImageRect($hGfx, $hImage_text, 0, $iH * 0.55, $iW, $iH / 8) ;draw shadow Global Const $iW_shadow1 = $iSize_globe * 0.85, $iH_shadow1 = $iSize_globe * 0.1, $iW_shadow2 = $iSize_globe * 0.60, _ $iW_shadow_Img = $iW_shadow1 * 2, $iH_shadowImg = $iH_shadow1 * 4 Global Const $hImage_shadow = _GDIPlus_BitmapCreateFromScan0($iW_shadow_Img, $iH_shadowImg) Global Const $hGfx_shadow = _GDIPlus_ImageGetGraphicsContext($hImage_shadow) _GDIPlus_GraphicsSetSmoothingMode($hGfx_shadow, $GDIP_SMOOTHINGMODE_ANTIALIAS8X8) Global Const $hBrush_shadow = _GDIPlus_BrushCreateSolid(0x66000000) _GDIPlus_GraphicsFillEllipse($hGfx_shadow, ($iW_shadow_Img - $iW_shadow1) / 2, ($iH_shadowImg / 4 + $iH_shadow1), $iW_shadow1, $iH_shadow1, $hBrush_shadow) _GDIPlus_BrushSetSolidColor($hBrush_shadow, 0xB3000000) _GDIPlus_GraphicsFillEllipse($hGfx_shadow, ($iW_shadow_Img - $iW_shadow2) / 2, ($iH_shadowImg / 4 + $iH_shadow1), $iW_shadow2, $iH_shadow1, $hBrush_shadow) Global Const $hEffect_blur_shadow = _GDIPlus_EffectCreateBlur(32) _GDIPlus_BitmapApplyEffect($hImage_shadow, $hEffect_blur_shadow) _GDIPlus_GraphicsDrawImageRect($hGfx, $hImage_shadow, ($iW - $iW_shadow_Img) / 2, $iH / 2 + $iH_shadow1 * 2.20, $iW_shadow_Img, $iH_shadowImg) ;draw globe Global Const $hPath_globe = _GDIPlus_PathCreate() _GDIPlus_PathAddEllipse($hPath_globe, ($iW - $iSize_globe) / 2, ($iH - $iSize_globe) / 2, $iSize_globe, $iSize_globe) Global Const $hLBrush_globe1 = _GDIPlus_LineBrushCreate($iW / 2, ($iH - $iSize_globe) / 2, $iW / 2, ($iH + $iSize_globe) / 2, 0, 0, 1) Global $aInterpolations[5][2] $aInterpolations[0][0] = 4 $aInterpolations[1][0] = 0xFFFFFFFF $aInterpolations[1][1] = 0 $aInterpolations[2][0] = 0xFFEEEEEE $aInterpolations[2][1] = 0.10 $aInterpolations[3][0] = 0xFF2E86FB $aInterpolations[3][1] = 0.50 $aInterpolations[4][0] = 0xFF1A237E $aInterpolations[4][1] = 1.0 _GDIPlus_LineBrushSetPresetBlend($hLBrush_globe1, $aInterpolations) _GDIPlus_GraphicsFillPath($hGfx, $hPath_globe, $hLBrush_globe1) Global Const $iSize_globe2 = $iSize_globe * 0.85, $iSize_globe2_Img = $iSize_globe2 * 1.5 Global Const $hImage_globe2 = _GDIPlus_BitmapCreateFromScan0($iSize_globe2_Img, $iSize_globe2_Img) Global Const $hGfx_globe2 = _GDIPlus_ImageGetGraphicsContext($hImage_globe2) Global Const $hBrush_globe2 = _GDIPlus_BrushCreateSolid(0x7F000000) ;draw shadow and blur it Global Const $px = ($iSize_globe2_Img - $iSize_globe2) / 2, $py = ($iSize_globe2_Img - $iSize_globe2) / 2 _GDIPlus_GraphicsFillEllipse($hGfx_globe2, $px, $py + ($iSize_globe - $iSize_globe2) * 0.25, $iSize_globe2, $iSize_globe2, $hBrush_globe2) Global Const $hEffect_blur_shadow2 = _GDIPlus_EffectCreateBlur(15) _GDIPlus_BitmapApplyEffect($hImage_globe2, $hEffect_blur_shadow2) ;draw 2nd smaller globe and blur it, too Global Const $hLBrush_globe2 = _GDIPlus_LineBrushCreate($iW / 2, $py, $iW / 2, $py + $iSize_globe2, 0, 0) Dim $aInterpolations[4][2] $aInterpolations[0][0] = 3 $aInterpolations[1][0] = 0xFFFFFFFF $aInterpolations[1][1] = 0 $aInterpolations[2][0] = 0xFF2E86FB $aInterpolations[2][1] = 0.60 $aInterpolations[3][0] = 0xFF283593 $aInterpolations[3][1] = 1.0 _GDIPlus_LineBrushSetPresetBlend($hLBrush_globe2, $aInterpolations) _GDIPlus_GraphicsFillEllipse($hGfx_globe2, $px, $py, $iSize_globe2, $iSize_globe2, $hLBrush_globe2) Global Const $hImage_globe2_blur = _Blur($hImage_globe2, $iSize_globe, $iSize_globe) ;windows gdi+ blur doesn't work properly _GDIPlus_GraphicsDrawImageRect($hGfx, $hImage_globe2_blur, ($iW - $iSize_globe2_Img) / 2 - ($iSize_globe - $iSize_globe2) / 8, ($iH - $iSize_globe2_Img) / 2, $iSize_globe2_Img, $iSize_globe2_Img) GUISetState() _GDIPlus_GraphicsDrawImageRect($hCanvas, $hImage, 0, 0, $iW, $iH) ;~ _GDIPlus_ImageSaveToFile($hImage, @ScriptDir & "\Blue Orb v1.20.png") ;clean-up ressources _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hStringFormat) _GDIPlus_EffectDispose($hEffect_blur_text) _GDIPlus_EffectDispose($hEffect_blur_text_shadow) _GDIPlus_EffectDispose($hEffect_blur_shadow) _GDIPlus_EffectDispose($hEffect_blur_shadow2) _GDIPlus_PathDispose($hPath_text) _GDIPlus_PathDispose($hPath_globe) _GDIPlus_PenDispose($hPen_txt) _GDIPlus_BrushDispose($hBrush_txt) _GDIPlus_BrushDispose($hBrush_txt_shadow) _GDIPlus_BrushDispose($hBrush_bg) _GDIPlus_BrushDispose($hLBrush_globe1) _GDIPlus_BrushDispose($hLBrush_globe2) _GDIPlus_BrushDispose($hBrush_globe2) _GDIPlus_ImageDispose($hImage) _GDIPlus_ImageDispose($hImage_text) _GDIPlus_ImageDispose($hImage_shadow) _GDIPlus_ImageDispose($hImage_globe2) _GDIPlus_ImageDispose($hImage_globe2_blur) _GDIPlus_GraphicsDispose($hCanvas) _GDIPlus_GraphicsDispose($hGfx_text) _GDIPlus_GraphicsDispose($hGfx_shadow) _GDIPlus_GraphicsDispose($hGfx_globe2) _GDIPlus_Shutdown() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete($hGUI) Exit Func _Blur($hBitmap, $iW, $iH, $fScale = 0.0525, $dx1 = 0, $dy1 = 0, $dx2 = 0, $dy2 = 0, $qual = 6) ; by eukalyptus Local $hBmpSmall = _GDIPlus_BitmapCreateFromScan0($iW, $iH) Local $hGfxSmall = _GDIPlus_ImageGetGraphicsContext($hBmpSmall) _GDIPlus_GraphicsSetPixelOffsetMode($hGfxSmall, $GDIP_PIXELOFFSETMODE_HALF) Local $hBmpBig = _GDIPlus_BitmapCreateFromScan0($iW, $iH) Local $hGfxBig = _GDIPlus_ImageGetGraphicsContext($hBmpBig) _GDIPlus_GraphicsSetPixelOffsetMode($hGfxBig, $GDIP_PIXELOFFSETMODE_HALF) _GDIPlus_GraphicsScaleTransform($hGfxSmall, $fScale, $fScale) _GDIPlus_GraphicsSetInterpolationMode($hGfxSmall, $qual) _GDIPlus_GraphicsScaleTransform($hGfxBig, 1 / $fScale, 1 / $fScale) _GDIPlus_GraphicsSetInterpolationMode($hGfxBig, $qual) _GDIPlus_GraphicsDrawImageRect($hGfxSmall, $hBitmap, 0, $dx1, $iW, $iH + $dy1) _GDIPlus_GraphicsDrawImageRect($hGfxBig, $hBmpSmall, 0, $dx2, $iW, $iH + $dy2) _GDIPlus_BitmapDispose($hBmpSmall) _GDIPlus_GraphicsDispose($hGfxSmall) _GDIPlus_GraphicsDispose($hGfxBig) Return $hBmpBig EndFunc ;==>_Blur I hope you like it. Feel free to post your examples here, too.3 points
-
I had recognized this function in the past (2014) and wrote an example but I couldn't think of any real usage of it. Good catch...1 point
-
WebDriver UDF - Help & Support (II)
seadoggie01 reacted to Danp2 for a topic
@seadoggie01 Thanks for the reminder to look into this issue. I just tried with the following DesiredCapabilities string at it worked as expected for me -- Local $sDesiredCapabilities = '{"capabilities":{"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "prefs": {"plugins.always_open_pdf_externally": true}}}}}'1 point -
...I'm sure some of you know what will this be about. Have patience and read the whole post and run some code. I find this theme to be very interesting and worth of lost time. Who knows, maybe I will even say something that you didn't know before. It's known that you can't take AutoIt and go with it to the stars. It's not made for that. If you try you will probably die doing it (out of oldness). It's slow. But in the same hand it's strong enough to go there. So, why not mount it on powerful rocket and take a trip here and there. Space is a fun place they say. Here goes... Few days back I found some code in which OpenGL functions were used. Code is written by C.Eugene (brilliant man, I must say). I don't know what language was written in but it looks very interesting. I wasn't able to run the code because I don't know how to. Anyway, since I have some limited experience with OpenGL functions (look here) I was able, after comprehending some aspects of it, to run the code in my head (yeah, I'm a freak). That code when converted to AutoIt looks like this: #NoTrayIcon #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ; #include "OpenGLconstants.au3"; constants are extracred for this example Opt("GUIOnEventMode", 1) ; Used constants from OpenGLconstants.au3 Global Const $GL_VERSION_1_1 = 1 Global Const $GL_DEPTH_BUFFER_BIT = 0x00000100 Global Const $GL_COLOR_BUFFER_BIT = 0x00004000 Global Const $GL_SRC_COLOR = 0x0300 Global Const $GL_DST_COLOR = 0x0306 Global Const $GL_FOG = 0x0B60 Global Const $GL_FOG_DENSITY = 0x0B62 Global Const $GL_FOG_START = 0x0B63 Global Const $GL_FOG_END = 0x0B64 Global Const $GL_FOG_MODE = 0x0B65 Global Const $GL_FOG_COLOR = 0x0B66 Global Const $GL_BLEND = 0x0BE2 Global Const $GL_FOG_HINT = 0x0C54 Global Const $GL_DONT_CARE = 0x1100 Global Const $GL_MODELVIEW = 0x1700 Global Const $GL_PROJECTION = 0x1701 Global Const $GL_LINEAR = 0x2601 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 $iNumStars = 106; number of stars Global $iWidthGUI = 600 Global $iHeightGUI = 400 Global $hGUI = GUICreate("OpenGL Space", $iWidthGUI, $iHeightGUI, -1, -1, $WS_OVERLAPPEDWINDOW) GUISetBkColor(0) Global $hDC, $hRC; device context and rendering context If Not _EnableOpenGL($hGUI, $hDC, $hRC) Then MsgBox(48, "Error", "Error initializing usage of OpenGL functions" & @CRLF & "Error code: " & @error) Exit EndIf _glClear(BitOR($GL_COLOR_BUFFER_BIT, $GL_DEPTH_BUFFER_BIT)); initially cleaning buffers in case something is left there Global $aStar[$iNumStars][3]; x, y, z coordinates Global $aStarColor[$iNumStars][3]; r, g, b color for stars For $i = 0 To $iNumStars - 1 $aStar[$i][0] = Random(-25, 25) $aStar[$i][1] = Random(-25, 25) $aStar[$i][2] = Random(-150, 0) $aStarColor[$i][1] = Random(0.8, 1) $aStarColor[$i][2] = Random(0.8, 1) Next _glClearColor(0, 0, 0, 1); black _glFogi($GL_FOG_MODE, $GL_LINEAR) Global $tFogColor = DllStructCreate("float[4]") DllStructSetData($tFogColor, 1, 1, 4) $pFogColor = DllStructGetPtr($tFogColor) _glFogfv($GL_FOG_COLOR, $pFogColor) _glFogf($GL_FOG_DENSITY, 0.1) _glHint($GL_FOG_HINT, $GL_DONT_CARE) _glFogf($GL_FOG_START, 70) _glFogf($GL_FOG_END, 150) _glEnable($GL_FOG); _glBlendFunc($GL_SRC_COLOR, $GL_DST_COLOR) _glEnable($GL_BLEND) _glLoadIdentity() _glViewport(0, 0, $iWidthGUI, $iHeightGUI) _glMatrixMode($GL_PROJECTION) _glLoadIdentity() $s = $iWidthGUI / $iHeightGUI _glFrustum(-$s * 0.75, $s * 0.75, -0.75, 0.75, 6, 150) _glMatrixMode($GL_MODELVIEW) GUIRegisterMsg(133, "_Preserve"); WM_NCPAINT GUIRegisterMsg(5, "_ResizeGL"); WM_SIZE GUISetOnEvent(-3, "_Quit"); on exit GUISetState(@SW_SHOW, $hGUI) While 1 _GLDraw() Sleep(0) WEnd ; USED FUNCTIONS Func _GLDraw() _glClear(16640); $GL_COLOR_BUFFER_BIT|$GL_DEPTH_BUFFER_BIT; cleaning buffers _glBegin(1); $GL_LINES; gonna draw lines For $i = 0 To $iNumStars - 1 _glColor3f($aStarColor[$i][0], $aStarColor[$i][1], $aStarColor[$i][2]); start color _glVertex3f($aStar[$i][0], $aStar[$i][1], $aStar[$i][2]); start point _glColor3f(0, 0, .2); end color _glVertex3f($aStar[$i][0], $aStar[$i][1], $aStar[$i][2] - 1.5); end point (z is moved) $aStar[$i][2] += 0.3 If $aStar[$i][2] > 5 Then $aStar[$i][0] = Random(-25, 25) $aStar[$i][1] = Random(-25, 25) $aStar[$i][2] = -150 ;$aStarColor[$i][1] = Random(0.8, 1) ;$aStarColor[$i][2] = Random(0.8, 1) EndIf Next _glEnd(); end drawing _SwapBuffers($hDC); "refresh" EndFunc ;==>_GLDraw Func _EnableOpenGL($hWnd, ByRef $hDeviceContext, ByRef $hOpenGLRenderingContext) Local $tPIXELFORMATDESCRIPTOR = DllStructCreate("ushort Size;" & _ "ushort Version;" & _ "dword Flags;" & _ "ubyte PixelType;" & _ "ubyte ColorBits;" & _ "ubyte RedBits;" & _ "ubyte RedShift;" & _ "ubyte GreenBits;" & _ "ubyte GreenShift;" & _ "ubyte BlueBits;" & _ "ubyte BlueShift;" & _ "ubyte AlphaBits;" & _ "ubyte AlphaShift;" & _ "ubyte AccumBits;" & _ "ubyte AccumRedBits;" & _ "ubyte AccumGreenBits;" & _ "ubyte AccumBlueBits;" & _ "ubyte AccumAlphaBits;" & _ "ubyte DepthBits;" & _ "ubyte StencilBits;" & _ "ubyte AuxBuffers;" & _ "ubyte LayerType;" & _ "ubyte Reserved;" & _ "dword LayerMask;" & _ "dword VisibleMask;" & _ "dword DamageMask") DllStructSetData($tPIXELFORMATDESCRIPTOR, "Size", DllStructGetSize($tPIXELFORMATDESCRIPTOR)) DllStructSetData($tPIXELFORMATDESCRIPTOR, "Version", $GL_VERSION_1_1) DllStructSetData($tPIXELFORMATDESCRIPTOR, "Flags", BitOR($PFD_DRAW_TO_WINDOW, $PFD_SUPPORT_OPENGL, $PFD_DOUBLEBUFFER)) DllStructSetData($tPIXELFORMATDESCRIPTOR, "PixelType", $PFD_TYPE_RGBA) DllStructSetData($tPIXELFORMATDESCRIPTOR, "ColorBits", 24) DllStructSetData($tPIXELFORMATDESCRIPTOR, "DepthBits", 32) DllStructSetData($tPIXELFORMATDESCRIPTOR, "LayerType", $PFD_MAIN_PLANE) Local $a_hCall = DllCall("kernel32.dll", "hwnd", "GetModuleHandleW", "wstr", "opengl32.dll") If @error Then Return SetError(1, 0, 0); what??? EndIf If Not $a_hCall[0] Then If DllOpen("opengl32.dll") = -1 Then Return SetError(2, 0, 0); could not open opengl32.dll EndIf EndIf $a_hCall = DllCall("user32.dll", "hwnd", "GetDC", "hwnd", $hWnd) If @error Or Not $a_hCall[0] Then Return SetError(3, 0, 0); could not retrieve a handle to a device context EndIf $hDeviceContext = $a_hCall[0] Local $a_iCall = DllCall("gdi32.dll", "int", "ChoosePixelFormat", "hwnd", $hDeviceContext, "ptr", DllStructGetPtr($tPIXELFORMATDESCRIPTOR)) If @error Or Not $a_iCall[0] Then Return SetError(4, 0, 0); could not match an appropriate pixel format EndIf Local $iFormat = $a_iCall[0] $a_iCall = DllCall("gdi32.dll", "int", "SetPixelFormat", "hwnd", $hDeviceContext, "int", $iFormat, "ptr", DllStructGetPtr($tPIXELFORMATDESCRIPTOR)) If @error Or Not $a_iCall[0] Then Return SetError(5, 0, 0); could not set the pixel format of the specified device context to the specified format EndIf $a_hCall = DllCall("opengl32.dll", "hwnd", "wglCreateContext", "hwnd", $hDeviceContext) If @error Or Not $a_hCall[0] Then Return SetError(6, 0, 0); could not create a rendering context EndIf $hOpenGLRenderingContext = $a_hCall[0] $a_iCall = DllCall("opengl32.dll", "int", "wglMakeCurrent", "hwnd", $hDeviceContext, "hwnd", $hOpenGLRenderingContext) If @error Or Not $a_iCall[0] Then Return SetError(7, 0, 0); failed to make the specified rendering context the calling thread's current rendering context EndIf Return SetError(0, 0, 1); all OK! EndFunc ;==>_EnableOpenGL Func _DisableOpenGL($hWnd, $hDeviceContext, $hOpenGLRenderingContext) ; No point in doing error checking if this is done on exit. Will just call the cleaning functions. DllCall("opengl32.dll", "int", "wglMakeCurrent", "hwnd", 0, "hwnd", 0) DllCall("opengl32.dll", "int", "wglDeleteContext", "hwnd", $hOpenGLRenderingContext) DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $hWnd, "hwnd", $hDeviceContext) EndFunc ;==>_DisableOpenGL Func _ResizeGL($hWnd, $iMsg, $wParam, $lParam) Local $aClientSize[2] = [BitAND($lParam, 65535), BitShift($lParam, 16)] _glLoadIdentity() _glViewport(0, 0, $aClientSize[0], $aClientSize[1]) _glMatrixMode($GL_PROJECTION) _glLoadIdentity() Local $nRatio = $aClientSize[0] / $aClientSize[1] _glFrustum(-$nRatio * .75, $nRatio * .75, -.75, .75, 6.0, 150.0) _glMatrixMode($GL_MODELVIEW) EndFunc ;==>_ResizeGL Func _glBegin($iMode) DllCall("opengl32.dll", "none", "glBegin", "dword", $iMode) EndFunc ;==>_glBegin Func _glBlendFunc($iSfactor, $iDfactor) DllCall("opengl32.dll", "none", "glBlendFunc", "dword", $iSfactor, "dword", $iDfactor) EndFunc ;==>_glBlendFunc Func _glColor3fv($pColorFloat) DllCall("opengl32.dll", "none", "glColor3fv", "ptr", $pColorFloat) EndFunc ;==>_glColor3fv Func _glClear($iMask) DllCall("opengl32.dll", "none", "glClear", "dword", $iMask) EndFunc ;==>_glClear Func _glClearColor($nRed, $nGreen, $nBlue, $nAlpha) DllCall("opengl32.dll", "none", "glClearColor", "float", $nRed, "float", $nGreen, "float", $nBlue, "float", $nAlpha) EndFunc ;==>_glClearColor Func _glColor3f($nRed, $nGreen, $nBlue) DllCall("opengl32.dll", "none", "glColor3f", "float", $nRed, "float", $nGreen, "float", $nBlue) EndFunc ;==>_glColor3f Func _glEnable($iCap) DllCall("opengl32.dll", "none", "glEnable", "dword", $iCap) EndFunc ;==>_glEnable Func _glEnd() DllCall("opengl32.dll", "none", "glEnd") EndFunc ;==>_glEnd Func _glFrustum($nLeft, $nRight, $nBottom, $nTop, $nZNear, $nZFar) DllCall("opengl32.dll", "none", "glFrustum", "double", $nLeft, "double", $nRight, "double", $nBottom, "double", $nTop, "double", $nZNear, "double", $nZFar) EndFunc ;==>_glFrustum Func _glFogf($iName, $nParam) DllCall("opengl32.dll", "none", "glFogf", "dword", $iName, "float", $nParam) EndFunc ;==>_glFogf Func _glFogi($iName, $iParam) DllCall("opengl32.dll", "none", "glFogi", "dword", $iName, "dword", $iParam) EndFunc ;==>_glFogi Func _glFogfv($iName, $pParams) DllCall("opengl32.dll", "none", "glFogfv", "dword", $iName, "ptr", $pParams) EndFunc ;==>_glFogfv Func _glHint($iTarget, $iMode) DllCall("opengl32.dll", "none", "glHint", "dword", $iTarget, "dword", $iMode) EndFunc ;==>_glHint Func _glLoadIdentity() DllCall("opengl32.dll", "none", "glLoadIdentity") EndFunc ;==>_glLoadIdentity Func _glMatrixMode($iMode) DllCall("opengl32.dll", "none", "glMatrixMode", "dword", $iMode) EndFunc ;==>_glMatrixMode Func _glViewport($iX, $iY, $iWidth, $iHeight) DllCall("opengl32.dll", "none", "glViewport", "int", $iX, "int", $iY, "dword", $iWidth, "dword", $iHeight) EndFunc ;==>_glViewport Func _glVertex3f($nX, $nY, $nZ) DllCall("opengl32.dll", "none", "glVertex3f", "float", $nX, "float", $nY, "float", $nZ) EndFunc ;==>glVertex3f Func _glVertex3fv($pPointer) DllCall("opengl32.dll", "none", "glVertex3fv", "ptr", $pPointer) EndFunc ;==>_glVertex3fv Func _SwapBuffers($hDC) DllCall("gdi32.dll", "int", "SwapBuffers", "hwnd", $hDC) EndFunc ;==>_SwapBuffers Func _Preserve() _SwapBuffers($hDC) EndFunc ;==>_Preserve Func _Quit() _DisableOpenGL($hGUI, $hDC, $hRC) Exit EndFunc ;==>_Quit If you would go thru code you would see that I'm saying that the number of stars is 106. Why 106. No particular reason. It's just for one that would run that code to see that something is happening actually. I number of stars is smaller you probably wouldn't spot anything. What can be seen by running it? Well, it's eating up CPU and it's slow like shi*t. But still, it's working!!! That's a good sign. Let's speed it up! How? Will use flying assembly to do that. If you were reading previous threads on this theme than you know that the code to convert must be without built-in functions. If you go thru posted script again, you will see that the problematic part is Random() and arrays. Since OpenGL functions are written to be very wide, there is a possibility to pass a pointer to array (of floats e.g.) to some functions instead of three different float values. For example there is function glColor3f. You feed this function with three float values: _glColor3f(0.8, 0.5, 0.1) Func _glColor3f($nRed, $nGreen, $nBlue) DllCall("opengl32.dll", "none", "glColor3f", "float", $nRed, "float", $nGreen, "float", $nBlue) EndFunc ;==>_glColor3f But, there is also function that does the same but you pass somethig different: Global $tStartColor = DllStructCreate("float[3]") DllStructSetData($tStartColor, 1, 0.8, 1); r DllStructSetData($tStartColor, 1, 0.5, 2); g DllStructSetData($tStartColor, 1, 0.1, 3); b Global $pStartColor = DllStructGetPtr($tStartColor) _glColor3fv($pStartColor) Func _glColor3fv($pColorFloat) DllCall("opengl32.dll", "none", "glColor3fv", "ptr", $pColorFloat) EndFunc ;==>_glColor3fv The effect would be the same. Another problem is to generate random number in some range. How is that done by not using buil-in function? ntdll.dll exports function RtlRandomEx. This function will generate random number (integer) in range 0 to 2147483648. The problem is obviously how to set range. That could be done using mathematics, like this: Global $tRandom = DllStructCreate("dword") Global $pRandom = DllStructGetPtr($tRandom) For $i = 1 To 10 ConsoleWrite($i & ". " & _Random(-23, 121) & @CRLF) Next Func _Random($iMin, $iMax) ;Return Random($iMin, $iMax) DllCall("ntdll.dll", "dword", "RtlRandomEx", "ptr", $pRandom) Return DllStructGetData($tRandom, 1) / (2147483648 - 1) * ($iMax - $iMin) + $iMin EndFunc ;==>_Random If you know the range you can do the calculations before and write something like this (to return integer in range of -25 to 25): Global $tRandom = DllStructCreate("dword") Global $pRandom = DllStructGetPtr($tRandom) For $i = 1 To 10 ConsoleWrite($i & ". " & _Random1() & @CRLF) Next Func _Random1() ;Return Random(-25, 25) DllCall("ntdll.dll", "dword", "RtlRandomEx", "ptr", $pRandom) Return Int(DllStructGetData($tRandom, 1) / 42949672) - 25 ; Return DllStructGetData($tRandom, 1) / 2147483647 * 50 - 25 EndFunc ;==>_Random1 Now that we know that the original script can be written like this: #NoTrayIcon #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ; #include "OpenGLconstants.au3"; constants are extracred for this examle Opt("GUIOnEventMode", 1) ; Used constants from OpenGLconstants.au3 Global Const $GL_VERSION_1_1 = 1 Global Const $GL_DEPTH_BUFFER_BIT = 0x00000100 Global Const $GL_COLOR_BUFFER_BIT = 0x00004000 Global Const $GL_SRC_COLOR = 0x0300 Global Const $GL_DST_COLOR = 0x0306 Global Const $GL_FOG = 0x0B60 Global Const $GL_FOG_DENSITY = 0x0B62 Global Const $GL_FOG_START = 0x0B63 Global Const $GL_FOG_END = 0x0B64 Global Const $GL_FOG_MODE = 0x0B65 Global Const $GL_FOG_COLOR = 0x0B66 Global Const $GL_BLEND = 0x0BE2 Global Const $GL_FOG_HINT = 0x0C54 Global Const $GL_DONT_CARE = 0x1100 Global Const $GL_MODELVIEW = 0x1700 Global Const $GL_PROJECTION = 0x1701 Global Const $GL_LINEAR = 0x2601 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 $iNumStars = 106; number of stars Global $iWidthGUI = 600 Global $iHeightGUI = 400 Global $hGUI = GUICreate("OpenGL Space", $iWidthGUI, $iHeightGUI, -1, -1, $WS_OVERLAPPEDWINDOW) GUISetBkColor(0) Global $tRandom = DllStructCreate("dword") Global $pRandom = DllStructGetPtr($tRandom) Global $hDC, $hRC; device context and rendering context If Not _EnableOpenGL($hGUI, $hDC, $hRC) Then MsgBox(48, "Error", "Error initializing usage of OpenGL functions" & @CRLF & "Error code: " & @error) Exit EndIf _glClear(BitOR($GL_COLOR_BUFFER_BIT, $GL_DEPTH_BUFFER_BIT)); initially cleaning buffers in case something is left there Global $tStars = DllStructCreate("float[" & 3 * $iNumStars & "]") Global $tColors = DllStructCreate("float[" & 3 * $iNumStars & "]") Global $pStars = DllStructGetPtr($tStars) Global $pColors = DllStructGetPtr($tColors) Global $tInt = DllStructCreate("dword") DllStructSetData($tInt, 1, $pStars) Global $pInt = DllStructGetPtr($tInt) Global $tInt1 = DllStructCreate("int") Global $pInt1 = DllStructGetPtr($tInt1) Global $tStartColor = DllStructCreate("float[3]") DllStructSetData($tStartColor, 1, 0.5, 1) DllStructSetData($tStartColor, 1, 0.9, 2) DllStructSetData($tStartColor, 1, 0.9, 3) Global $pStartColor = DllStructGetPtr($tStartColor) Global $tEndColor = DllStructCreate("float[3]") DllStructSetData($tEndColor, 1, 0.2, 3) Global $pEndColor = DllStructGetPtr($tEndColor) $k = TimerInit() For $i = 1 To $iNumStars DllStructSetData($tStars, 1, _Random1(), ($i * 3) - 2) DllStructSetData($tStars, 1, _Random1(), ($i * 3) - 1) DllStructSetData($tStars, 1, _Random3(), $i * 3) DllStructSetData($tColors, 1, _Random2(), ($i * 3) - 1) DllStructSetData($tColors, 1, _Random2(), $i * 3) Next ConsoleWrite(TimerDiff($k) & @CRLF) ;INIT _glClearColor(0, 0, 0, 1) _glFogi($GL_FOG_MODE, $GL_LINEAR); $tFogColor = DllStructCreate("float[4]") DllStructSetData($tFogColor, 1, 1, 4) $pFogColor = DllStructGetPtr($tFogColor) _glFogfv($GL_FOG_COLOR, $pFogColor) _glFogf($GL_FOG_DENSITY, 0.1); _glHint($GL_FOG_HINT, $GL_DONT_CARE); _glFogf($GL_FOG_START, 70); _glFogf($GL_FOG_END, 150); _glEnable($GL_FOG); _glBlendFunc($GL_SRC_COLOR, $GL_DST_COLOR); _glEnable($GL_BLEND) ; End INIT ; ResizeGL _glLoadIdentity(); _glViewport(0, 0, $iWidthGUI, $iHeightGUI); _glMatrixMode($GL_PROJECTION); _glLoadIdentity(); $s = $iWidthGUI / $iHeightGUI _glFrustum(-$s * .75, $s * .75, -.75, .75, 6.0, 150.0) _glMatrixMode($GL_MODELVIEW) ; End ResizeGL GUIRegisterMsg(133, "_Preserve"); WM_NCPAINT GUIRegisterMsg(5, "_ResizeGL"); WM_SIZE GUISetOnEvent(-3, "_Quit"); on exit GUISetState(@SW_SHOW, $hGUI) Global $a = DllStructCreate("float[3]") Global $pa = DllStructGetPtr($a) Global $z While 1 _GLDraw() Sleep(0) WEnd ; FUNCTIONS Func _GLDraw() _glClear(16640); $GL_COLOR_BUFFER_BIT|$GL_DEPTH_BUFFER_BIT; cleaning buffers _glBegin(1); $GL_LINES; gonna draw lines For $i = 1 To $iNumStars $z = DllStructGetData($tStars, 1, $i * 3) DllStructSetData($a, 1, DllStructGetData($tStars, 1, ($i * 3) - 2), 1) DllStructSetData($a, 1, DllStructGetData($tStars, 1, ($i * 3) - 1), 2) DllStructSetData($a, 1, $z, 3) ;_glColor3fv($pColors + ($i - 1) * 12); start color (12 = size of float[3]) _glColor3fv($pStartColor); this is a constant value ;_glVertex3fv($pa); start point _glVertex3fv($pStars + ($i - 1) * 12); start point _glColor3fv($pEndColor); this is a constant value $z -= 1.5; dislocating z coordinate DllStructSetData($a, 1, $z, 3) _glVertex3fv($pa); end point $z += 1.5; returning z coordinate $z += 0.3 DllStructSetData($tStars, 1, $z, $i * 3) If $z > 5 Then DllStructSetData($tStars, 1, _Random1(), ($i * 3) - 2) DllStructSetData($tStars, 1, _Random1(), ($i * 3) - 1) DllStructSetData($tStars, 1, -150, $i * 3) ;DllStructSetData($tColors, 1, _Random2(), ($i * 3) - 1) ;DllStructSetData($tColors, 1, _Random2(), ($i * 3)) EndIf Next _glEnd(); end drawing _SwapBuffers($hDC); "refresh" EndFunc ;==>_GLDraw Func _Random($iMin, $iMax) ;Return Random($iMin, $iMax) DllCall("ntdll.dll", "dword", "RtlRandomEx", "ptr", $pRandom) Return DllStructGetData($tRandom, 1) / 2147483647 * ($iMax - $iMin) + $iMin EndFunc ;==>_Random Func _Random1() ;Return Random(-25, 25) DllCall("ntdll.dll", "dword", "RtlRandomEx", "ptr", $pRandom) Return Int(DllStructGetData($tRandom, 1) / 42949672) - 25 Return DllStructGetData($tRandom, 1) / 2147483647 * 50 - 25 EndFunc ;==>_Random1 Func _Random2() ;Return Random(0.8, 1) DllCall("ntdll.dll", "dword", "RtlRandomEx", "ptr", $pRandom) Return Int((DllStructGetData($tRandom, 1) / 2147483647)) / 5 + 0.8 EndFunc ;==>_Random2 Func _Random3() ;Return Random(-150, 0) DllCall("ntdll.dll", "dword", "RtlRandomEx", "ptr", $pRandom) Return -DllStructGetData($tRandom, 1) / 14316558 EndFunc ;==>_Random3 Func SwapEndian($iValue) Return Hex(BinaryMid($iValue, 1, 4)) EndFunc ;==>SwapEndian Func _EnableOpenGL($hWnd, ByRef $hDeviceContext, ByRef $hOpenGLRenderingContext) Local $tPIXELFORMATDESCRIPTOR = DllStructCreate("ushort Size;" & _ "ushort Version;" & _ "dword Flags;" & _ "ubyte PixelType;" & _ "ubyte ColorBits;" & _ "ubyte RedBits;" & _ "ubyte RedShift;" & _ "ubyte GreenBits;" & _ "ubyte GreenShift;" & _ "ubyte BlueBits;" & _ "ubyte BlueShift;" & _ "ubyte AlphaBits;" & _ "ubyte AlphaShift;" & _ "ubyte AccumBits;" & _ "ubyte AccumRedBits;" & _ "ubyte AccumGreenBits;" & _ "ubyte AccumBlueBits;" & _ "ubyte AccumAlphaBits;" & _ "ubyte DepthBits;" & _ "ubyte StencilBits;" & _ "ubyte AuxBuffers;" & _ "ubyte LayerType;" & _ "ubyte Reserved;" & _ "dword LayerMask;" & _ "dword VisibleMask;" & _ "dword DamageMask") DllStructSetData($tPIXELFORMATDESCRIPTOR, "Size", DllStructGetSize($tPIXELFORMATDESCRIPTOR)) DllStructSetData($tPIXELFORMATDESCRIPTOR, "Version", $GL_VERSION_1_1) DllStructSetData($tPIXELFORMATDESCRIPTOR, "Flags", BitOR($PFD_DRAW_TO_WINDOW, $PFD_SUPPORT_OPENGL, $PFD_DOUBLEBUFFER)) DllStructSetData($tPIXELFORMATDESCRIPTOR, "PixelType", $PFD_TYPE_RGBA) DllStructSetData($tPIXELFORMATDESCRIPTOR, "ColorBits", 24) DllStructSetData($tPIXELFORMATDESCRIPTOR, "DepthBits", 32) DllStructSetData($tPIXELFORMATDESCRIPTOR, "LayerType", $PFD_MAIN_PLANE) Local $a_hCall = DllCall("kernel32.dll", "hwnd", "GetModuleHandleW", "wstr", "opengl32.dll") If @error Then Return SetError(1, 0, 0); what??? EndIf If Not $a_hCall[0] Then If DllOpen("opengl32.dll") = -1 Then Return SetError(2, 0, 0); could not open opengl32.dll EndIf EndIf $a_hCall = DllCall("user32.dll", "hwnd", "GetDC", "hwnd", $hWnd) If @error Or Not $a_hCall[0] Then Return SetError(3, 0, 0); could not retrieve a handle to a device context EndIf $hDeviceContext = $a_hCall[0] Local $a_iCall = DllCall("gdi32.dll", "int", "ChoosePixelFormat", "hwnd", $hDeviceContext, "ptr", DllStructGetPtr($tPIXELFORMATDESCRIPTOR)) If @error Or Not $a_iCall[0] Then Return SetError(4, 0, 0); could not match an appropriate pixel format EndIf Local $iFormat = $a_iCall[0] $a_iCall = DllCall("gdi32.dll", "int", "SetPixelFormat", "hwnd", $hDeviceContext, "int", $iFormat, "ptr", DllStructGetPtr($tPIXELFORMATDESCRIPTOR)) If @error Or Not $a_iCall[0] Then Return SetError(5, 0, 0); could not set the pixel format of the specified device context to the specified format EndIf $a_hCall = DllCall("opengl32.dll", "hwnd", "wglCreateContext", "hwnd", $hDeviceContext) If @error Or Not $a_hCall[0] Then Return SetError(6, 0, 0); could not create a rendering context EndIf $hOpenGLRenderingContext = $a_hCall[0] $a_iCall = DllCall("opengl32.dll", "int", "wglMakeCurrent", "hwnd", $hDeviceContext, "hwnd", $hOpenGLRenderingContext) If @error Or Not $a_iCall[0] Then Return SetError(7, 0, 0); failed to make the specified rendering context the calling thread's current rendering context EndIf Return SetError(0, 0, 1); all OK! EndFunc ;==>_EnableOpenGL Func _DisableOpenGL($hWnd, $hDeviceContext, $hOpenGLRenderingContext) ; No point in doing error checking if this is done on exit. Will just call the cleaning functions. DllCall("opengl32.dll", "int", "wglMakeCurrent", "hwnd", 0, "hwnd", 0) DllCall("opengl32.dll", "int", "wglDeleteContext", "hwnd", $hOpenGLRenderingContext) DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $hWnd, "hwnd", $hDeviceContext) EndFunc ;==>_DisableOpenGL Func _ResizeGL($hWnd, $iMsg, $wParam, $lParam) Local $aClientSize[2] = [BitAND($lParam, 65535), BitShift($lParam, 16)] _glLoadIdentity() _glViewport(0, 0, $aClientSize[0], $aClientSize[1]) _glMatrixMode($GL_PROJECTION) _glLoadIdentity() Local $nRatio = $aClientSize[0] / $aClientSize[1] _glFrustum(-$nRatio * .75, $nRatio * .75, -.75, .75, 6.0, 150.0) _glMatrixMode($GL_MODELVIEW) EndFunc ;==>_ResizeGL Func _glBegin($iMode) DllCall("opengl32.dll", "none", "glBegin", "dword", $iMode) EndFunc ;==>_glBegin Func _glBlendFunc($iSfactor, $iDfactor) DllCall("opengl32.dll", "none", "glBlendFunc", "dword", $iSfactor, "dword", $iDfactor) EndFunc ;==>_glBlendFunc Func _glColor3fv($pColorFloat) DllCall("opengl32.dll", "none", "glColor3fv", "ptr", $pColorFloat) EndFunc ;==>_glColor3fv Func _glClear($iMask) DllCall("opengl32.dll", "none", "glClear", "dword", $iMask) EndFunc ;==>_glClear Func _glClearColor($nRed, $nGreen, $nBlue, $nAlpha) DllCall("opengl32.dll", "none", "glClearColor", "float", $nRed, "float", $nGreen, "float", $nBlue, "float", $nAlpha) EndFunc ;==>_glClearColor Func _glColor3f($nRed, $nGreen, $nBlue) DllCall("opengl32.dll", "none", "glColor3f", "float", $nRed, "float", $nGreen, "float", $nBlue) EndFunc ;==>_glColor3f Func _glEnable($iCap) DllCall("opengl32.dll", "none", "glEnable", "dword", $iCap) EndFunc ;==>_glEnable Func _glEnd() DllCall("opengl32.dll", "none", "glEnd") EndFunc ;==>_glEnd Func _glFrustum($nLeft, $nRight, $nBottom, $nTop, $nZNear, $nZFar) DllCall("opengl32.dll", "none", "glFrustum", "double", $nLeft, "double", $nRight, "double", $nBottom, "double", $nTop, "double", $nZNear, "double", $nZFar) EndFunc ;==>_glFrustum Func _glFogf($iName, $nParam) DllCall("opengl32.dll", "none", "glFogf", "dword", $iName, "float", $nParam) EndFunc ;==>_glFogf Func _glFogi($iName, $iParam) DllCall("opengl32.dll", "none", "glFogi", "dword", $iName, "dword", $iParam) EndFunc ;==>_glFogi Func _glFogfv($iName, $pParams) DllCall("opengl32.dll", "none", "glFogfv", "dword", $iName, "ptr", $pParams) EndFunc ;==>_glFogfv Func _glHint($iTarget, $iMode) DllCall("opengl32.dll", "none", "glHint", "dword", $iTarget, "dword", $iMode) EndFunc ;==>_glHint Func _glLoadIdentity() DllCall("opengl32.dll", "none", "glLoadIdentity") EndFunc ;==>_glLoadIdentity Func _glMatrixMode($iMode) DllCall("opengl32.dll", "none", "glMatrixMode", "dword", $iMode) EndFunc ;==>_glMatrixMode Func _glViewport($iX, $iY, $iWidth, $iHeight) DllCall("opengl32.dll", "none", "glViewport", "int", $iX, "int", $iY, "dword", $iWidth, "dword", $iHeight) EndFunc ;==>_glViewport Func _glVertex3f($nX, $nY, $nZ) DllCall("opengl32.dll", "none", "glVertex3f", "float", $nX, "float", $nY, "float", $nZ) EndFunc ;==>glVertex3f Func _glVertex3fv($pPointer) DllCall("opengl32.dll", "none", "glVertex3fv", "ptr", $pPointer) EndFunc ;==>_glVertex3fv Func _SwapBuffers($hDC) DllCall("gdi32.dll", "int", "SwapBuffers", "hwnd", $hDC) EndFunc ;==>_SwapBuffers Func _Preserve() _SwapBuffers($hDC) EndFunc ;==>_Preserve Func _Quit() _DisableOpenGL($hGUI, $hDC, $hRC) Exit EndFunc ;==>_Quit Ok, that's almost half of the job. All that needs to be done now is to convert the slow part to assembly. There are some things that should be said before though. New (assembly) code will be executed using function CallWindowProc. Some other functions could be used too but there is always a thread issue. You can't be sure if there would be a new thread created. Why is this important? Because if you look at documentation of wglMakeCurrent function, you will see that it works for threads (not processes!). If you make a new thread and want to draw to some rendering context you need to call wglMakeCurrent from that thread to make the association. Interesting thing is that in XP you could even skip that, but on Vista skipping association leads to crash. That's why you will see calls to wglMakeCurrent in script that follows in places you didn't in the previous scripts. Since the script is somewhere larger and this post is large enough I have to attach it. Space.au3 Change the speed using mouse wheel or up an down arrows on your keyboard. Every line of code is commented (hell, even the comments are commented). That script is dealing with 7777 stars (again no particular reason why) and is very, very low on CPU. If you are interested you can learn about floats and dealing with them on processor level by examining that script (that's new) and many, many other stuff. I think I could write a short book on that code It's almost a perfect screensaver. If anyone have any question, ask. You know how they say: "Space: the final frontier..."1 point
-
URL Encoding
Colduction reacted to ProgAndy for a topic
I wrote some functions including UTF-8 conversion Func _URIEncode($sData) ; Prog@ndy Local $aData = StringSplit(BinaryToString(StringToBinary($sData,4),1),"") Local $nChar $sData="" For $i = 1 To $aData[0] ; ConsoleWrite($aData[$i] & @CRLF) $nChar = Asc($aData[$i]) Switch $nChar Case 45, 46, 48 To 57, 65 To 90, 95, 97 To 122, 126 $sData &= $aData[$i] Case 32 $sData &= "+" Case Else $sData &= "%" & Hex($nChar,2) EndSwitch Next Return $sData EndFunc Func _URIDecode($sData) ; Prog@ndy Local $aData = StringSplit(StringReplace($sData,"+"," ",0,1),"%") $sData = "" For $i = 2 To $aData[0] $aData[1] &= Chr(Dec(StringLeft($aData[$i],2))) & StringTrimLeft($aData[$i],2) Next Return BinaryToString(StringToBinary($aData[1],1),4) EndFunc MsgBox(0, '', _URIDecode(_URIEncode("testäöü fv"))) Edit 2012: Fixed bug in _URIEncode, removed debug output1 point