Slick Forums

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

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Sun Sep 02, 2012 6:55 pm 
Offline

Joined: Sun Sep 02, 2012 6:46 pm
Posts: 4
I'm using slick2D to draw text in my java project. The project is not running on slick, I'm just using it to render text. But the problem is when I try to render anything with texture, it throws me an error.
Code:
Exception in thread "main" java.lang.RuntimeException: Image based resources must be loaded as part of init() or the game loop. They cannot be loaded before initialisation.
   at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:228)
   at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:184)
   at org.newdawn.slick.opengl.TextureLoader.getTexture(TextureLoader.java:64)
   at org.newdawn.slick.opengl.TextureLoader.getTexture(TextureLoader.java:24)
   at engine.entity.RectangleTextured.setTexture(RectangleTextured.java:51)
   at main.states.DefaultState.onEnter(DefaultState.java:39)
   at engine.Game.changeState(Game.java:106)
   at main.Crash.main(Crash.java:17)

Is there any way around it? I want to use slick to load textures AND to render text. I could render the text using small rectangles with texture but it would be really inconvinient, long, buggy and not so pretty.


Top
 Profile  
 
PostPosted: Sun Sep 02, 2012 9:10 pm 
Offline

Joined: Wed Jul 06, 2011 5:14 pm
Posts: 33
Have you tried using the 'slick-utils' library they provide? It contains Image loading and stuff for LWJGL (OpenGL).


Top
 Profile  
 
PostPosted: Sun Sep 02, 2012 10:06 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1477
You need to do texture loading on the GL thread after a call to Display.create() otherwise you will run into that exception.


Top
 Profile  
 
PostPosted: Sun Sep 02, 2012 10:34 pm 
Offline

Joined: Fri Aug 31, 2012 6:54 pm
Posts: 8
davedes wrote:
You need to do texture loading on the GL thread after a call to Display.create() otherwise you will run into that exception.


Top
 Profile  
 
PostPosted: Mon Sep 03, 2012 9:14 am 
Offline

Joined: Sun Sep 02, 2012 6:46 pm
Posts: 4
Mech wrote:
Have you tried using the 'slick-utils' library they provide? It contains Image loading and stuff for LWJGL (OpenGL).

When I use slick-util I can't make text and when I use slick2d I can't use textures


Top
 Profile  
 
PostPosted: Mon Sep 03, 2012 9:21 am 
Offline

Joined: Sun Sep 02, 2012 6:46 pm
Posts: 4
davedes wrote:
You need to do texture loading on the GL thread after a call to Display.create() otherwise you will run into that exception.

I'm new to java so could you explain it a bit more? If you need I could post some of my source codes.


Top
 Profile  
 
PostPosted: Mon Sep 03, 2012 3:52 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1477
Look at the LWJGL wiki as it will explain how to set up an OpenGL context and display. After the display is created, e.g. in your "init" method, you can start loading textures, sounds, and so forth in the same thread.

LWJGL/OpenGL isn't really suited for "Java noobs" so maybe you'd be better off learning how to program before trying to make a game, and once you feel comfortable with basic programming concepts, move to Slick2D or LibGDX.


Top
 Profile  
 
PostPosted: Tue Sep 04, 2012 10:26 am 
Offline

Joined: Sun Sep 02, 2012 6:46 pm
Posts: 4
I am loading them in my update method that is after Display.create().
Code:
public void start() {      
      try{
         Display.setDisplayMode(new DisplayMode(this.windowWidth, this.windowHeight));
         Display.setFullscreen(this.getFullscreen());
         Display.setVSyncEnabled(this.getVsync());
         Display.setTitle(this.getTitle() + " " + this.getTitleExtension() + " (" + this.getVersion() + ")");
         Display.create();
      }catch(LWJGLException e){
         e.printStackTrace();
         System.exit(1);
      }
        
      if(this.activeState.getDimensions() == 2){
         glMatrixMode(GL_PROJECTION);
           glLoadIdentity();
           glOrtho(0, this.windowWidth, this.windowHeight, 0, 1, -1);
           glMatrixMode(GL_MODELVIEW);
         }else if(this.activeState.getDimensions() == 3){
           glMatrixMode(GL_PROJECTION);
           glLoadIdentity();
           gluPerspective(this.FOV, this.windowWidth / this.windowHeight, 0.001f, 100);
           glMatrixMode(GL_MODELVIEW);
         }else{
             System.out.println("Invalid dimensions number in this state. Cannot set-up OpenGL. Shutting down.");
             System.exit(1);
         }
          
      lastFrame = Time.getTime();
      setUpDebug();
      
      while(!Display.isCloseRequested()){
         update(this.calculateDelta(), this);
         render();      
         Display.update();
      }
   }


Top
 Profile  
 
PostPosted: Tue Sep 04, 2012 2:59 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1477
Where is the image loading code? There is none in that code block.

From the looks of it you are initializing the states before calling start(), and some of the state initialization code depends on the GL context which has not yet been created.

Can't really help you much without looking at more of your code. My advice is to look at the stack trace you posted in the OP and determine where the loading is actually taking place.


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

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 2 guests


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