如何在GLWallpaperService Renderer中设置背景图像,并在其上呈现其他对象

时间:2015-08-10 07:12:30

标签: android opengl-es background render glsurfaceview

我想将背景设置为GLSurfaceView.Renderer中的图像替换为黑色,是否可以在其上呈现其他对象,就像多个立方体渲染一样?

screen shot of my issue

我的渲染器类代码如下所示,

public MyGLRenderer(Context context){
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config){
gl.glClearColor(0, 0, 0,255f); 
gl.glClearDepthf(1.0f);          
gl.glEnable(GL10.GL_DEPTH_TEST); 
gl.glDepthFunc(GL10.GL_LEQUAL);  
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST); 
gl.glShadeModel(GL10.GL_SMOOTH);   
gl.glDisable(GL10.GL_DITHER);
gl.glOrthof(0, 1, 0 , 1, -1, 1);

cube.loadTexture(gl);             

gl.glEnable(GL10.GL_ALPHA_TEST);
gl.glAlphaFunc(GL10.GL_GREATER,0);
gl.glEnable(GL10.GL_TEXTURE_2D);  

}

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
if (height == 0) { 
    height = 1; 
}

gl.glViewport(0, 0, width, height); 
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity(); 

GLU.gluPerspective(gl, 45.0f, (float) width / (float) height, 0.1f,100.0f);

gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity(); 

}

@Override
public void onDrawFrame(GL10 gl) {

gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

gl.glLoadIdentity();                 

gl.glPushMatrix();
cube.draw(gl);
gl.glPopMatrix();

}
}

0 个答案:

没有答案
相关问题