Author Topic: Hardware Renderer Error  (Read 7097 times)

Offline Jamison

  • byte
  • *
  • Posts: 12
    • View Profile
Hardware Renderer Error
« on: August 22, 2006, 07:50:18 pm »
Hello all,

I'm trying to render in OpenGL Hardware mode, however, the following is thrown as soon as buffer.clear() is called.
Code: [Select]
java.lang.NullPointerException
        at org.lwjgl.opengl.GL11.glClearColor(GL11.java:562)
        at com.threed.jpct.GLRenderer.execute(Unknown Source)
        at com.threed.jpct.FrameBuffer.clearHardware(Unknown Source)
        at com.threed.jpct.FrameBuffer.clear(Unknown Source)
        at com.threed.jpct.FrameBuffer.clear(Unknown Source)
        at Hardware3D.Render(Hardware3D.java:35)
        at Hardware3D.run(Hardware3D.java:27)
        at java.lang.Thread.run(Thread.java:536)


Here is my code:
Code: [Select]
import java.awt.*;
import com.threed.jpct.*;

public class Hardware3D implements Runnable {
int fps = 60;
int gameW = 640;
int gameH = 480;

World world;
Camera camera;
FrameBuffer buffer;

public Hardware3D() {
buffer = new FrameBuffer(gameW, gameH, buffer.SAMPLINGMODE_NORMAL);
buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
buffer.enableRenderer(IRenderer.RENDERER_OPENGL, IRenderer.MODE_OPENGL);

world = new World();
camera = world.getCamera();

(new Thread(this)).start();
}

public void run() {
while(true) {
try {
Render();
GameLoop();
Thread.currentThread().sleep(1000/fps);
} catch(InterruptedException e){}
}
}

public void Render() {
buffer.clear();
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
buffer.displayGLOnly();
}

public void GameLoop() {
}

public static void main(String args[]) {
new Hardware3D();
}
}


I could not find any tutorial or any kind of information on how to render in OpenGL Hardware mode, so I looked through the documentation. I'm assuming I did something wrong here. I'd appreciate any help you can give me.

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
Hardware Renderer Error
« Reply #1 on: August 23, 2006, 12:26:17 am »
try to initialize te hardware renderer inside the run method!

Egon said its an lwjgl feature nothing to be with jpct.
Nada por ahora

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Hardware Renderer Error
« Reply #2 on: August 23, 2006, 12:27:21 am »
Don't enable the renderer in another thread than the one you are doing the actual rendering in. LWJGL doesn't support this.

Edit: Got owned by Melssj5...one minute too late... :D

Offline Jamison

  • byte
  • *
  • Posts: 12
    • View Profile
Hardware Renderer Error
« Reply #3 on: August 23, 2006, 12:35:00 am »
Thank you guys for the reply. After I found your Paradroidz source and scanned it for about 2 hours, I figured out that my Thread was causing the problem (like you both said), but now I have another... nothing is being rendered onto the screen. Here's my new and updated code:
Code: [Select]
import java.awt.*;
import java.awt.event.*;
import com.threed.jpct.*;
import com.threed.jpct.util.*;

public class Hardware3D {
int fps = 60;
int gameW = 640;
int gameH = 480;
boolean running = true;

World world;
Camera camera;
FrameBuffer buffer;
KeyMapper keyMapper;
TextureManager texMan;

Object3D object;

public Hardware3D() {
texMan = TextureManager.getInstance();

Config.glWindowName = "Hardware 3D";
Config.glSetDesiredVideoMode(32, 16, 60, false);
buffer = new FrameBuffer(gameW, gameH, buffer.SAMPLINGMODE_NORMAL);
buffer.enableRenderer(IRenderer.RENDERER_OPENGL);
buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);

world = new World();
camera = world.getCamera();

texMan.addTexture("block", new Texture("Block.png"));
object = Loader.load3DS("Block.3ds", 1f)[0];
object.setTexture("block");
world.addObject(object);

world.buildAllObjects();

camera.setPosition(new SimpleVector(0, 0, -10));

keyMapper = new KeyMapper();
Render();
}

public void ExitNow() {
System.exit(-1);
}

public void Render() {
while(running) {
buffer.clear();
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
buffer.displayGLOnly();

Controls();
GameLoop();

try {
Thread.currentThread().sleep(1000/fps);
} catch(InterruptedException e){}
}
ExitNow();
}

public void Controls() {
int k = keyMapper.poll().getKeyCode();

if (k == KeyEvent.VK_ESCAPE) running = false;
}

public void GameLoop() {
}

public static void main(String args[]) {
new Hardware3D();
}
}

