2012-01-27 67 views

回答

5

繪製一個覆蓋整個視口的紋理四邊形。爲此,請將投影和模型視圖切換爲標識並禁用深度測試。使用投影和模型視圖作爲身份頂點座標[-1 ... 1]將覆蓋整個視口。代碼:

glViewport(0, 0, width, height); 
glMatrixMode(GL_PROJECTION); 
glLoadIdentity(); 
glMatrixMode(GL_MODELVIEW); 
glLoadIdentity(); 

GLfloat tex_quad[16] = { 
/* x, y, s, t */ 
-1, -1, 0, 0, 
1, -1, 1, 0, 
1, 1, 1, 1, 
-1, 1, 0, 1 
};  

glVertexPointer(2, GL_FLOAT, sizeof(GLfloat)*4, &tex_quad[0]); 
glTexCoordPointer(2, GL_FLOAT, sizeof(GLfloat)*4, &tex_quad[2]); 

glDisable(GL_DEPTH_TEST); 
glDepthMask(GL_FALSE); 
glEnable(GL_TEXTURE_2D); 
glBindTexture(GL_TEXTURE_2D, background_image_texture_ID); 

glDrawArrays(GL_TRIANGLE_FAN, 0, 4); 

glEnable(GL_DEPTH_TEST); 
glDepthMask(GL_TRUE); 
glDisable(GL_TEXTURE_2D); 
+0

錯誤:E/libEGL:所謂的未實現的OpenGL ES API – 2017-12-30 12:15:00

3

在我的項目創造的所有代碼GLSurfaceView樣子:

glSurfaceView = ... 

glSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0); 
glSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT); 
glSurfaceView.setBackgroundResource(R.drawable.my_background); 
glSurfaceView.setZOrderOnTop(true); 

glSurfaceView.setRenderer(...); 
glSurfaceView.setRenderMode(...); 

注意:不要使用

_glSurfaceView.setBackgroundDrawable(this.getResources().getDrawable(R.drawable.my_background)); 

我浪費了這幾天。

別叫

gl.glClearColor(...) 

Renderer.onDrawFrame