trancexx Posted August 6, 2009 Author Share Posted August 6, 2009 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. expandcollapse popup#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 Excellent, I see some new options. That's great. Functions you use are (or to be) rewritten. '_' is added in front of any to be in the spirit of AutoIt and data types are corrected (so that it works on 64-bit systems and to be more uniform). Also EnableOpenGL() is improved and _DisableOpenGL() added as it's needed to do what's polite - not to leave garbage behind. Until uploaded could you write include-free scripts that meet listed above. It could also be additional way of learning AutoIt for you (if that's what you want). So extract functions from OpenGLfunctions.au3 and put them in your scripts corrected as said. For example glRotatef() function: Func glRotatef($angle, $x, $y, $z) DllCall("opengl32.dll", "none", "glRotatef", "float", $angle, "float", $x, "float", $y, "float", $z) EndFunc should be (after doing Global Const $hOPENGL32 = DllOpen("opengl32.dll") at the beginning of the script): Func _glRotatef($nAngle, $nX, $nY, $nZ) DllCall($hOPENGL32, "none", "glRotatef", "float", $nAngle, "float", $nX, "float", $nY, "float", $nZ) EndFunc Some tips on how it should look at the end find here. Bunch of rewritten functions can be find here. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
trancexx Posted August 6, 2009 Author Share Posted August 6, 2009 This one shows new objects of rotation: 1. Auto rotation of circular planes (color fiters) 2. Manual rotation of cubic (body connected to mouse) expandcollapse popupFunc _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 You think you could do WideBoyDixon's 3D Pie Chart? It would be interesting to see the difference between gdip and opengl approach. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
ValeryVal Posted August 6, 2009 Share Posted August 6, 2009 You think you could do WideBoyDixon's 3D Pie Chart? It would be interesting to see the difference between gdip and opengl approach. This chart is very like to windows 3.1 party. Now we have moving group from the transparent color discs and cube manually rotated. expandcollapse popupFunc _GLDraw() global $nM ; this to be used for rotation local $R = 0.6 _glClear(BitOR($GL_COLOR_BUFFER_BIT, $GL_DEPTH_BUFFER_BIT)) ; cleaning buffers $nM -= 0.7 ; decreasing. To rotate otherwise do increasing _glPopMatrix() _glPushMatrix() ; Auto Rotation _glRotatef($nM, 1, 1, 1) ; Start red circle Disc ($R,-$R/2,+$R/2, -0.075, 1, 0.5, 0.5, 0.25) ; Start green circle Disc ($R,+$R/2,+$R/2, 0.025, 0.5, 1, 0.5, 0.25) ; Start blue circle Disc ($R,+$R/2,-$R/2, -0.025, 0.5, 0.5, 1, 0.25) ; Start yellow circle Disc ($R,-$R/2,-$R/2, -0.075, 1, 1, 0.5, 0.25) ; 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 ;===================== ;Disc create Func Disc ($R, $x, $y, $z, $cR, $cG, $cB, $h) local $GL_POLYGON = 0x0009 local $i, $fi, $a = 3.14/30 local $x1[61], $y1[61], $p1, $q1, $p2, $q2, $z1, $z2 $z1 = $z+$h/2 $z2 = $z-$h/2 _glBegin($GL_POLYGON) _glColor4f($cR, $cG, $cB, 0.5) For $i = 0 to 60 $fi = (2*$i-1)*$a $x1[$i] = $R*Cos($fi)+$x $y1[$i] = $R*Sin($fi)+$y _glVertex3f($x1[$i], $y1[$i], $z1) Next _glEnd(); _glBegin($GL_POLYGON) _glColor4f($cR/3, $cG/3, $cB/3, 0.5) For $i = 0 to 60 _glVertex3f($x1[$i], $y1[$i], $z2) Next _glEnd(); For $i = 0 to 60 _glBegin($GL_QUADS) _glColor4f($cR/2, $cG/2, $cB/2, 0.5) $p1 = $x1[$i] $q1 = $y1[$i] if $i = 60 then $p2 = $x1[0] $q2 = $y1[0] else $p2 = $x1[$i+1] $q2 = $y1[$i+1] endif _glVertex3f($p1, $q1, $z1) _glVertex3f($p2, $q2, $z1) _glVertex3f($p2, $q2, $z2) _glVertex3f($p1, $q1, $z2) _glEnd() Next Endfunc Maybe soon we will draw the Earth cuts from BBC TV very easy. The point of world view Link to comment Share on other sites More sharing options...
Beomagi Posted August 6, 2009 Share Posted August 6, 2009 expandcollapse popup#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) glEnable($GL_DEPTH_TEST) 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,0) glRotated($m-10, 1, 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 yay figured it out >_< glEnable($GL_DEPTH_TEST) ... glClear(BitOR($GL_COLOR_BUFFER_BIT, $GL_DEPTH_BUFFER_BIT)); ... Used wrong constant last time I tried "glEnable" trancexx, thanks for the library and other code. Never realized autoit was this capable. I'll check through your other examples and msdn as recommended to see if there's any changes I should make. Merci! Beomagi Link to comment Share on other sites More sharing options...
trancexx Posted August 7, 2009 Author Share Posted August 7, 2009 (edited) Gurus, I tell you. Hope that people will see the power of what you posted. For example, the touch with _glNewList() and $GL_COMPILE makes the huge difference. CPU goes down dramatically. edit: This is variation of Valery's. Check CPU usage on both: expandcollapse popup#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 Const $GL_COMPILE = 0x1300 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 Global $hFontList = _CreateOpenGLFont(20, 400, 256) ; 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 GUIRegisterMsg(512, "_ChangeSpeed") ; WM_MOUSEMOVE ; Show GUI GUISetState(@SW_SHOW, $hGUI) Local $nRadius = 0.6 _glNewList(1, $GL_COMPILE) _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) _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) _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) _glColor4f(1, 1, 0.5, 0.5) ; yelow _glVertex3f(-.3, -.3, .3) _glVertex3f(-.3, -.3, -.3) _glVertex3f(.3, -.3, -.3) _glVertex3f(.3, -.3, .3) _glColor4f(0.5, 1, 1, 0.5) ; aqua _glVertex3f(-.3, .3, .3) _glVertex3f(-.3, -.3, .3) _glVertex3f(.3, -.3, .3) _glVertex3f(.3, .3, .3) _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() _glEndList() _glNewList(2, $GL_COMPILE) ; Red circle _glDisc($nRadius, -$nRadius / 2, +$nRadius / 2, -0.075, 1, 0.5, 0.5, 0.7) ; Green circle _glDisc($nRadius, +$nRadius / 2, +$nRadius / 2, 0.025, 0.5, 1, 0.5, 0.4) ; Blue circle _glDisc($nRadius, +$nRadius / 2, -$nRadius / 2, -0.025, 0.5, 0.5, 1, 0.3) ; Yellow circle _glDisc($nRadius, -$nRadius / 2, -$nRadius / 2, -0.075, 1, 1, 0.5, 0.2) _glEndList() _glNewList(3, $GL_COMPILE) _glColor3f(1, 1, 1) _glDrawText(-0.9, 0, "4 discs, 1 cube and rotation", $hFontList) _glEndList() ; Loop and draw till exit While 1 _GLDraw() Sleep(10) 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 _glCallList($iList) DllCall($hOPENGL32, "none", "glCallList", "dword", $iList) EndFunc ;==>_glCallList 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 _glEndList() DllCall($hOPENGL32, "none", "glEndList") EndFunc ;==>_glEndList Func _glListBase($iBase) DllCall($hOPENGL32, "none", "glListBase", "dword", $iBase) EndFunc ;==>_glListBase Func _glLoadIdentity() DllCall($hOPENGL32, "none", "glLoadIdentity") EndFunc ;==>_glLoadIdentity Func _glNewList($iList, $iMode) DllCall($hOPENGL32, "none", "glNewList", "dword", $iList, "dword", $iMode) EndFunc ;==>_glNewList 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, $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 Func _glDisc($nRadius, $iX, $iY, $iZ, $nRed, $nGreen, $nBlue, $iHeight) Local Const $GL_POLYGON = 0x0009 Local $iAngle Local $a = 3.14 / 60 Local $iX1[121], $iY1[121], $p1, $q1, $p2, $q2, $iZ1, $iZ2 $iZ1 = $iZ + $iHeight / 2 $iZ2 = $iZ - $iHeight / 2 _glBegin($GL_POLYGON) _glColor4f($nRed, $nGreen, $nBlue, 0.5) For $i = 0 To 120 $iAngle = (2 * $i - 1) * $a $iX1[$i] = $nRadius * Cos($iAngle) + $iX $iY1[$i] = $nRadius * Sin($iAngle) + $iY _glVertex3f($iX1[$i], $iY1[$i], $iZ1) Next _glColor4f($nRed / 3, $nGreen / 3, $nBlue / 3, 0.5) For $i = 0 To 120 _glVertex3f($iX1[$i], $iY1[$i], $iZ2) Next _glEnd() _glBegin($GL_QUADS) For $i = 0 To 120 _glColor4f($nRed / 2, $nGreen / 2, $nBlue / 2, 0.5) $p1 = $iX1[$i] $q1 = $iY1[$i] If $i = 120 Then $p2 = $iX1[0] $q2 = $iY1[0] Else $p2 = $iX1[$i + 1] $q2 = $iY1[$i + 1] EndIf _glVertex3f($p1, $q1, $iZ1) _glVertex3f($p2, $q2, $iZ1) _glVertex3f($p2, $q2, $iZ2) _glVertex3f($p1, $q1, $iZ2) Next _glEnd() EndFunc ;==>_glDisc Func _Preserve() _SwapBuffers($hDC) EndFunc ;==>_Preserve Func _Quit() _DisableOpenGL($hGUI, $hDC, $hRC) Exit EndFunc ;==>_Quit ; 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 _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 -= 0.7 ; decreasing. To rotate otherwise do increasing _glPopMatrix() _glPushMatrix() ; Auto Rotation _glRotatef($nM, 1, 1, 1) _glCallList(2) _glCallList(1) _glCallList(3) ; Replace old with the new one _SwapBuffers($hDC) EndFunc ;==>_GLDraw Edited August 7, 2009 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
ValeryVal Posted August 7, 2009 Share Posted August 7, 2009 New example: expandcollapse popupFunc _GLDraw() global $nM ; this to be used for rotation local $R = 0.5, $D = $R*Sqrt(2)/4 ; Parallelepiped type: cube - 4, hexahedron - 6, disc - from 27 to 30 ; here local $P = 7 _glClear(BitOR($GL_COLOR_BUFFER_BIT, $GL_DEPTH_BUFFER_BIT)) ; cleaning buffers $nM -= 0.3 ; decreasing. To rotate otherwise do increasing _glPopMatrix() _glPushMatrix() ; Auto Rotation _glRotatef($nM, 1, 1, 1) ; Start red Parallelepiped Disc ($R,-$D,+$D, -3*$R/4, 1, 0.6, 0.6, $R/2, 2*$P) ; Start green Parallelepiped Disc ($R,+$D,+$D, -$R/4, 0.6, 1, 0.6, $R/2, 2*$P) ; Start blue Parallelepiped Disc ($R,+$D,-$D, $R/4, 0.6, 0.6, 1, $R/2, 2*$P) ; Start yellow Parallelepiped Disc ($R,-$D,-$D, 3*$R/4, 1, 1, 0.6, $R/2, 2*$P) ; 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 ;===================== Func Disc ($R, $x, $y, $z, $cR, $cG, $cB, $h, $n = 60) local $GL_POLYGON = 0x0009 local $i, $fi, $a = 2*3.14/$n local $x1[61], $y1[61], $p1, $q1, $p2, $q2, $z1, $z2 $z1 = $z+$h $z2 = $z-$h _glBegin($GL_POLYGON) _glColor4f($cR, $cG, $cB, 0.5) For $i = 0 to $n $fi = (2*$i-1)*$a + $a/2 $x1[$i] = $R*Cos($fi)+$x $y1[$i] = $R*Sin($fi)+$y _glVertex3f($x1[$i], $y1[$i], $z1) Next _glEnd(); _glBegin($GL_POLYGON) _glColor4f($cR/3, $cG/3, $cB/3, 0.5) For $i = 0 to $n _glVertex3f($x1[$i], $y1[$i], $z2) Next _glEnd(); For $i = 0 to $n _glBegin($GL_QUADS) _glColor4f($cR/2, $cG/2, $cB/2, 0.5) $p1 = $x1[$i] $q1 = $y1[$i] if $i = $n then $p2 = $x1[0] $q2 = $y1[0] else $p2 = $x1[$i+1] $q2 = $y1[$i+1] endif _glVertex3f($p1, $q1, $z1) _glVertex3f($p2, $q2, $z1) _glVertex3f($p2, $q2, $z2) _glVertex3f($p1, $q1, $z2) _glEnd() Next Endfunc It uses disc func with $n variable. See it's calling from _GLDraw(): ; Parallelepiped type: cube - 4, hexahedron - 6, disc - from 27 to 30 ; here local $P = 7 To make hexahedron you have to set $P = 6 The point of world view Link to comment Share on other sites More sharing options...
ValeryVal Posted August 13, 2009 Share Posted August 13, 2009 This variation is just to unfreeze cool OpenGL thread: expandcollapse popup;=============================== ; Func _GLDraw() global $nM ; this to be used for rotation local $R = 0.5, $D = $R*Sqrt(2)/4 ; Pyramid base: rectangular - 4, hex - 6, round - from 27 ; here local $P = 9 _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 Pyramid Pyramid ($R,-$D,+$D, -3*$R/4, 1, 0.5, 0.5, 2*$R, 2*$P) ; Start green Pyramid Pyramid ($R,+$D,+$D, -$R/4, 0.5, 1, 0.5, 2*$R, 2*$P) ; Start blue Pyramid Pyramid ($R,+$D,-$D, $R/4, 0.5, 0.5, 1, 2*$R, 2*$P) ; Start yellow Pyramid Pyramid ($R,-$D,-$D, 3*$R/4, 1, 1, 0.5, 2*$R, 2*$P) ; 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 ;===================== Func Pyramid ($R, $x, $y, $z, $cR, $cG, $cB, $h, $n = 54) local $GL_POLYGON = 0x0009 local $GL_TRIANGLES = 0x0004 local $i, $fi, $a = 2*3.14/$n local $dc local $d[61], $x1[61], $y1[61], $p1, $q1, $p2, $q2, $z1, $z2 ;circle begins from 60 if $n > 54 then $n = 54 $z1 = $z-$h/3 $z2 = $z+2*$h/3 _glBegin($GL_POLYGON) _glColor4f($cR, $cG, $cB, 0.5) For $i = 0 to $n $fi = (2*$i-1)*$a + $a/2 $x1[$i] = $R*Cos($fi)+$x $y1[$i] = $R*Sin($fi)+$y $d[$i] = Abs(Sin($fi/2)) _glVertex3f($x1[$i], $y1[$i], $z1) Next _glEnd(); For $i = 0 to $n _glBegin($GL_TRIANGLES) $dc = 0.7*$d[$i] + 0.3 _glColor4f($dc*$cR, $dc*$cG, $dc*$cB, 0.5) $p1 = $x1[$i] $q1 = $y1[$i] if $i = $n then $p2 = $x1[0] $q2 = $y1[0] else $p2 = $x1[$i+1] $q2 = $y1[$i+1] endif _glVertex3f($p1, $q1, $z1) _glVertex3f($p2, $q2, $z1) _glVertex3f($x, $y, $z2) _glEnd() Next Endfunc It shows the easy Pyramid creation. The point of world view Link to comment Share on other sites More sharing options...
matwachich Posted June 1, 2011 Share Posted June 1, 2011 How can I draw a textured quad??? Link to comment Share on other sites More sharing options...
matwachich Posted June 4, 2011 Share Posted June 4, 2011 In other words, can any body translate me this PowerBasic code? (it's intended to load a GDI+ bitmap as an OpenGL Texture) expandcollapse popupTYPE colorARGB32 blue AS BYTE green AS BYTE red AS BYTE alpha AS BYTE END TYPE UNION pix4 whole AS DWORD colors AS colorARGB32 END UNION FUNCTION SetTexture(biwidth AS DWORD , biHeight AS DWORD, ref AS DWORD) AS LONG DIM p AS BYTE PTR p=STRPTR(pixmap(ref)) glBindTexture GL_TEXTURE_2D, mapref(ref) ' Bind Texture glTexParameterf GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR glTexParameterf GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST ' target level components width height border format datatype ptr to image data glTexImage2D GL_TEXTURE_2D, 0, 4, biWidth, biHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, @p END FUNCTION FUNCTION GDIP_GetTexMap (img AS STRING, ref AS DWORD ) AS STRING LOCAL hStatus AS LONG LOCAL pBitmap AS DWORD LOCAL pStream AS DWORD LOCAL pStreamo AS DWORD LOCAL pThumb AS DWORD LOCAL strFileName AS STRING LOCAL pix AS pix4 DIM thumf AS STRING:thumf=UCODE$("thumb.png") DIM cParamList AS EncoderParameters DIM cParam AS EncoderParameter cParamList.Count=0 strFileName = UCODE$(img) hStatus = GdipLoadImageFromFile(strFileName, pBitmap) hStatus = GdipGetImageThumbnail ( pBitMap, 256, 256, pThumb, 0, 0 ) ' hstatus=GdiPlusSaveImageToFile (pThumb,"thumb.png","image/png") hStatus = GdipImageRotateFlip(pThumb,%RotateNoneFlipY) 'invert 'MSGBOX STR$(hstatus) DIM w AS DWORD PTR pixmap(ref)=NUL$(4*256*256) w=STRPTR(pixmap(ref)) DIM x AS DWORD, y AS DWORD FOR y=0 TO 255 FOR x=0 TO 255 GdipBitmapGetPixel(pThumb, x, y, pix.whole) SWAP pix.colors.red, pix.colors.blue @w=pix.whole: INCR w NEXT NEXT SetTexture(256,256,ref) IF pBitmap THEN GdipDisposeImage(pBitmap) IF pThumb THEN GdipDisposeImage(pThumb) FUNCTION = "ok" END FUNCTION Link to comment Share on other sites More sharing options...
matwachich Posted June 6, 2011 Share Posted June 6, 2011 Found this:MSDNAnd here is the code i'm trying to get working!expandcollapse popup#include <OpenGL.au3> #include <GDIPlus.au3> #include <Array.au3> Global $scrW = 400, $scrH = 400 _GDIPlus_Startup() _OpenGL_Startup() Global $hGui = GuiCreate("OpenGL", $scrW, $scrH) GUISetState(@SW_SHOW) Global $oGL = _OpenGL_Enable($hGui) ; --- glMatrixMode($GL_PROJECTION) glLoadIdentity(); glOrtho(0, $scrW, $scrH, 0, 0, 1) ; coord like in GDI+ (0,0 => Top left corner) glMatrixMode($GL_MODELVIEW) glDisable($GL_DEPTH_TEST) ; Not needed for 2D ; --- $sPath = "C:\Users\Mat\Desktop\Tofs\Homer Simpson Apple-600960.jpeg" ; remplacé par une image valide Global $w = 8, $h = 8 ; Resize the image just to see the pixel data in the console $hImg = _GDIPlus_ImageLoadFromFile($sPath) $hImg2 = __GDIPlus_ImageGetThumbnail($hImg, $w, $h) _GDIPlus_ImageDispose($hImg) $BitmapData = _GDIPlus_BitmapLockBits($hImg2, 0, 0, $w, $h, $GDIP_ILMREAD, $GDIP_PXF32ARGB) $Scan0 = DllStructGetData($BitmapData, "Scan0") $v_BufferA = DllStructCreate("byte[" & $w * $h * 4 & "]", $Scan0) $AllPixels = DllStructGetData($v_BufferA, 1) $PixelsPtr = DllStructGetPtr($v_BufferA, 1) ConsoleWrite($AllPixels & @CRLF) ConsoleWrite(BinaryLen($AllPixels) & @CRLF) ; --- ;Global $texture[1] glClearColor(0.0, 0.0, 0.0, 1.0) glEnable($GL_TEXTURE_2D) ; About blending (not needed but to show it) glEnable($GL_BLEND) ; enable GL_BLEND glBlendFunc($GL_SRC_ALPHA, $GL_ONE_MINUS_SRC_ALPHA) glHint($GL_PERSPECTIVE_CORRECTION_HINT, $GL_NICEST) ;glGenTextures(5, $texture) glBindTexture($GL_TEXTURE_2D, 1) glTexParameteri($GL_TEXTURE_2D, $GL_TEXTURE_MAG_FILTER, $GL_LINEAR); glTexParameteri($GL_TEXTURE_2D, $GL_TEXTURE_MIN_FILTER, $GL_LINEAR); glTexEnvi($GL_TEXTURE_ENV, $GL_TEXTURE_ENV_MODE, $GL_MODULATE); glTexImage2D($GL_TEXTURE_2D, 0, $GL_RGBA, $w, $h, 0, $GL_RGBA, $GL_BITMAP, $GL_UNSIGNED_BYTE); ; --- Do $t = TimerInit() glClear($GL_COLOR_BUFFER_BIT) ; --- glBindTexture($GL_TEXTURE_2D, 1) glColor4f(1.0, 1.0, 1.0, 1.0) glBegin($GL_QUADS) glTexCoord2d(0,0) glVertex2d(10,10) ; --- glTexCoord2d(0,1) glVertex2d(390,10) ; --- glTexCoord2d(1,1) glVertex2d(390,390) ; --- glTexCoord2d(1,0) glVertex2d(10,390) glEnd() ; --- SwapBuffers($oGL) WinSetTitle($oGL[0], "", Round(1000 / TimerDiff($t)) & " fps") Until GuiGetMsg() = -3 $v_BufferA = 0 _GDIPlus_BitmapUnlockBits($hImg2, $BitmapData) _GDIPlus_ImageDispose($hImg2) _OpenGL_Disable($oGL) _OpenGL_Shutdown() _GDIPlus_Shutdown() ; ############################################################## Func __GDIPlus_ImageGetThumbnail($hImg, $iW, $iH) Local $ret = DllCall($ghGDIPDll, "int", "GdipGetImageThumbnail", _ "hwnd", $hImg, _ "int", $iW, _ "int", $iH, _ "int*", 0, _ "ptr", 0, _ "ptr", 0) If @error Then Return SetError(1, 0, 0) EndIf ; --- Return SetError(0, 0, $ret[4]) EndFuncMy Include OpenGL.au3 (needed)OpenGL.zip Link to comment Share on other sites More sharing options...
matwachich Posted June 7, 2011 Share Posted June 7, 2011 No body? Link to comment Share on other sites More sharing options...
matwachich Posted February 16, 2012 Share Posted February 16, 2012 up Link to comment Share on other sites More sharing options...
matwachich Posted February 21, 2012 Share Posted February 21, 2012 I think the problem is that GDI+ load pixel data as ARGB, and OpenGL waits for RGBA data. Any one... please, i'm near the goal! it would be great to be able to load image as OpenGL textures!!! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now