
Hi, I would like to know how to multiply the current matrix with, for example, the following translation matrix in RowMajor order: [1,0,0,x ,0,1,0,y ,0,0,1,z ,0,0,0,1] I know I must use: multMatrix :: (Matrix m, MatrixComponent c) => m c -> IO () but I don't know how to call it. Can anybody help me? Greetings, Bas

Am Samstag, 15. Oktober 2005 10:24 schrieb Bas van Dijk:
I would like to know how to multiply the current matrix with, for example, the following translation matrix in RowMajor order:
[1,0,0,x ,0,1,0,y ,0,0,1,z ,0,0,0,1]
I know I must use:
multMatrix :: (Matrix m, MatrixComponent c) => m c -> IO ()
but I don't know how to call it. Can anybody help me?
Again I fell guilty regarding the OpenGL package implementation... :-] OK, let's tear the signature apart a bit, so things might become clear. First the Matrix class: http://haskell.org/ghc/docs/latest/html/libraries/OpenGL/Graphics.Rendering.... It has 2 pairs of constructors/accessors for matrices: One pointer-based pair (withNewMatrix and withMatrix) and one list-based pair (newMatrix and getMatrixComponents). Each pair has default definitions using the other pair, so you only have to implement one constructor (withNewMatrix or newMatrix) and one accessor (withMatrix or getMatrixComponents). Lists are often more handy when you explicitly specify the matrix by hand and the pointer-based stuff is often more convenient/efficient when you have the data already loaded from some external source. The OpenGL package comes already with one abstract type (GLmatrix) which is an instance of Matrix, so you don't have to write instances for yourself if there are no special needs. GLmatrix is based on ForeignPtr internally, BTW, but this is really an implementation detail. The other class involved is MatrixComponent: http://haskell.org/ghc/docs/latest/html/libraries/OpenGL/Graphics.Rendering.... Instances of this class are the possible types of matrix components which are supported by OpenGL, i.e. GLfloat and GLdouble. So if the x, y, z variables in your example above are of type GLdouble and you have no special needs regarding the matrix representation, your question boils down to: How can I construct "GLmatrix GLdouble" given a list of GLdoubles in row-major order? The answer is: Use newMatrix and help Haskell's type inference a bit by giving an explicit type signature: ... m <- newMatrix RowMajor [1,0,0,x ,0,1,0,y ,0,0,1,z ,0,0,0,1] :: IO (GLmatrix GLdouble) multMatrix m The type signature is needed because the type of the matrix itself does not uniquely specify its components (and not the other way round, either). By using a named helper function with a type signature which wraps newMatrix you can get rid of the explicit type signature in the middle of the code above, but that's a matter of taste. Hope that helps, S.

Hello, when I try to compile a program that uses HOpenGL with profiling enabled, GHC complains about types not being declared and functions not being exported (all names belonging to the HOpenGL package). Does HOpenGL lack profiling support or am I doing something wrong ? How would I go about installing the package so that profiling works ? Thank you for your help. Yann Morvan

I was trying to compile GLUT and HOpenGL with profiling on (I added "GhcLibWays = p" in buid.mk). When it goes back to building the profiling versions, it fails with: Graphics/UI/GLUT/Callbacks/Registration.hs:64: Couldn't match `Maybe Window' against `Window' Expected type: Maybe Window Inferred type: Window In the third argument of `maybe', namely `win' In the result of a 'do' expression: maybe (error (func ++ ": no current window")) return win Even though things worked fine for the non profiling build. I don't understand why it would behave differently. I am using version 6.3 of the fptools disribution, because it is at that time that I had to play around to get fragment programs working. Was there known issues with profiling HOpenGL at that time ? Has a lot happened since ? Do I need to do more than set GhcLibWays ? Thank you for your help, Yann Morvan

Apparently that last issue was solved by doing "make depend". Sorry for the spam. Still working on it.

I can get everything to compile with the -prof flag now, but I get those two linking errors that I don't understand: c:/ghc/ghc-6.2.1/libHSGLUT_p.a(Debugging.p_o)(.text+0x748):Debugging.p_hc: undefined reference to `GraphicsziRenderingziOpenGLziGLUziErrors_getErrors_closure' c:/ghc/ghc-6.2.1/libHSGLUT_p.a(Debugging.p_o)(.text+0x7a4):Debugging.p_hc: undefined reference to `GraphicsziRenderingziOpenGLziGLUziErrors_getErrors_entry' make: *** [renderer] Error 1 My configuration is a bit weird: I compile HOpenGL and GLUT from a 6.3 fptools distribution, but I install the resulting packages in a 6.2.1 binary distribution (because for some reason I don't remember I was having trouble building the whole fptools 6.3). I'm using cygwin on a win XP PC. In case it's relevent, the package.conf entries for GLUT and OpenGL read like this: Package {name = "OpenGL", auto = True, import_dirs = ["$libdir/imports"], source_dirs = [], library_dirs = ["$libdir"], hs_libraries = ["HSOpenGL"], extra_libraries = ["HSOpenGL_cbits"], include_dirs = [], c_includes = ["HsOpenGL.h"], package_deps = ["base"], extra_ghc_opts = [], extra_cc_opts = [], extra_ld_opts = ["-lglu32", "-lopengl32"], framework_dirs = [], extra_frameworks = []}, Package {name = "GLUT", auto = True, import_dirs = ["$libdir/imports"], source_dirs = [], library_dirs = ["$libdir"], hs_libraries = ["HSGLUT"], extra_libraries = ["HSGLUT_cbits"], include_dirs = [], c_includes = ["HsGLUT.h"], package_deps = ["base", "OpenGL"], extra_ghc_opts = [], extra_cc_opts = [], extra_ld_opts = ["-lglut32"], framework_dirs = [], extra_frameworks = []}, Thank you for your help, Yann Morvan
participants (3)
-
Bas van Dijk
-
Sven Panne
-
Yann Morvan