Is it possible to set the hard ware cursor with a binary file?

as the topic, i want to use a binary file to set the hardware cursor instead of a image file.

is this possible?

image files are binary?

renanse said:

image files are binary?

I was going to ask the same question but I didn't want to come off as a smartass - not that you did Renanse, you just opened the door.

I guess the question is - Neakor - what do you mean by binary files?  Images ARE binary files.  Do you mean a certain format?

I hope I didn't come off that way.  :slight_smile:

Perhaps you mean a windows cursor file or something like that?

sry for not being clear. heres what i did

i converted all the image files like .png, .jpg, .bmp into .texture file with bianryexporter.

everything works fine and the quality is also good. except the set mouse cursor method of hardware mouse doesnt allow me to use my cursor.texture file.

so my question is can i use the files exported with binaryexporter to set the mouse cursor?

yes, but you'll have to load it in as a Texture and apply it accordingly.

ill be really happy to do that, but first i need some advices.

setHardwareCursor takes in an URL, so u r saying the ImageLoader method should take in a custom binary file and return an URL?

com.jme.util.ImageLoader is an interface.  It's main method (load) takes an InputStream and returns a com.jme.image.Image.  The URL you pass to load the cursor is sent to TextureManager to create a texture.  It uses the name to determine the file type (like .png, .tga, etc.) and then passes the URL's data stream to a loader to get the image.  So assuming you were writing out just the Image in your binary export, you could write a class like this (not tested):

public class BinaryImageLoader implements ImageLoader {

    public Image load(InputStream is) throws IOException {

        // read data from binary file

        com.jme.image.Image img = (com.jme.image.Image)BinaryImporter.getInstance().load(is);

        return img;



If Texture is what you wrote to binary, you'd need to read a Texture and pull the image data out of it to return.

The other step you need to do then is register you reader with TextureManager:

TextureManager.registerHandler(".cur", new BinaryImageLoader());

Do that before loading your cursor, of course.

hope that helps!

renanse said:

yes, but you'll have to load it in as a Texture and apply it accordingly. not sure if u get what im talking about. coz i cant seem to find a renderstate for hardware mouse.

i want to set the cursor of this


and im just wondering if the url passed in can be a .cur file or even my own texture file file.texture?

You're right, I thought you were talking software cursor.  The answer is still yes though, BUT you'll have to write an ImageLoader (which should be pretty easy and would make a nice donation :slight_smile: ) and add it to TextureManager before you load the cursor.

thx alot~ and this is the method i wrote, pretty much the same as the one u provided as an example  :smiley:

    * Decodes image data from an InputStream.
    * @param is The InputStream to create the image from. The inputstream should be closed before
    *           this method returns.
    * @return The decoded Image.
    * @throws IOException
   public Image load(InputStream is) throws IOException {
      Texture tex = (Texture)BinaryImporter.getInstance().load(is);
      return tex.getImage();

Great, looks good.  Get it working then?

renanse said:

Great, looks good.