[solved] Always getting NullPointerException when trying to access OpenGL

Started by zezioen, December 21, 2010, 13:56:37

Previous topic - Next topic

zezioen

Hey everyone,

I've just downloaded LWJGL 2.6 and right now I can't render anything!
I can't even make a call to any OpenGL method.

I've added the natives to the project in Eclipse and to the run-time variables.
A fullscreen display is made but does not close when receiving a NullPointer. And it receives the NullPointer at the first call to the render method.

Here is the code that I currently use:

package com.nitrocrime.games.lwjgl.test;

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.*;

import static org.lwjgl.opengl.GL11.*;

public class TestLauncher extends Thread
{
	public static void main(String args[])
	{
		new TestLauncher();
	}
	
	private boolean rendering = true;
	
	public TestLauncher()
	{
		try
		{
			DisplayMode mode = Display.getDisplayMode();
	
			if (mode == null)
			{
				System.out.println("Error creating display mode");
				return;
			}
	
			// configure and create the LWJGL display
			Display.setTitle("LWJGL test");
			Display.setDisplayMode(mode);
			Display.setFullscreen(true);
			
			Display.create();
			
			this.start();
		} 
		catch (LWJGLException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void run()
	{
		while(rendering)
		{
			try 
			{
				Thread.sleep(1000/60);
			} 
			catch (InterruptedException e)
			{
				
			}
			render();
		}
	}
	
	private void render() 
	{
		glClearColor(1.0f,0.0f,0.0f,1.0f);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	}
}


And this is the error that I receive:
QuoteException in thread "Thread-0" java.lang.NullPointerException
   at org.lwjgl.opengl.GL11.glClearColor(GL11.java:570)
   at com.nitrocrime.games.lwjgl.test.TestLauncher.render(TestLauncher.java:65)
   at com.nitrocrime.games.lwjgl.test.TestLauncher.run(TestLauncher.java:59)

Line 65 is the call to GLClearColor and line 59 is the call to render.

Have I made a mistake or is this maby a bug in LWJGL?
I am using a IMac 24 Inch with an NVidia geforce 9400 graphics card.

Matthias

Well - you try to render in a different thread. Just remove threads from your program and make a simple loop like this:
Display.create();
while(!Display.isCloseRequested()) {
   GL11.glClear(....);
   // render stuff
   Display.update();
}
Display.destroy();