    {-# LINE 2 "./Graphics/UI/Gtk/OpenGL/General.chs" #-}
    -- -*-haskell-*-
    -- GIMP Toolkit (GTK) OpenGL Extension: General
    --
    -- Author : Duncan Coutts
    --
    -- Created: 9 June 2005
    --
    -- Copyright (C) 2005 Duncan Coutts
    --
    -- This library is free software; you can redistribute it and/or
    -- modify it under the terms of the GNU Lesser General Public
    -- License as published by the Free Software Foundation; either
    -- version 2.1 of the License, or (at your option) any later version.
    --
    -- This library is distributed in the hope that it will be useful,
    -- but WITHOUT ANY WARRANTY; without even the implied warranty of
    -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    -- Lesser General Public License for more details.
    --
    -- |
    -- Maintainer : gtk2hs-users@lists.sourceforge.net
    -- Stability : provisional
    -- Portability : portable (depends on GHC)
    --
    --
    --
    module Graphics.UI.Gtk.OpenGL.General (

    -- * Methods
      initGL,
    -- ** Query
      glQueryExtension,
      glQueryExtensionForDisplay,
      glQueryGLExtension,
      glQueryVersion,
      glQueryVersionForDisplay,

      ) where

    import Control.Monad (liftM)
    import System.Environment (getProgName, getArgs)

    import System.Glib.FFI
    import System.Glib.UTFString
    import System.Glib.GObject (makeNewGObject)
    import Graphics.Rendering.Pango.Types
    {-# LINE 53 "./Graphics/UI/Gtk/OpenGL/General.chs" #-}
    import Graphics.Rendering.Pango.BasicTypes
    {-# LINE 54 "./Graphics/UI/Gtk/OpenGL/General.chs" #-}
    import Graphics.UI.Gtk.OpenGL.Types
    {-# LINE 55 "./Graphics/UI/Gtk/OpenGL/General.chs" #-}

    {-# LINE 57 "./Graphics/UI/Gtk/OpenGL/General.chs" #-}

    --------------------
    -- Methods

    initGL :: IO [String]
    initGL = do
      prog <- getProgName
      args <- getArgs
      let allArgs = (prog:args)
      withMany withUTFString allArgs $ \addrs ->
        withArrayLen addrs $ \argc argv ->
        with argv $ \argvp ->
        with argc $ \argcp -> do
          res <- gtk_gl_init_check (castPtr argcp) (castPtr argvp)
          if (toBool res) then do
            argc'   <- peek argcp
            argv'   <- peek argvp
            _:addrs'  <- peekArray argc' argv'  -- drop the program name
            mapM peekUTFString addrs'
            else error "Cannot initialize OpenGL."

    -- |
    --
    glQueryExtension :: IO Bool
    glQueryExtension =
      liftM toBool $
      gdk_gl_query_extension
    {-# LINE 84 "./Graphics/UI/Gtk/OpenGL/General.chs" #-}

    -- |
    --
    glQueryExtensionForDisplay :: Display -> IO Bool
    glQueryExtensionForDisplay display =
      liftM toBool $
      (\(Display arg1) -> withForeignPtr arg1 $ \argPtr1 ->gdk_gl_query_extension_for_display argPtr1)
    {-# LINE 91 "./Graphics/UI/Gtk/OpenGL/General.chs" #-}
        display

    -- |
    --
    glQueryGLExtension :: String -> IO Bool
    glQueryGLExtension extension =
      liftM toBool $
      withUTFString extension $ \extensionPtr ->
      gdk_gl_query_gl_extension
    {-# LINE 100 "./Graphics/UI/Gtk/OpenGL/General.chs" #-}
        extensionPtr

    -- |
    --
    glQueryVersion :: IO (Maybe (Int, Int))
    glQueryVersion =
      alloca $ \majorPtr ->
      alloca $ \minorPtr ->
      gdk_gl_query_version
    {-# LINE 109 "./Graphics/UI/Gtk/OpenGL/General.chs" #-}
        majorPtr
        minorPtr
      >>= \ok ->
      if toBool ok
        then peek majorPtr >>= \major ->
             peek minorPtr >>= \minor ->
             return (Just (fromIntegral major, fromIntegral minor))
        else return Nothing

    -- |
    --
    glQueryVersionForDisplay :: Display -> IO (Maybe (Int, Int))
    glQueryVersionForDisplay display =
      alloca $ \majorPtr ->
      alloca $ \minorPtr ->
      (\(Display arg1) arg2 arg3 -> withForeignPtr arg1 $ \argPtr1 ->gdk_gl_query_version_for_display argPtr1 arg2 arg3)
    {-# LINE 125 "./Graphics/UI/Gtk/OpenGL/General.chs" #-}
        display
        majorPtr
        minorPtr
      >>= \ok ->
      if toBool ok
        then peek majorPtr >>= \major ->
             peek minorPtr >>= \minor ->
             return (Just (fromIntegral major, fromIntegral minor))
        else return Nothing

    foreign import ccall safe "gtk_gl_init_check"
      gtk_gl_init_check :: ((Ptr CInt) -> ((Ptr (Ptr (Ptr CChar))) -> (IO CInt)))

    foreign import ccall safe "gdk_gl_query_extension"
      gdk_gl_query_extension :: (IO CInt)

    foreign import ccall safe "gdk_gl_query_extension_for_display"
      gdk_gl_query_extension_for_display :: ((Ptr Display) -> (IO CInt))

    foreign import ccall safe "gdk_gl_query_gl_extension"
      gdk_gl_query_gl_extension :: ((Ptr CChar) -> (IO CInt))

    foreign import ccall safe "gdk_gl_query_version"
      gdk_gl_query_version :: ((Ptr CInt) -> ((Ptr CInt) -> (IO CInt)))

    foreign import ccall safe "gdk_gl_query_version_for_display"
      gdk_gl_query_version_for_display :: ((Ptr Display) -> ((Ptr CInt) -> ((Ptr CInt) -> (IO CInt))))