Okay… I got this error, and I have absolutely no clue what it might be caused by. My code is more or less directly taken from NeHe tutorial jogl example code, since I’ve gone back step by step in order to track that bug. Didn’t work out.
Some code:
init function, should be self-explaining
this.drawable = drawable;
// we do this manually (in show()), so it's steadily done at the end of each tick
drawable.setAutoSwapBufferMode(false);
// get generic GLU :)
this.glu = new GLU();
drawable.setGL(new DebugGL(drawable.getGL()));
this.gl = drawable.getGL();
gl.glEnable(GL.GL_TEXTURE_2D);
gl.glShadeModel(GL.GL_SMOOTH);
gl.glClearDepth(1.0f);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthFunc(GL.GL_LEQUAL);
this.gl = null;
display method, interesting comments with !!!
// get surface
gl = drawable.getGL();
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
// go through queue and draw
// !!! in the second tick, the texture gets generated and bound here. nothing else to say, all other functionality gone for debugging
if(blah == null)
while(!queue.isEmpty())
// draw each element of this
queue.remove().draw(this);
try {
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glTranslatef(0.0f,0.0f,-5.0f);
// !!! blah is the texture (wrapped up in a simple class), in the first tick it's null, (draws red square), second tick it's there
if(blah == null) {
gl.glBindTexture(GL.GL_TEXTURE_2D, 0);
gl.glBegin(GL.GL_QUADS); {
gl.glColor3f(1.0f, 0.0f, 0.0f);
gl.glVertex3f(-1.0f, -1.0f, 1.0f);
gl.glVertex3f( 1.0f, -1.0f, 1.0f);
gl.glVertex3f( 1.0f, 1.0f, 1.0f);
gl.glVertex3f(-1.0f, 1.0f, 1.0f);
} gl.glEnd();
} else {
gl.glColor3f(0.0f, 1.0f, 1.0f);
// !!! simply binds texture, nothing else. checked a thousand times for errors
blah.bind(gl);
gl.glBegin(GL.GL_QUADS); {
// !!! code 1:1 from tutorial, the square is shown, but it's plain color
gl.glTexCoord2f(0.0f, 0.0f);
gl.glVertex3f(-1.0f, -1.0f, 1.0f);
gl.glTexCoord2f(1.0f, 0.0f);
gl.glVertex3f( 1.0f, -1.0f, 1.0f);
gl.glTexCoord2f(1.0f, 1.0f);
gl.glVertex3f( 1.0f, 1.0f, 1.0f);
gl.glTexCoord2f(0.0f, 1.0f);
gl.glVertex3f(-1.0f, 1.0f, 1.0f);
// !!! this glEnd gives the error (see below), but only in the tick after the texture is generated. after that, a solid square is drawn.
} gl.glEnd();
}
} catch (GLException e) {
e.printStackTrace();
}
// pass stuff to graka
gl.glFlush();
// make sure outside this procedure, no gl is called.
gl = null;
reshape
this.gl = drawable.getGL();
final float h = (float)width / (float)height;
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(45.0f, h, 1.0, 20.0);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
this.gl = null;
texture making code, only the important bits. everything else is a-ok.
// !!! serialized the byte[] array and put into the lesson06 code, it works, so up to here it's all right.
imageBuffer = ByteBuffer.allocateDirect(data.length);
imageBuffer.order(ByteOrder.nativeOrder());
imageBuffer.put(data, 0, data.length);
imageBuffer.rewind();
gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, texWidth, texHeight, 0, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, imageBuffer);
given error
javax.media.opengl.GLException: glGetError() returned the following error codes after a call to glEnd(): GL_INVALID_OPERATION
at javax.media.opengl.DebugGL.checkGLGetError(DebugGL.java:11724)
at javax.media.opengl.DebugGL.glEnd(DebugGL.java:1816)
at com.mugenguild.vMugen.graphics.OglDisplay.display(OglDisplay.java:244)
at com.sun.opengl.impl.GLDrawableHelper.display(GLDrawableHelper.java:78)
at javax.media.opengl.GLCanvas$DisplayAction.run(GLCanvas.java:281)
at com.sun.opengl.impl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:194)
at javax.media.opengl.GLCanvas.maybeDoSingleThreadedWorkaround(GLCanvas.java:258)
at javax.media.opengl.GLCanvas.display(GLCanvas.java:130)
at javax.media.opengl.GLCanvas.paint(GLCanvas.java:142)
at sun.awt.RepaintArea.paintComponent(Unknown Source)
at sun.awt.RepaintArea.paint(Unknown Source)
at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
javax.media.opengl.GLException: glGetError() returned the following error codes after a call to glEnd(): GL_INVALID_OPERATION
at javax.media.opengl.DebugGL.checkGLGetError(DebugGL.java:11724)
at javax.media.opengl.DebugGL.glEnd(DebugGL.java:1816)
at com.mugenguild.vMugen.graphics.OglDisplay.display(OglDisplay.java:266)
at com.sun.opengl.impl.GLDrawableHelper.display(GLDrawableHelper.java:78)
at javax.media.opengl.GLCanvas$DisplayAction.run(GLCanvas.java:281)
at com.sun.opengl.impl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:194)
at javax.media.opengl.GLCanvas$DisplayOnEventDispatchThreadAction.run(GLCanvas.java:298)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
wtf?! I’ve been shooting trouble for like, 5 hours now, and I can’t seem to find any error. the only difference left, is that the texture is bound during the display routine instead of the init routine. but that can’t be it… nuh?