/usr/lib/hugs/packages/OpenGL/Graphics/Rendering/OpenGL/GLU/Quadrics.hs is in libhugs-opengl-bundled 98.200609.21-5.3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | --------------------------------------------------------------------------------
-- |
-- Module : Graphics.Rendering.OpenGL.GLU.Quadrics
-- Copyright : (c) Sven Panne 2002-2005
-- License : BSD-style (see the file libraries/OpenGL/LICENSE)
--
-- Maintainer : sven.panne@aedion.de
-- Stability : provisional
-- Portability : portable
--
-- This module corresponds to chapter 6 (Quadrics) of the GLU specs.
--
--------------------------------------------------------------------------------
module Graphics.Rendering.OpenGL.GLU.Quadrics (
QuadricNormal, QuadricTexture(..), QuadricOrientation(..),
QuadricDrawStyle(..), QuadricStyle(..),
Radius, Height, Angle, Slices, Stacks, Loops, QuadricPrimitive(..),
renderQuadric
) where
import Control.Monad ( unless )
import Foreign.Ptr ( Ptr, nullPtr, FunPtr, freeHaskellFunPtr )
import Graphics.Rendering.OpenGL.GL.BasicTypes (
GLboolean, GLenum, GLint, GLdouble )
import Graphics.Rendering.OpenGL.GL.Colors ( ShadingModel(Smooth,Flat) )
import Graphics.Rendering.OpenGL.GL.Exception ( bracket )
import Graphics.Rendering.OpenGL.GL.GLboolean ( marshalGLboolean )
import Graphics.Rendering.OpenGL.GLU.ErrorsInternal (
recordErrorCode, recordOutOfMemory )
--------------------------------------------------------------------------------
data QuadricDrawStyle =
PointStyle
| LineStyle
| FillStyle
| SilhouetteStyle
deriving ( Eq, Ord, Show )
marshalQuadricDrawStyle :: QuadricDrawStyle -> GLenum
marshalQuadricDrawStyle x = case x of
PointStyle -> 0x186aa
LineStyle -> 0x186ab
FillStyle -> 0x186ac
SilhouetteStyle -> 0x186ad
--------------------------------------------------------------------------------
data QuadricCallback =
Error'2
deriving ( Eq, Ord, Show )
marshalQuadricCallback :: QuadricCallback -> GLenum
marshalQuadricCallback x = case x of
Error'2 -> 0x18707
--------------------------------------------------------------------------------
type QuadricNormal = Maybe ShadingModel
marshalQuadricNormal :: QuadricNormal -> GLenum
marshalQuadricNormal (Just Smooth) = 0x186a0
marshalQuadricNormal (Just Flat ) = 0x186a1
marshalQuadricNormal Nothing = 0x186a2
--------------------------------------------------------------------------------
data QuadricOrientation =
Outside
| Inside
deriving ( Eq, Ord, Show )
marshalQuadricOrientation :: QuadricOrientation -> GLenum
marshalQuadricOrientation x = case x of
Outside -> 0x186b4
Inside -> 0x186b5
--------------------------------------------------------------------------------
data QuadricTexture
= NoTextureCoordinates
| GenerateTextureCoordinates
deriving ( Eq,Ord )
marshalQuadricTexture :: QuadricTexture -> GLboolean
marshalQuadricTexture NoTextureCoordinates = marshalGLboolean False
marshalQuadricTexture GenerateTextureCoordinates = marshalGLboolean True
--------------------------------------------------------------------------------
data QuadricStyle
= QuadricStyle QuadricNormal
QuadricTexture
QuadricOrientation
QuadricDrawStyle
deriving ( Eq,Ord )
--------------------------------------------------------------------------------
type Radius = GLdouble
type Height = GLdouble
type Angle = GLdouble
type Slices = GLint
type Stacks = GLint
type Loops = GLint
--------------------------------------------------------------------------------
data QuadricPrimitive
= Sphere Radius Slices Stacks
| Cylinder Radius Radius Height Slices Stacks
| Disk Radius Radius Slices Loops
| PartialDisk Radius Radius Slices Loops Angle Angle
deriving ( Eq, Ord )
--------------------------------------------------------------------------------
renderQuadric :: QuadricStyle -> QuadricPrimitive -> IO ()
renderQuadric style prim = do
withQuadricObj recordOutOfMemory $ \quadricObj ->
withErrorCallback quadricObj recordErrorCode $ do
setStyle quadricObj style
renderPrimitive quadricObj prim
withQuadricObj :: IO a -> (QuadricObj -> IO a) -> IO a
withQuadricObj failure success =
bracket gluNewQuadric safeDeleteQuadric
(\quadricObj -> if isNullQuadricObj quadricObj
then failure
else success quadricObj)
withErrorCallback :: QuadricObj -> QuadricCallback' -> IO a -> IO a
withErrorCallback quadricObj callback action =
bracket (makeQuadricCallback callback) freeHaskellFunPtr $ \callbackPtr -> do
gluQuadricCallback quadricObj (marshalQuadricCallback Error'2) callbackPtr
action
setStyle :: QuadricObj -> QuadricStyle -> IO ()
setStyle quadricObj (QuadricStyle n t o d) = do
gluQuadricNormals quadricObj (marshalQuadricNormal n)
gluQuadricTexture quadricObj (marshalQuadricTexture t)
gluQuadricOrientation quadricObj (marshalQuadricOrientation o)
gluQuadricDrawStyle quadricObj (marshalQuadricDrawStyle d)
renderPrimitive :: QuadricObj -> QuadricPrimitive -> IO ()
renderPrimitive quadricObj (Sphere r s n) =
gluSphere quadricObj r s n
renderPrimitive quadricObj (Cylinder b t h s n) =
gluCylinder quadricObj b t h s n
renderPrimitive quadricObj (Disk i o s l) =
gluDisk quadricObj i o s l
renderPrimitive quadricObj (PartialDisk i o s l a w) =
gluPartialDisk quadricObj i o s l a w
--------------------------------------------------------------------------------
-- 'Char' is a fake here, any marshalable type would do
newtype QuadricObj = QuadricObj (Ptr Char)
deriving ( Eq )
isNullQuadricObj :: QuadricObj -> Bool
isNullQuadricObj = (QuadricObj nullPtr ==)
--------------------------------------------------------------------------------
foreign import ccall unsafe "gluNewQuadric" gluNewQuadric :: IO QuadricObj
safeDeleteQuadric :: QuadricObj -> IO ()
safeDeleteQuadric quadricObj =
unless (isNullQuadricObj quadricObj) $ gluDeleteQuadric quadricObj
foreign import ccall unsafe "gluDeleteQuadric" gluDeleteQuadric ::
QuadricObj -> IO ()
--------------------------------------------------------------------------------
type QuadricCallback' = GLenum -> IO ()
foreign import ccall "wrapper" makeQuadricCallback ::
QuadricCallback' -> IO (FunPtr QuadricCallback')
foreign import ccall unsafe "gluQuadricCallback" gluQuadricCallback ::
QuadricObj -> GLenum -> FunPtr QuadricCallback' -> IO ()
--------------------------------------------------------------------------------
foreign import ccall unsafe "gluQuadricNormals" gluQuadricNormals ::
QuadricObj -> GLenum -> IO ()
foreign import ccall unsafe "gluQuadricTexture" gluQuadricTexture ::
QuadricObj -> GLboolean -> IO ()
foreign import ccall unsafe "gluQuadricOrientation" gluQuadricOrientation ::
QuadricObj -> GLenum -> IO ()
foreign import ccall unsafe "gluQuadricDrawStyle" gluQuadricDrawStyle ::
QuadricObj -> GLenum -> IO ()
--------------------------------------------------------------------------------
foreign import ccall safe "gluSphere" gluSphere ::
QuadricObj -> Radius -> Slices -> Stacks -> IO ()
foreign import ccall safe "gluCylinder" gluCylinder ::
QuadricObj -> Radius -> Radius -> Height -> Slices -> Stacks -> IO ()
foreign import ccall safe "gluDisk" gluDisk ::
QuadricObj -> Radius -> Radius -> Slices -> Loops -> IO ()
foreign import ccall safe "gluPartialDisk" gluPartialDisk ::
QuadricObj -> Radius -> Radius -> Slices -> Loops -> Angle -> Angle -> IO ()
|