Hey Iam getting this annoying error
"java.lang.NullPointerException
at org.lwjgl.opengl.GL11.glGenTextures(GL11.java:1206)
"
Long story short I know that not calling Display.Create() can cause this problem to arise, but in my source code iam 1000% sure that Display.Create() is being called before hand. So what else might be causing this error?
this can only fail if you have not created a display, are passing a null reference or dong have a OpenGL 1.1 ready card.
private void createWindow() throws Exception
{
Display.setFullscreen(fullscreen);
DisplayMode d[] = Display.getAvailableDisplayModes();
for (int i = 0; i < d.length; i++)
{
if (d[i].getWidth() == 640
&& d[i].getHeight() == 480
&& d[i].getBitsPerPixel() == 32)
{
displayMode = d[i];
break;
}
}
Display.setDisplayMode(displayMode);
Display.setTitle(windowTitle);
Display.create();
System.out.println("Display created");
Mouse.create();
}
private void init() throws Exception
{
createWindow();
initGL();
game = new Game();
game.connect();
}
private void initGL()
{
GL11.glEnable(GL11.GL_TEXTURE_2D); // Enable Texture Mapping
GL11.glShadeModel(GL11.GL_SMOOTH); // Enable Smooth Shading
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background
GL11.glClearDepth(1.0); // Depth Buffer Setup
GL11.glEnable(GL11.GL_DEPTH_TEST); // Enables Depth Testing
GL11.glDepthFunc(GL11.GL_LEQUAL); // The Type Of Depth Testing To Do
GL11.glMatrixMode(GL11.GL_PROJECTION); // Select The Projection Matrix
GL11.glLoadIdentity(); // Reset The Projection Matrix
// Calculate The Aspect Ratio Of The Window
GLU.gluPerspective(
45.0f,
(float) displayMode.getWidth() / (float) displayMode.getHeight(),
0.1f,
100.0f);
GL11.glMatrixMode(GL11.GL_MODELVIEW); // Select The Modelview Matrix
// Really Nice Perspective Calculations
GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
GL11.glPointSize(8.0f);
GL11.glLineWidth(2.0f);
try
{
Texture.Init();
}
catch(Exception e)
{
System.out.println("Could not instantiate IL " + e.toString());
}
}
but if you see my code game.connect(); is called way after Display.create() is being called, and no models/textures are loaded until you call game.connect(), but game.connect(), the game class also has threads running inside of it so do you think that might be leading to the problem?
definately - multithreading and opengl = bad
Only the thread that created the OpenGL context can use it.