Render To Texture

Is there anything I need to look out for when creating a testure renderer? Im getting the following error from the below piece of code (the line it is failing at)



Exception in thread "main" java.lang.NullPointerException

        at com.jme.renderer.lwjgl.LWJGLTextureRenderer.<init>(Unknown Source)

        at com.jme.system.lwjgl.LWJGLDisplaySystem.createTextureRenderer(Unknown Source)

        at com.influx.scene.RenderToTexture.<init>(RenderToTexture.java:69)



textureRenderer = DisplaySystem.getDisplaySystem().createTextureRenderer(256, 256, TextureRenderer.RENDER_TEXTURE_2D);



The DisplaySystem is not null (tested). The code was taken from the TestCameraMan or TestRenderToCamera (one or the other).

Looks like you are running into a threading issue.  Are you creating the texrenderer in a thread other than the OpenGL owner?  If so, that is the cause of the NPE.

Ok ive kept it as simple as possible



package com.influx.game;

import com.jme.renderer.ColorRGBA;
import com.jme.system.DisplaySystem;
import com.jmex.editors.swing.settings.GameSettingsPanel;
import com.jmex.game.state.GameStateManager;
import com.jmex.game.StandardGame;
import com.jme.renderer.TextureRenderer;

public class Client {

   private StandardGame game;
   private GameStateManager gameStateManager;

   /**
    * Class constructor.
    */
   public Client() {

      game = new StandardGame("Influx");
      
      try {
         GameSettingsPanel.prompt(game.getSettings());
      } catch(InterruptedException e) {
         e.printStackTrace();
         System.exit(0);
      }
      
      game.setBackgroundColor(ColorRGBA.black);
      game.start();
      
      DisplaySystem.getDisplaySystem().createTextureRenderer(256, 256, TextureRenderer.RENDER_TEXTURE_2D);
   }
   
   /**
    * Application entry point.
    *
    * @param args String[]
    */
   public static void main(String[] args) {

      new Client();
   }
}



Returns the following output using the most up-to-date version from CSV.

compile:
run:
WARNING: Found unknown Windows version: Windows Vista
Attempting to use default windows plug-in.
13-Jun-2007 20:24:33 com.jme.system.lwjgl.LWJGLDisplaySystem <init>
INFO: LWJGL Display System created.
13-Jun-2007 20:24:34 com.jme.renderer.lwjgl.LWJGLRenderer <init>
INFO: LWJGLRenderer created. W:  800H: 600
13-Jun-2007 20:24:35 com.jme.renderer.AbstractCamera <init>
INFO: Camera created.
13-Jun-2007 20:24:35 com.jmex.sound.openAL.SoundSystem <clinit>
INFO: DETECT OPERATING SYSTEM
13-Jun-2007 20:24:35 com.jmex.sound.openAL.SoundSystem <clinit>
INFO: CREATE OPENAL
13-Jun-2007 20:24:35 com.jmex.sound.openAL.SoundSystem initializeOpenAL
INFO: OpenAL initalized!
13-Jun-2007 20:24:35 com.jmex.sound.openAL.SoundSystem <clinit>
INFO: CREATE LISTENER
13-Jun-2007 20:24:35 com.jmex.game.state.GameStateManager create
INFO: Created GameStateManager
13-Jun-2007 20:24:35 com.jme.util.lwjgl.LWJGLTimer <init>
INFO: Timer resolution: 1000 ticks per second
Exception in thread "main" java.lang.NullPointerException
        at com.jme.renderer.lwjgl.LWJGLTextureRenderer.<init>(Unknown Source)
        at com.jme.system.lwjgl.LWJGLDisplaySystem.createTextureRenderer(Unknown Source)
        at com.influx.game.Client.<init>(Client.java:43)
        at com.influx.game.Client.main(Client.java:53)
Java Result: 1
BUILD SUCCESSFUL (total time: 10 seconds)

I would say that the problem is that the system is not initialized yet… Why don’t you create the TextureRenderer in simpleInitGame()?



Edit: Sorry about that, I noticed you are not using SimpleGame, but StandardGame… still it looks like either an initialization problem or a driver (capability) problem.

Yes, StandardGame is primarily designed for multithreading, but just to be clear, it is not necessary anything be done in more than one thread.