Slick Forums

Discuss the Slick 2D Library
It is currently Thu Jun 20, 2013 9:08 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Fri Oct 17, 2008 1:10 am 
Offline
Regular

Joined: Sun Oct 05, 2008 9:24 pm
Posts: 173
If you change the cursor via setMouseCursor "a whole bunch", then it blows up.

the reason I'm doing it 'a whole bunch' is because I'm updating the cursor based on the state of the game (ie. different cursor when over enemy, versus when over the hud or a friendly target, etc).

Here is some example code, it's excessive; but just put it in there so you could see what it does. the 3 images are just png images 31x31 pixels. Let it run 30-60 seconds and you will see it.

Code:
import org.newdawn.slick.Animation;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Color;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;

import org.newdawn.slick.util.Log;


public class MouseTest extends BasicGame {

   private String cursorSelect;
   private String cursorNone;
   private String cursorNo;

   public MouseTest() { super("MouseTest"); }

   public static void main(String [] arguments) {
      try {
         AppGameContainer app = new AppGameContainer(new MouseTest());
         app.setDisplayMode(600,480,false);

         app.setShowFPS(true);
         app.setVerbose(true);

         app.setTitle("Mouse Test");

         app.start();
      } catch (SlickException e) {
         e.printStackTrace();
      }
   }
   @Override
   public void init(GameContainer container) throws SlickException {

      cursorSelect = "gfx/cursors/cursorSelect.png";
      cursorNone= "gfx/cursors/cursorNone.png";
      cursorNo= "gfx/cursors/cursorNo.png";    
   }     
     
   @Override
   public void update(GameContainer container, int delta) throws SlickException {

       container.setMouseCursor(cursorNone, 15, 15);
       container.setMouseCursor(cursorNo, 15, 15);
       container.setMouseCursor(cursorSelect, 15, 15);

   }       
   public void render(GameContainer container, Graphics g) throws SlickException {
       container.setMouseCursor(cursorNone, 15, 15);
       container.setMouseCursor(cursorNo, 15, 15);
       container.setMouseCursor(cursorSelect, 15, 15);
   

   }
}



Here is the error it spits out:

Code:
Thu Oct 16 19:52:33 CDT 2008 INFO:Chances are you cursor is too small for this platform
Thu Oct 16 19:52:33 CDT 2008 ERROR:Failed to load and apply cursor.
Thu Oct 16 19:52:33 CDT 2008 ERROR:org.lwjgl.LWJGLException: Could not allocate DIB section.
org.lwjgl.LWJGLException: org.lwjgl.LWJGLException: Could not allocate DIB section.
        at org.newdawn.slick.opengl.CursorLoader.getCursor(CursorLoader.java:81)
        at org.newdawn.slick.AppGameContainer.setMouseCursor(AppGameContainer.java:208)
        at Cursor.setCursor(Cursor.java:181)
        at MountainDefender.renderValidArea(MountainDefender.java:341)
        at MountainDefender.render(MountainDefender.java:237)
        at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:576)
        at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:371)
        at MountainDefender.main(MountainDefender.java:134)
Caused by: org.lwjgl.LWJGLException: Could not allocate DIB section.
        at org.lwjgl.opengl.WindowsDisplay.nCreateCursor(Native Method)
        at org.lwjgl.opengl.WindowsDisplay.doCreateCursor(WindowsDisplay.java:519)
        at org.lwjgl.opengl.WindowsDisplay.createCursor(WindowsDisplay.java:515)
        at org.lwjgl.input.Cursor.createCursors(Cursor.java:192)
        at org.lwjgl.input.Cursor.<init>(Cursor.java:107)
        at org.newdawn.slick.opengl.CursorLoader.getCursor(CursorLoader.java:78)
        ... 7 more


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 17, 2008 7:26 am 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
It's a bug with the platform really I suppose, but it does need to be resolved, probably in LWJGL. I'll check it out with them.

For now however, if you're looking to get an animated cursor, you can do that through the LWJGL API easier. I can expose that in Slick too if required.

Whats the use case?

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 17, 2008 8:57 pm 
Offline
Regular

Joined: Sun Oct 05, 2008 9:24 pm
Posts: 173
kevglass wrote:
It's a bug with the platform really I suppose, but it does need to be resolved, probably in LWJGL. I'll check it out with them.

For now however, if you're looking to get an animated cursor, you can do that through the LWJGL API easier. I can expose that in Slick too if required.

Whats the use case?

Kev


No, I don't use an animated cursor. Just change it a lot based on it's position.

For now I created a work around. I just set the cursor to a transparent PNG ONCE and then "draw" and Image at the cursor location (with the correct offsets) and that looks exactly like what I was doing with SetMouseCursor.

That works, but think it might 'tear' if I put vsync on.

So I guess from my point of view I would consider it a low priority since I can 'cheat' around it for now.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group