Two small examples:
Global Const $GL_VERSION_1_1 = 1 Global Const $PFD_TYPE_RGBA = 0 Global Const $PFD_MAIN_PLANE = 0 Global Const $PFD_DOUBLEBUFFER = 1 Global Const $PFD_DRAW_TO_WINDOW = 4 Global Const $PFD_SUPPORT_OPENGL = 32 Global Const $GL_PROJECTION = 0x1701 Global Const $GL_COLOR_BUFFER_BIT = 0x00004000 Global Const $GL_TRIANGLES = 0x0004 Global $gui = GUICreate("OpenGL", 250, 250) GUISetBkColor(0x000000) Global $dc EnableOpenGL($gui, $dc) glMatrixMode($GL_PROJECTION) glViewport(0, 0, 250, 250) GUISetState(@SW_SHOW) While GUIGetMsg() <> -3 glClear($GL_COLOR_BUFFER_BIT) glBegin($GL_TRIANGLES) glColor3f(0, 1, 0) glVertex3f(-.75, -.5, 0) glColor3f(1, 0, 0) glVertex3f(0, .75, 0) glColor3f(0, 0, 1) glVertex3f( .75, -.5, 0) glEnd() SwapBuffers($dc) WEnd Func EnableOpenGL($hwnd, ByRef $hDC) Local $pfd = DllStructCreate("short nSize;" & _ "short nVersion;" & _ "dword dwFlags;" & _ "byte iPixelType;" & _ "byte cColorBits;" & _ "byte cRedBits;" & _ "byte cRedShift;" & _ "byte cGreenBits;" & _ "byte cGreenShift;" & _ "byte cBlueBits;" & _ "byte cBlueShift;" & _ "byte cAlphaBits;" & _ "byte cAlphaShift;" & _ "byte cAccumBits;" & _ "byte cAccumRedBits;" & _ "byte cAccumGreenBits;" & _ "byte cAccumBlueBits;" & _ "byte cAccumAlphaBits;" & _ "byte cDepthBits;" & _ "byte cStencilBits;" & _ "byte cAuxBuffers;" & _ "byte iLayerType;" & _ "byte bReserved;" & _ "dword dwLayerMask;" & _ "dword dwVisibleMask;" & _ "dword dwDamageMask;") Local $h_dc = DllCall("user32.dll", "hwnd", "GetDC", "hwnd", $hwnd) DllStructSetData($pfd, "nSize", DllStructGetSize($pfd)) DllStructSetData($pfd, "nVersion", $GL_VERSION_1_1) DllStructSetData($pfd, "dwFlags", BitOR($PFD_DRAW_TO_WINDOW, $PFD_SUPPORT_OPENGL, $PFD_DOUBLEBUFFER)) DllStructSetData($pfd, "iPixelType", $PFD_TYPE_RGBA) DllStructSetData($pfd, "cColorBits", 24) DllStructSetData($pfd, "cDepthBits", 16) DllStructSetData($pfd, "iLayerType", $PFD_MAIN_PLANE) DllOpen("gdi32.dll") DllOpen("opengl32.dll") Local $iFormat = DllCall("gdi32.dll", "int", "ChoosePixelFormat", "hwnd", $h_dc[0], "ptr", DllStructGetPtr($pfd)) Local $iSetFormat = DllCall("gdi32.dll", "int", "SetPixelFormat", "hwnd", $h_dc[0], "int", $iFormat[0], "ptr", DllStructGetPtr($pfd)) Local $h_cont = DllCall("opengl32.dll", "hwnd", "wglCreateContext", "hwnd", $h_dc[0]) Local $iRet = DllCall("opengl32.dll", "int", "wglMakeCurrent", "int", $h_dc[0], "int", $h_cont[0]) $hDC = $h_dc[0] Return 1 ; absolutley no error checking at this moment EndFunc ;==>EnableOpenGL Func glBegin($mode) DllCall("opengl32.dll", "none", "glBegin", "uint", $mode) EndFunc ;==>glBegin Func glClear($mask) DllCall("opengl32.dll", "none", "glClear", "uint", $mask) EndFunc ;==>glClear Func glColor3f($red, $green, $blue) DllCall("opengl32.dll", "none", "glColor3f", "float", $red, "float", $green, "float", $blue) EndFunc ;==>glColor3f Func glEnd() DllCall("opengl32.dll", "none", "glEnd") EndFunc ;==>glEnd Func glMatrixMode($mode) DllCall("opengl32.dll", "none", "glMatrixMode", "uint", $mode) EndFunc ;==>glMatrixMode Func glVertex3f($x, $y, $z) DllCall("opengl32.dll", "none", "glVertex3f", "float", $x, "float", $y, "float", $z) EndFunc ;==>glVertex3f Func glViewport($x, $y, $width, $height) DllCall("opengl32.dll", "none", "glViewport", "int", $x, "int", $y, "int", $width, "int", $height) EndFunc ;==>glViewport Func SwapBuffers($hDC) DllCall("gdi32.dll", "int", "SwapBuffers", "hwnd", $hDC) EndFunc ;==>SwapBuffers
Opt("GUIOnEventMode", 1) Global Const $GL_VERSION_1_1 = 1 Global Const $PFD_TYPE_RGBA = 0 Global Const $PFD_MAIN_PLANE = 0 Global Const $PFD_DOUBLEBUFFER = 1 Global Const $PFD_DRAW_TO_WINDOW = 4 Global Const $PFD_SUPPORT_OPENGL = 32 Global Const $GL_PROJECTION = 0x1701 Global Const $GL_COLOR_BUFFER_BIT = 0x00004000 Global Const $GL_LINES = 0x0001 Global $gui = GUICreate("Simple OpenGL Example", 350, 350) GUISetBkColor(0x000000) GUISetOnEvent(-3, "Quit") Global $dc EnableOpenGL($gui, $dc) glMatrixMode($GL_PROJECTION) glViewport(0, 0, 350, 350) GUISetState(@SW_SHOW) Global $a, $m While 1 glViewport(0, 0, 400 - $a / 5, 400 - $a / 5) $a += 10 If $a > 1750 Then $a = 0 glClear($GL_COLOR_BUFFER_BIT) glPopMatrix() glPushMatrix() $m -= .5 glRotated($m, 0, 0, 1) glBegin($GL_LINES) glColor3f(0, 1, 0) glVertex2d(-.5, -.5) glColor3f(1, 0, 0) glVertex2d(-.5, .5) glColor3f(0, 1, 0) glVertex2d(-.5, -.5) glColor3f(1, 0, 0) glVertex2d(.75, -.5) glColor3f(1, 0, 0) glVertex2d(.75, -.5) glColor3f(0, 1, 0) glVertex2d(.75, .5) glColor3f(0, 1, 0) glVertex2d(.75, .5) glColor3f(1, 0, 0) glVertex2d(-.5, .5) glEnd() SwapBuffers($dc) Sleep(10) WEnd Func EnableOpenGL($hwnd, ByRef $hDC) Local $pfd = DllStructCreate("short nSize;" & _ "short nVersion;" & _ "dword dwFlags;" & _ "byte iPixelType;" & _ "byte cColorBits;" & _ "byte cRedBits;" & _ "byte cRedShift;" & _ "byte cGreenBits;" & _ "byte cGreenShift;" & _ "byte cBlueBits;" & _ "byte cBlueShift;" & _ "byte cAlphaBits;" & _ "byte cAlphaShift;" & _ "byte cAccumBits;" & _ "byte cAccumRedBits;" & _ "byte cAccumGreenBits;" & _ "byte cAccumBlueBits;" & _ "byte cAccumAlphaBits;" & _ "byte cDepthBits;" & _ "byte cStencilBits;" & _ "byte cAuxBuffers;" & _ "byte iLayerType;" & _ "byte bReserved;" & _ "dword dwLayerMask;" & _ "dword dwVisibleMask;" & _ "dword dwDamageMask;") Local $h_dc = DllCall("user32.dll", "hwnd", "GetDC", "hwnd", $hwnd) DllStructSetData($pfd, "nSize", DllStructGetSize($pfd)) DllStructSetData($pfd, "nVersion", $GL_VERSION_1_1) DllStructSetData($pfd, "dwFlags", BitOR($PFD_DRAW_TO_WINDOW, $PFD_SUPPORT_OPENGL, $PFD_DOUBLEBUFFER)) DllStructSetData($pfd, "iPixelType", $PFD_TYPE_RGBA) DllStructSetData($pfd, "cColorBits", 24) DllStructSetData($pfd, "cDepthBits", 32) DllStructSetData($pfd, "iLayerType", $PFD_MAIN_PLANE) DllOpen("gdi32.dll") DllOpen("opengl32.dll") Local $iFormat = DllCall("gdi32.dll", "int", "ChoosePixelFormat", "hwnd", $h_dc[0], "ptr", DllStructGetPtr($pfd)) Local $iSetFormat = DllCall("gdi32.dll", "int", "SetPixelFormat", "hwnd", $h_dc[0], "int", $iFormat[0], "ptr", DllStructGetPtr($pfd)) Local $h_cont = DllCall("opengl32.dll", "hwnd", "wglCreateContext", "hwnd", $h_dc[0]) Local $iRet = DllCall("opengl32.dll", "int", "wglMakeCurrent", "int", $h_dc[0], "int", $h_cont[0]) $hDC = $h_dc[0] Return 1 EndFunc ;==>EnableOpenGL Func glColor3f($red, $green, $blue) DllCall("opengl32.dll", "none", "glColor3f", "float", $red, "float", $green, "float", $blue) EndFunc ;==>glColor3f Func glVertex2d($x, $y) DllCall("opengl32.dll", "none", "glVertex2d", "double", $x, "double", $y) EndFunc ;==>glVertex2d Func glClear($mask) DllCall("opengl32.dll", "none", "glClear", "uint", $mask) EndFunc ;==>glClear Func glBegin($mode) DllCall("opengl32.dll", "none", "glBegin", "uint", $mode) EndFunc ;==>glBegin Func glViewport($x, $y, $width, $height) DllCall("opengl32.dll", "none", "glViewport", "int", $x, "int", $y, "int", $width, "int", $height) EndFunc ;==>glViewport Func glEnd() DllCall("opengl32.dll", "none", "glEnd") EndFunc ;==>glEnd Func glMatrixMode($mode) DllCall("opengl32.dll", "none", "glMatrixMode", "uint", $mode) EndFunc ;==>glMatrixMode Func glPopMatrix() DllCall("opengl32.dll", "none", "glPopMatrix") EndFunc ;==>glPopMatrix Func glPushMatrix() DllCall("opengl32.dll", "none", "glPushMatrix") EndFunc ;==>glPushMatrix Func glRotated($angle, $x, $y, $z) DllCall("opengl32.dll", "none", "glRotated", "double", $angle, "double", $x, "double", $y, "double", $z) EndFunc ;==>glRotated Func SwapBuffers($hDC) DllCall("gdi32.dll", "int", "SwapBuffers", "hwnd", $hDC) EndFunc ;==>SwapBuffers Func Quit() Exit EndFunc
OpenGl contstants:
OpenGLconstants.au3 24.79KB
900 downloadsOpenGL functions: *
OpenGLfunctions.au3 48.75KB
943 downloadsAbsolutley no error checking at this moment.
edit:
* 2nd July 2009 This is not reliable. You should check every used function with msdn or some other source. I found many mistakes I've made when writting it. Some functions are corrected and can be found in some other scripts I wrote on this subject. Search the forum.
Edited by trancexx, 02 July 2009 - 11:16 AM.








