need help please [HOpenGL]

hello ; I am writing to ask you a thing ; I am writing a little game on Haskell's HOpenGL ; the game isn't much , but I want to make look a little better ; and for that I want to use bitmaps (or textures) ; I don't know very much about this subject ; I've tried to use de bitmap function from Graphics.Rendering.OpenGL.GL.Bitmap , but i gives me an error ; I've used the function like this ; bmp <- bitmap (Size (100,100)) (Vertex2 0 0 ) (Vector2 0 0 ) (Ptr "C:\1.bmp") end it tells me that he doesn't find the Ptr constructor ; if you can supply an full example on this matter it would great ; many thanks ; hope to hear from you soon ; thanks for your time in reading my letter ; PS : the example doesn't have to be big , it just has to contain all the things , in order for me not to miss something --------------------------------- Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ countries) for 2¢/min or less.

Hi - You could try something like: import Foreign.Ptr import Foreign.C.String bmp <- withCAString "C:\1.bmp" $ bitmap (Size (100,100)) (Vertex2 0 0) (Vertex2 0 0) and if that doesn't work try withCString or withCWString. I'm assuming that the Ptr a in the docs is supposed to be a pointer to a null terminated C string hence withCAString should hopefully work. I'd also compile with -fffi (if you're using ghc) (I haven't tried it myself so someone else might have a better answer) Regards, Brian. ----- Original Message ----- From: enache alex To: haskell-cafe@haskell.org Sent: Saturday, April 22, 2006 11:10 PM Subject: [Haskell-cafe] need help please [HOpenGL] hello ; I am writing to ask you a thing ; I am writing a little game on Haskell's HOpenGL ; the game isn't much , but I want to make look a little better ; and for that I want to use bitmaps (or textures) ; I don't know very much about this subject ; I've tried to use de bitmap function from Graphics.Rendering.OpenGL.GL.Bitmap , but i gives me an error ; I've used the function like this ; bmp <- bitmap (Size (100,100)) (Vertex2 0 0 ) (Vector2 0 0 ) (Ptr "C:\1.bmp") end it tells me that he doesn't find the Ptr constructor ; if you can supply an full example on this matter it would great ; many thanks ; hope to hear from you soon ; thanks for your time in reading my letter ; PS : the example doesn't have to be big , it just has to contain all the things , in order for me not to miss something _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Brian Hulley wrote:
Hi - You could try something like:
import Foreign.Ptr import Foreign.C.String
bmp <- withCAString "C:\1.bmp" $ bitmap (Size (100,100)) (Vertex2 0 0) (Vertex2 0 0)
and if that doesn't work try withCString or withCWString. I'm assuming that the Ptr a in the docs is supposed to be a pointer to a null terminated C string hence withCAString should hopefully work. I'd also compile with -fffi (if you're using ghc)
(I haven't tried it myself so someone else might have a better answer)
Sorry I shouldn't have replied when I hadn't even tried it myself ;-) I don't think it is nearly so easy to display a bitmap from an image on file. If you look at the online version of the OpenGL redbook here http://www.rush3d.com/reference/opengl-redbook-1.1/chapter08.html the example C code for glBitmap is: GLubyte rasters[24] = { 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xff, 0x00, 0xff, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xff, 0xc0, 0xff, 0xc0}; void display(void) { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); glRasterPos2i (20.5, 20.5); glBitmap(10, 12, 0.0, 0.0, 12.0, 0.0, rasters); glBitmap(10, 12, 0.0, 0.0, 12.0, 0.0, rasters); glBitmap(10, 12, 0.0, 0.0, 12.0, 0.0, rasters); glFlush(); } and the explanation which follows suggests that the Ptr a in the HOpenGL bitmap function is a pointer to the raw bytes containing the bitmap image, not a pointer to the filename, and that the bitmap function actually displays a bitmap immediately at the current raster position rather than creating a texture for later use. You can create an array of raw bytes in memory by using eg newArray from Foreign.Marshal.Array, then pass the pointer to your display callback to use in the call to bitmap. The best place to get more info (eg about how to load bmp files) would be the HOpenGL mailing list. A link to it is on the HOpenGL page at http://haskell.org/HOpenGL/ Apologies for any confusion caused by my earlier rather ignorant post! ;-) Good luck - Brian.

Am Sonntag, 23. April 2006 04:49 schrieb Brian Hulley:
Brian Hulley wrote: [...] Sorry I shouldn't have replied when I hadn't even tried it myself ;-) I don't think it is nearly so easy to display a bitmap from an image on file. If you look at the online version of the OpenGL redbook here http://www.rush3d.com/reference/opengl-redbook-1.1/chapter08.html the example C code for glBitmap is: [...]
The GLUT package contains all examples from the Red Book, see: http://darcs.haskell.org/packages/GLUT/examples/RedBook/ The coding style is probably not the best one can imagine, but the intention is to give a very close 1:1 mapping of these well-known examples in Haskell. If you have read the Red Book (what everybody trying to do some OpenGL programming should have done IMHO), you should have no trouble understanding the Haskell examples. As already mentioned in another post, loading image data is by design out of the scope of OpenGL, but the examples contain a loader for a trivial raw RGB format: http://darcs.haskell.org/packages/GLUT/examples/RedBook/ReadImage.hs For further questions, hopengl@haskell.org is probably a better mailing list. Cheers, S.

On 4/23/06, enache alex
hello ; I am writing to ask you a thing ; I am writing a little game on Haskell's HOpenGL ; the game isn't much , but I want to make look a little better ; and for that I want to use bitmaps (or textures) ; I don't know very much about this subject ; I've tried to use de bitmap function from Graphics.Rendering.OpenGL.GL.Bitmap , but i gives me an error ; I've used the function like this ; bmp <- bitmap (Size (100,100)) (Vertex2 0 0 ) (Vector2 0 0 ) (Ptr "C:\1.bmp") end it tells me that he doesn't find the Ptr constructor ; if you can supply an full example on this matter it would great ; many thanks ; hope to hear from you soon ; thanks for your time in reading my letter ; PS : the example doesn't have to be big , it just has to contain all the things , in order for me not to miss something
With libSDL you can easily load a variety of formats and blit them via OpenGL. This binding even contains relevant example code: http://darcs.haskell.org/~lemmih/hsSDL -- Friendly, Lemmih
participants (4)
-
Brian Hulley
-
enache alex
-
Lemmih
-
Sven Panne