OpenGL Transformation

  • Ich experimentiere gerade etwas mit OpenGL und bin dabei über ein Problem gestolpert.
    Die glOrtho zeigt keine Reaktion, ich weiß aber auch nicht wo der Fehler liegen sollte.
    Kennt sich jemand damit aus???

    Spoiler anzeigen
    [autoit]


    #include <GuiConstants.au3>
    #include <OpenGL.au3>
    #include <Math.au3>
    #include <WindowsConstants.au3>
    #include <Constants.au3>
    #include <GUIScrollBars.au3>
    #include <ScrollBarConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $GUI, $DC, $OpenGL

    [/autoit] [autoit][/autoit] [autoit]

    $GUI = GuiCreate("OpenGl", 800, 600, -1, -1 , $WS_SIZEBOX + $WS_SYSMENU + $WS_MINIMIZEBOX + $WS_MAXIMIZEBOX)
    $OpenGL = GUICtrlCreateOpenGL($DC, 0, 0, 800, 600)
    If @Error Then Exit
    GUICtrlSetResizing($OpenGL, $GUI_DOCKBORDERS)

    [/autoit] [autoit][/autoit] [autoit]

    _GUIScrollBars_Init($GUI)
    _GUIScrollBars_SetScrollInfoPage($GUI, $SB_VERT, 600)
    _GUIScrollBars_SetScrollInfoPage($GUI, $SB_HORZ, 800)
    _GUIScrollBars_ShowScrollBar($gui, $SB_BOTH)

    [/autoit] [autoit][/autoit] [autoit]

    $pos = ControlGetPos($GUI, "", $OpenGL)
    glViewport(0, 0, $pos[2], $pos[3])
    glMatrixMode($GL_PROJECTION)
    glLoadIdentity()
    glOrtho(0, 9, 0, 9, -1, 1)
    glMatrixMode($GL_MODELVIEW)
    glLoadIdentity()

    [/autoit] [autoit][/autoit] [autoit]

    glColor3f(0, 0, 1)
    glClearColor(1, 1, 1, 1)

    [/autoit] [autoit][/autoit] [autoit]

    GuiSetState()
    While 1
    $msg = GuiGetMsg()
    Switch $msg
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch

    [/autoit] [autoit][/autoit] [autoit]

    glClear($GL_COLOR_BUFFER_BIT)

    [/autoit] [autoit][/autoit] [autoit]

    glBegin($GL_QUADS)
    glVertex2i(0, 8)
    glVertex2i(8, 8)
    glVertex2i(8, 0)
    glVertex2i(0, 0)
    glEnd()

    [/autoit] [autoit][/autoit] [autoit]

    SwapBuffers($DC)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func GUICtrlCreateOpenGL(ByRef $hDC, $x, $y, $width, $height)
    Local $control = GUICtrlCreateLabel("", $x, $y, $width, $height)
    Local Const $PFD_TYPE_RGBA = 0
    Local Const $PFD_MAIN_PLANE = 0
    Local Const $PFD_DOUBLEBUFFER = 1
    Local Const $PFD_DRAW_TO_WINDOW = 4
    Local Const $PFD_SUPPORT_OPENGL = 32

    [/autoit] [autoit][/autoit] [autoit]

    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;")

    [/autoit] [autoit][/autoit] [autoit]

    Local $h_dc = DllCall("user32.dll", "hwnd", "GetDC", "hwnd", GUICtrlGetHandle($control))

    [/autoit] [autoit][/autoit] [autoit]

    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)

    [/autoit] [autoit][/autoit] [autoit]

    Global $gdi = DllOpen("gdi32.dll")
    If @Error Then
    SetError(1)
    Return 0
    EndIf
    Global $opengl = DllOpen("opengl32.dll")
    If @Error Then
    SetError(1)
    Return 0
    EndIf

    Local $iFormat = DllCall($gdi, "int", "ChoosePixelFormat", "hwnd", $h_dc[0], "ptr", DllStructGetPtr($pfd))

    Local $iSetFormat = DllCall($gdi, "int", "SetPixelFormat", "hwnd", $h_dc[0], "int", $iFormat[0], "ptr", DllStructGetPtr($pfd))

    [/autoit] [autoit][/autoit] [autoit]

    Local $h_cont = DllCall($opengl, "hwnd", "wglCreateContext", "hwnd", $h_dc[0])

    Local $iRet = DllCall($opengl, "int", "wglMakeCurrent", "int", $h_dc[0], "int", $h_cont[0])

    [/autoit] [autoit][/autoit] [autoit]

    $hDC = $h_dc[0]

    [/autoit] [autoit][/autoit] [autoit]

    Return $control
    EndFunc ;==>EnableOpenGL

    [/autoit] [autoit][/autoit] [autoit]

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

    [/autoit]

    Edit: Auf die Nutzung des Plugin würde ich gerne verzichten. Das macht das umschreiben in eine andere Sprache nur kompliziert, falls Autoit zu langsam ist.

    Edit2: OK, doofe Frage. glOrtho legt nur den Zeichenbereich fest, Transformiert wird mit glScalef und glTranslatef. Gelöst^^