Closed linsyking closed 11 months ago
Or how to create texture with given format and size?
There's load_image_from_memory, where the image data is provided as an ocaml string. From there, you could use load_texture_from_image. I have never used these functions, so please report back if something is not working.
The texture struct isn't exposed for writing right now. I think the data field isn't exposed at all.
There's load_image_from_memory, where the image data is provided as an ocaml string. From there, you could use load_texture_from_image. I have never used these functions, so please report back if something is not working.
The texture struct isn't exposed for writing right now. I think the data field isn't exposed at all.
From this issue, if i want to use rlgl then I need a texture constructor.
From this issue, if i want to use rlgl then I need a texture constructor.
In the linked issue, they want to fill the texture struct directly. The issue they are having is the texture id, which needs access to GL to generate (through rlgl here).
The function load_texture_from_image
sets it correctly though, see here https://github.com/raysan5/raylib/blob/5e1a81555ca130e2c6544add0e2391a8763e7e2a/src/rtextures.c#L3340.
So the way of creating an image and then a texture should work.
The lowlevel rlgl function is also exposed by the bindings (https://tjammer.github.io/raylib-ocaml/raylib/Raylib/Rlgl/index.html#val-load_texture), but as I said, the texture struct isn't writable from the ocaml side directly
From this issue, if i want to use rlgl then I need a texture constructor.
In the linked issue, they want to fill the texture struct directly. The issue they are having is the texture id, which needs access to GL to generate (through rlgl here). The function
load_texture_from_image
sets it correctly though, see here https://github.com/raysan5/raylib/blob/5e1a81555ca130e2c6544add0e2391a8763e7e2a/src/rtextures.c#L3340. So the way of creating an image and then a texture should work.The lowlevel rlgl function is also exposed by the bindings (https://tjammer.github.io/raylib-ocaml/raylib/Raylib/Rlgl/index.html#val-load_texture), but as I said, the texture struct isn't writable from the ocaml side directly
Thanks for your help!
The problem with load_texture_from_image
is that I cannot set the image format (e.g. PIXELFORMAT_UNCOMPRESSED_R8G8B8
), so it becomes impossible to load some image correctly.
Also the image data is binary data so I think it should be pointer type rather than string.
Yes, you're right about the image format. I'll expose the missing fields of Texture then and make them writable. That way one can use exactly the same method as one would in C. It'll take a few days because the rlgl bindings are pretty raw. One of those int from load_texture shoulde be the image format, for instance.
Regarding binary data; String in OCaml are just arrays of bytes so they could be used that way. I'd be clearer to have something like Bytes.t instead, I agree
I've added a create function to the Textures module that you can use like in the raylib issue above.
The rlgl function doesn't take a PixelFormat.t
right now as the pixel format, but an int. To call it, you need to use Pixelformat.to_int
.
I want to load an image from memory, but I cannot find a function to create an image.
Equivalent in C: