2015-11-17 34 views
0

我已经尝试使用Android中的示例代码来学习OpenGL。但我看不到预期的输出。请指出问题在哪里?无法设置背景颜色并清除EGL中的输出

我已经使用fadden的贡献作为参考。

grafika-fadden

步骤1:

我已创建renderThread与renderHandler。

public void run() { 
     Looper.prepare(); 
     mHandler = new RenderHandler(this); 

     mEconEglCore = new EGLCore(null, EGLCore.FLAG_RECORDABLE); 
     EGLSurface eglSur = mEconEglCore.createWindowSurface(userSurface); 


     synchronized (mStartLock) { 
      mReady = true; 
      mStartLock.notifyAll(); 
     } 
     Looper.loop(); 
    } 

我在RenderThread构造函数中收到的userSurface。

public RenderThread(Surface surface) { 
     // Log.d (TAG, "Inside Render Thread.."); 
     userSurface = surface; 

    } 

现在,我在Choreographer回调机制的帮助下调用doFrame()API来绘制曲面中的颜色。

GLES20.glLineWidth(3.0f); 
GLES20.glClearColor(0.6f, 1.0f, 0.3f, 1.0f); 
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); 

注意:应用程序使用TextureView并按照以下方式接收到曲面。

mytextureView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() { 
      @Override 
      public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { 
       Log.d(TAG, "Surface Texture Available.."); 
       userSurface = new Surface(surface); 

问题:

我不知道如果我在OpenGL编码与正确的程序一致。此外,我没有看到任何颜色显示在表面,但只有黑色。即使我不做任何事我会做黑色。

请提供输入。另外,让我知道我需要知道的缺失部分?

回答

0

我想我发现了我犯下的错误。

1)我以

eglCreateWindowSurface 

错失创建或表面以EGL上下文相关联的以下两个步骤:

2)。但是,我忘了将当前表面告知EGL上下文。所以,我做到了。

EGL14.eglMakeCurrent(mEGLDisplay, eglUserSurface, eglUserSurface, 
      mEGLContext); 

3)我们需要swapBuffer.of表面。我已经通过

EGL14.eglSwapBuffers(mEGLDisplay, eglUserSurface); 

做现在,我看到我的表面颜色已经得到了改变,以绿色。

今天学到了一些新东西。谢谢。