ClassCaseException上GL11ExtensionPack。纹理渲染OpenGL的机器人 [英] ClassCaseException on GL11ExtensionPack. Rendering to texture on OpenGL android

查看:205
本文介绍了ClassCaseException上GL11ExtensionPack。纹理渲染OpenGL的机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想渲染到纹理(真的以为它会比这更容易!)

I'm trying to render to a texture (really thought it would be easier than this!)

我发现这个资源:<一href=\"http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/FrameBufferObjectActivity.html\"相对=nofollow>这似乎正是我想要

我不过得到一个ClassCastException,上GL11ExtensionPack gl11ep =(GL11ExtensionPack)GL;

I'm getting a ClassCastException however, on GL11ExtensionPack gl11ep = (GL11ExtensionPack) gl;

谁能告诉我为什么吗?

  public void renderToTexture(GLRenderer glRenderer, GL10 gl)
  {
    boolean checkIfContextSupportsExtension = checkIfContextSupportsExtension(gl, "GL_OES_framebuffer_object");
    if(checkIfContextSupportsExtension)
    {
      GL11ExtensionPack gl11ep = (GL11ExtensionPack) gl;

      int mFrameBuffer = createFrameBuffer(gl,texture.getWidth(), texture.getHeight(), texture.getGLID());

      gl11ep.glBindFramebufferOES(GL11ExtensionPack.GL_FRAMEBUFFER_OES, mFrameBuffer);

      gl.glClearColor(0f, 1f, 0f, 1f);

      gl11ep.glBindFramebufferOES(GL11ExtensionPack.GL_FRAMEBUFFER_OES, 0);
    }
  }

问题通过去除固定 setDebugFlags(GLSurfaceView.DEBUG_LOG_GL_CALLS);

然而,它仍然没有修改的质感。我修改了code所以它的作用是明确的颜色为绿色,所以质地应该成为所有绿色。这里是createFrameBuffer方法。我真的不明白了一切,多数民众赞成在这回事:/

However, its still not modifying the texture. I modified the code so all it does is clear the colour green, so the texture should become all green. Here is the createFrameBuffer method. I don't really understand everything thats going on in this :/

private int createFrameBuffer(GL10 gl, int width, int height, int targetTextureId) {
GL11ExtensionPack gl11ep = (GL11ExtensionPack) gl;
int framebuffer;
int[] framebuffers = new int[1];
gl11ep.glGenFramebuffersOES(1, framebuffers, 0);
framebuffer = framebuffers[0];
gl11ep.glBindFramebufferOES(GL11ExtensionPack.GL_FRAMEBUFFER_OES, framebuffer);

int depthbuffer;
int[] renderbuffers = new int[1];
gl11ep.glGenRenderbuffersOES(1, renderbuffers, 0);
depthbuffer = renderbuffers[0];

gl11ep.glBindRenderbufferOES(GL11ExtensionPack.GL_RENDERBUFFER_OES, depthbuffer);
gl11ep.glRenderbufferStorageOES(GL11ExtensionPack.GL_RENDERBUFFER_OES,
        GL11ExtensionPack.GL_DEPTH_COMPONENT16, width, height);
gl11ep.glFramebufferRenderbufferOES(GL11ExtensionPack.GL_FRAMEBUFFER_OES,
        GL11ExtensionPack.GL_DEPTH_ATTACHMENT_OES,
        GL11ExtensionPack.GL_RENDERBUFFER_OES, depthbuffer);

gl11ep.glFramebufferTexture2DOES(GL11ExtensionPack.GL_FRAMEBUFFER_OES,
        GL11ExtensionPack.GL_COLOR_ATTACHMENT0_OES, GL10.GL_TEXTURE_2D,
        targetTextureId, 0);
int status = gl11ep.glCheckFramebufferStatusOES(GL11ExtensionPack.GL_FRAMEBUFFER_OES);
if (status != GL11ExtensionPack.GL_FRAMEBUFFER_COMPLETE_OES) {
    //throw new RuntimeException("Framebuffer is not complete: " +
    //        Integer.toHexString(status));
  Log.v("error","Frame buffer not complete");
} else {
  gl11ep.glBindFramebufferOES(GL11ExtensionPack.GL_FRAMEBUFFER_OES, 0);
  return -1;
}
return framebuffer;

}

推荐答案

调用 setDebugFlags GLSurfaceView 包在GL实例有/的中有的不幸sideeffect的不实现所有 GL * 接口的。的不幸的是,问题没有规定在版本是固定的。

Calling setDebugFlags on a GLSurfaceView to wrap the GL instance has/had the unfortunate sideeffect to not implementing all GL* interfaces. Unfortunately the issue does not state in which version this is fixed.

这篇关于ClassCaseException上GL11ExtensionPack。纹理渲染OpenGL的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