[Haskell-cafe] need help please [HOpenGL]
Brian Hulley
brianh at metamilk.com
Sat Apr 22 22:49:27 EDT 2006
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.
More information about the Haskell-Cafe
mailing list