Exception while using [glTexImage2d]

Started by Abhi2011, November 22, 2013, 12:46:51

Previous topic - Next topic

Abhi2011

Hello guys,
I would like to first start of by saying that I am fairly new with OpenGl so please forgive me for my any stupidness.

When I ever try to render using the glTexImage2D of GL11 I get an OpenGlException. Here is the stacktrace.
Exception in thread "main" org.lwjgl.opengl.OpenGLException: Cannot use offsets when Pixel Unpack Buffer Object is disabled
	at org.lwjgl.opengl.GLChecks.ensureUnpackPBOenabled(GLChecks.java:141)
	at org.lwjgl.opengl.GL11.glTexImage2D(GL11.java:2889)
	at Objects.Npcs.NPC.Draw(NPC.java:50)
	at Graphics.Scene.DrawMob(Scene.java:25)
	at Graphics.Scene.Render_Graphics(Scene.java:14)
	at GameLogic.Gamelogic.run(Gamelogic.java:19)
	at Start.main(Start.java:20)


I have done my own research but couldn't find any topic relating to fixing this. This is my initialization code.
GL11.glEnable(GL11.GL_TEXTURE_2D);

		GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

		// enable alpha blending
		GL11.glEnable(GL11.GL_BLEND);
		GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

		GL11.glViewport(0, 0, 800, 600);
		GL11.glMatrixMode(GL11.GL_MODELVIEW);

		GL11.glMatrixMode(GL11.GL_PROJECTION);
		GL11.glLoadIdentity();
		GL11.glOrtho(0, 800, 600, 0, 1, -1);
		GL11.glMatrixMode(GL11.GL_MODELVIEW);


Thanks,
Abhi2011

Cornix

Could you maybe post the part of your code which generates errors?
glTexImage2D is not being used in the code you posted at all right now.

quew8

glTexImage2D() tells OpenGL what data to use for the texture. Now there are two ways of doing this. The first is just to put all of the data in a a JAVA buffer and then give this JAVA buffer to OpenGL. The other way is to point OpenGL to some data it already has in the form of a PIXEL buffer. In this case the pixel unpack buffer (there is also a pixel pack buffer). To do this you bind the PIXEL buffer, already filled with the data, and you pass an offset into the buffer to glTexImage2D(). In LWJGL you decide which version you are using by what parameters you pass into the function. The first takes a java.nio.XXXXBuffer and the second takes a long offset.

From the error message, you are using the second function. Hence you should have a PIXEL buffer bound. You don't which means that if LWJGL didn't notice the error and throw this exception, OpenGL would screw up. Actually you would just get a GL_INVALID_OPERATION error, but that is far harder to debug than this exception so you should be thanking LWJGL.

So clearly whatever you are trying to do with this function, you are not going about it the right way. As @Cornix says, post the relevant code, then tells us what you want / expect to occur. After that we can advise you better.

Sorry for the patronizing capitalization but it can get really confusing since in LWJGL we use buffers and buffers and yet they are two completely (sort of) different things.


Abhi2011

@Override
	public boolean Draw()
	{
		Texture tex = super.texsc.getTexture();

		Color.white.bind();
		tex.bind(); // or GL11.glBind(texture.getTextureID());
		
		texsc.addTimer();

		GL11.glBegin(GL11.GL_QUADS);
		{
			GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA,50 , 50, 0, GL11.GL_RGBA_MODE, GL11.GL_UNSIGNED_INT, 0);
		}
		GL11.glEnd();
		return true;
	}


This is my code. I couldn't get a well documented example. (Didn't get an example at all tbh)

Cornix

Thats not at all how you are supposed to do it.

The method:
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA,50 , 50, 0, GL11.GL_RGBA_MODE, GL11.GL_UNSIGNED_INT, 0);

uploads picture data to the graphics card. You usually do this ONLY ONCE, at the beginning.

And you are not supposed to call it within a begin-end-block.

I suggest you read one of the many tutorials first. There is plenty of tutorials about how to use immediate mode.
Here is one tutorial for example: http://www.lwjgl.org/wiki/index.php?title=LWJGL_Basics_3_%28The_Quad%29