Now what am I doing wrong?

Sorry if it seems like I'm an idiot with jPCT, but it's quite hard without any tutorials. :(

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
Hardware Renderer Error
« Reply #4 on: August 23, 2006, 12:38:29 am »
WEll, 2 things.

1.- Are you sure you are far enough to see the object.

2.- There are no lights there, so you cant see in the dark.
Nada por ahora

Offline Jamison

  • byte
  • *
  • Posts: 12
    • View Profile
Hardware Renderer Error
« Reply #5 on: August 23, 2006, 12:40:47 am »
1. Yes, the view is far enough back (since it renders at that same distance in software mode, and the model's size is 2m).

2. I didn't think lights were required. In software mode it renders without lights, or is OpenGL differant?

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
Hardware Renderer Error
« Reply #6 on: August 23, 2006, 12:43:33 am »
I guess Egon should answer that. try to put the lights and see by yourself.
Nada por ahora

Offline Jamison

  • byte
  • *
  • Posts: 12
    • View Profile
Hardware Renderer Error
« Reply #7 on: August 23, 2006, 12:47:02 am »
Okay, I added a white light (10, 10, 10) at position 0, 0, -3, and also tried it at 0, 0, -10. Still nothing... I'm stumped. :cry:

EDIT: Apparently the light colors needed to be higher values than software mode, because I changed the light color to 100, 100, 100 and it works now!!!

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
Hardware Renderer Error
« Reply #8 on: August 23, 2006, 12:49:59 am »
well 10,10,10 is not white, is almost black, anyway you should see something, let me check the code.
Nada por ahora

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
Hardware Renderer Error
« Reply #9 on: August 23, 2006, 12:52:48 am »
can you post the complete code now using the lights.?
Nada por ahora

Offline Jamison

  • byte
  • *
  • Posts: 12
    • View Profile
Hardware Renderer Error
« Reply #10 on: August 23, 2006, 12:55:20 am »
Quote from: "Melssj5"
well 10,10,10 is not white, is almost black, anyway you should see something, let me check the code.

Well, whenever I was rendering in software mode, 10, 10, 10 was perfect (sometimes even too bright).

Here's the code:
Code: [Select]
import java.awt.*;
import java.awt.event.*;
import com.threed.jpct.*;
import com.threed.jpct.util.*;

public class Hardware3D {
int fps = 60;
int gameW = 640;
int gameH = 480;
boolean running = true;

World world;
Camera camera;
FrameBuffer buffer;
KeyMapper keyMapper;
TextureManager texMan;

Object3D object;

public Hardware3D() {
texMan = TextureManager.getInstance();

Config.glWindowName = "Hardware 3D";
Config.glSetDesiredVideoMode(32, 16, 60, false);
buffer = new FrameBuffer(gameW, gameH, buffer.SAMPLINGMODE_NORMAL);
buffer.enableRenderer(IRenderer.RENDERER_OPENGL);
buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);

world = new World();
camera = world.getCamera();

world.addLight(new SimpleVector(0, 0, -10), new Color(100, 100, 100));

texMan.addTexture("block", new Texture("Block.png"));
object = Loader.load3DS("Block.3ds", 1f)[0];
object.setTexture("block");
world.addObject(object);

world.buildAllObjects();

camera.setPosition(new SimpleVector(0, 0, -5));

keyMapper = new KeyMapper();
Render();
}

public void ExitNow() {
System.exit(-1);
}

public void Render() {
while(running) {
buffer.clear();
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
buffer.displayGLOnly();

Controls();
GameLoop();

try {
Thread.currentThread().sleep(1000/fps);
} catch(InterruptedException e){}
}
ExitNow();
}

public void Controls() {
int k = keyMapper.poll().getKeyCode();

if (k == KeyEvent.VK_ESCAPE) running = false;
}

public void GameLoop() {
}

public static void main(String args[]) {
new Hardware3D();
}
}

(I moved the camera forward by 5 meters just because the model was too far back - it made no rendering differance except -5m is closer.)

EDIT:
Note that I was playing around with the lights and remember Config.setAmbientLight() and it looks better with ambient light color 200, 200, 200.

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
Hardware Renderer Error
« Reply #11 on: August 23, 2006, 01:06:33 am »
well, all I can suggest and say now just by viewing the code is:

1) Did jpct allowed you to load a png pic as a texture?

2) remove the desired video mode

3) set the running=true inside the constructor

4) add some console messages to see if the loop is being executed, to see what if happening!

5) use the the enableRenderer form that has 2 parameters

you should see it now, but try this to see what is happening, I have not used jpct in many time, just came here ocassionally to help.
Nada por ahora