How to change frame title/icon on lwjgl?

Started by Mr.Marbles, April 02, 2007, 07:34:03 PM

Previous topic - Next topic

Mr.Marbles

I'm trying to find a way to access the native window that gets created with the FrameBuffer.displayGLOnly() method. I need to change the title and icon of this window. I notice that the title is "http://www.jpct.net" so it seems that jPCT has access to this window and is modifying the title. Is it possible to get a reference to this window through jPCT?

Mr.Marbles

I just found the API. It's in org.lwjgl.opengl.Display

public static void setTitle(java.lang.String newTitle);
public static int setIcon(java.nio.ByteBuffer[] icons);


Now all I need to find out is how to get a ByteBuffer out of an Image  ???

EgonOlsen

This is taken directly from Paradroidz. It should be easy to adjust it to your needs:


   private IntBuffer createBuffer(Image img) {
      int len=img.getHeight(null)*img.getWidth(null);
      ByteBuffer temp=ByteBuffer.allocateDirect(len<<2);;
      temp.order(ByteOrder.LITTLE_ENDIAN);

      int[] pixels=new int[len];

      PixelGrabber pg=new PixelGrabber(img, 0, 0, img.getWidth(null), img.getHeight(null), pixels, 0, img.getWidth(null));

      try {
         pg.grabPixels();
      } catch (InterruptedException e) {
         Logger.log("Could not grab pixels from image!", Logger.ERROR);
      }

      for (int i=0; i<len; i++) {
         int pos=i<<2;
         int texel=pixels[i];
         if (texel!=0) {
            texel|=0xff000000;
         }
         temp.putInt(pos, texel);
      }

      return temp.asIntBuffer();
   }

Melssj5

The Config class has what you need to change the title of the windows when using hardware rendering. For changing the icon, then I dont know.

for example.

Config.glWindowName="My own game";
Nada por ahora