LWJGL
June 19, 2013, 11:04:21 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL is now using GitHub
 
   Home   Help Search Login Register  



Pages: [1]
  Print  
Author Topic: [solved] Always getting NullPointerException when trying to access OpenGL  (Read 1241 times)
zezioen
Newbie
*
Posts: 3


« on: December 21, 2010, 05:56:37 »

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:

Code:
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:
Quote
Exception 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.
Logged
Matthias
Talks Too Much
***
Posts: 180


WWW
« Reply #1 on: December 21, 2010, 06:18:42 »

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

zezioen
Newbie
*
Posts: 3


« Reply #2 on: December 21, 2010, 06:37:44 »

Thanks man it is working now!
 Grin
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!