Hello, I'm trying to write some king of java 3d game engine (starting at tetris : - P ) But I've got a really intreaging problem...
Well in short, when I call "GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GLL11.GL_DEPTH_BUFFER_BIT)" my aplication crashes and throws a NullPointerException...
Edit:
// troba quin es el bpp actual
int bpp =
Display.getDisplayMode().getBitsPerPixel();
//trobar el mode que busquem
DisplayMode[] modes =
Display.getAvailableDisplayModes();
DisplayMode mode = null;
for (int i=0;i<modes.length;i++) {
if ((modes[i].getBitsPerPixel() == bpp)
|| (mode == null))
{
if ((modes[i].getWidth() == width)
&& (modes[i].getHeight() == height))
mode = modes[i];
}
}
if (mode==null)
throw new Arexception("no s'ha trobat " +
"un mode de renderitzat adecuat");
Display.setTitle(titol);
Display.setDisplayMode(mode);
Display.setFullscreen(fullscreen);
Display.create();
//inicialitzacions OpenGL
GL11.glShadeModel(GL11.GL_SMOOTH);
GL11.glClearColor(0.3f, 0.3f, 0.2f, 0.0f);
GL11.glClearDepth(1.0f);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glDepthFunc(GL11.GL_LEQUAL);
GL11.glDisable(GL11.GL_CULL_FACE);
GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
GL11.glMatrixMode(GL11.GL_PROJECTION); // Select The Projection Matrix
GL11.glLoadIdentity(); // Reset The Projection Matrix
// Calculate The Aspect Ratio Of The Window
float ratio =((float)width)/((float)height);
GLU.gluPerspective(45.0f,ratio,1.0f,100.0f);
GL11.glMatrixMode(GL11.GL_MODELVIEW); // Select The Modelview Matrix
GL11.glLoadIdentity();
Do I miss anything?
are you doing Display.create in the same thread as GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GLL11.GL_DEPTH_BUFFER_BIT)?
is it only GL11.glClear that crashes ?
Quoteare you doing Display.create in the same thread as GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GLL11.GL_DEPTH_BUFFER_BIT)?
well... no I'm not...
I'm trying some kind of multithreated engine... and initialitzation is done in another thread... so... I see it may be a bad idea... I'll change it to the render thread
Edit:
It worked, so thanks
From now on, I s'pose that I should move every single GL call to the same thread, nop?
either that - or make sure to release and aquire the context as needed - tho it can be tricky to get right.
Every gl call at one thread, and no problems...
except from input xDDDDDD I works OK in debug mode, but not when I run it (using eclipse, BTW)