Question

I have read some tutorials and trying to wrap my head around OpenGL ES 2.0. While trying to create a depth buffer, my JVM crashes. Btw I am using LibGDX framework.

  IntBuffer depthBuffer = BufferUtils.newIntBuffer(1);

  // AFAIK this puts 1 texture name into depthBuffer.
  Gdx.gl20.glGenTextures(1, depthBuffer);
  int depthBufferValue = depthBuffer.get();

  // I now bind the texture, so I can use it.
  Gdx.gl20.glBindTexture(GL20.GL_TEXTURE_2D, depthBufferValue);

I have no idea what glTexImage2D does, I suppose It should generate depth texture.

Next line crashes the JVM

Gdx.gl20.glTexImage2D(GL20.GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, Gdx.graphics.getWidth(),  Gdx.graphics.getHeight(), 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT,  BufferUtils.newIntBuffer(1));

Next line causes a NullPointerException

I don't know what should I put as glTexImage2D last parameter. I have seen examples for iOS where they put NULL.

Gdx.gl20.glTexImage2D(GL20.GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, null);

The rest of the code

  // This code should attach the depth texture into frame buffer
  IntBuffer depthFrameBuffer = BufferUtils.newIntBuffer(1);
  glGenFramebuffers(1, depthFrameBuffer);
  int depthFrameBufferValue = depthBuffer.get();
  glBindFramebuffer(GL_FRAMEBUFFER, depthFrameBufferValue);
  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthFrameBufferValue, 0);
  // I dont know what should I call next or what type of shader should I use

Please point me the right direction, or whenever I did make a mistake in my assumptions.

Tutorial would be best, I didn't find much about shadowmaps in OpenGL ES 2.0

Was it helpful?

Solution

There was a bug in libGDX that required the glTexImage2D texture parameter to be non-null (implying there must always be some local texture data to upload). It was fixed with this change: https://github.com/libgdx/libgdx/pull/228. This will be part of the release after 0.9.8 (most likely the 0.9.9 release).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top