Question

I try to display a cube in my android application, but i doesn't seem to work right on my HTC One SV, because the screen only remains white (i think because of glClearColor()) Here's the code of the two relevant classes:

public class ClassicByteRenderer implements GLSurfaceView.Renderer {

private Square square = new Square();
public int width = 0;
public int height = 0;

public void onDrawFrame(GL10 gl) {
    GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
    gl.glMatrixMode(GLES10.GL_PROJECTION);
    gl.glLoadIdentity();
    GLU.gluPerspective(gl, 45.0F, (float) this.width / (float) this.height,0.1F,100.0F);
    GLU.gluLookAt(gl, 5.0F, 10.0F, 5.0F, 1.0F, 1.0F, 0.0F, 0.0F, 1.0F, 0.0F);
    gl.glMatrixMode(GLES10.GL_MODELVIEW);
    gl.glLoadIdentity();
    this.drawCube(gl);
}

public void drawCube(GL10 gl) {
    gl.glColor4f(1.0F,1.0F,0.0F,1.0F);
    this.square.draw(gl);

    gl.glTranslatef(0.0F,0.0F,-2.0F);
    gl.glColor4f(1.0F,0.0F,0.0F,1.0F);
    this.square.draw(gl);

    gl.glTranslatef(1.0F,0.0F,1.0F);
    gl.glRotatef(90.0F,0.0F,1.0F,0.0F);
    gl.glColor4f(0.0F,0.0F,1.0F,1.0F);
    this.square.draw(gl);

    gl.glTranslatef(0.0F,0.0F,-2.0F);
    gl.glColor4f(0.0F,1.0F,0.0F,1.0F);
    this.square.draw(gl);

    gl.glTranslatef(0.0F,-1.0F,1.0F);
    gl.glRotatef(90.0F,-1.0F,0.0F,0.0F);
    gl.glColor4f(0.0F,1.0F,1.0F,1.0F);
    this.square.draw(gl);

    gl.glTranslatef(0.0F,0.0F,2.0F);
    gl.glColor4f(1.0F,0.0F,1.0F,1.0F);
    this.square.draw(gl);
}

public void onSurfaceChanged(GL10 gl, int width, int height) {
    GLES20.glViewport(0, 0, width, height);
    this.width = width;
    this.height = height;
}

public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    GLES20.glClearColor(1.0F, 1.0F, 1.0F, 1.0F);
    GLES20.glEnable(GLES20.GL_DEPTH_TEST);
    GLES20.glEnable(GLES20.GL_TEXTURE_2D);
    GLES20.glDisable(GLES20.GL_CULL_FACE);
    GLES20.glDepthFunc(GLES20.GL_LEQUAL);
    gl.glHint(GLES10.GL_PERSPECTIVE_CORRECTION_HINT, GLES10.GL_NICEST);
    GLES20.glDepthMask(true);
}

}

Here another one that could be necessary:

public class ClassicByteView extends GLSurfaceView {

public ClassicByteView(Context context) {
    super(context);
    super.setEGLConfigChooser(true);
    this.setEGLContextClientVersion(2);
    this.setRenderer(new ClassicByteRenderer());
    this.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
}
}

How everything should look like (that's how it is rendered in the emulator):

Was it helpful?

Solution

I was able to solve the problem myself. The solution was to delete

super.setEGLConfigChooser(true);
this.setEGLContextClientVersion(2);

in the ClassicByteView class. Now everything is working fine.

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