0

Here is my problem: I have a GLSurfaceView with Renderer and stuff. Everything works just as I wanted, on older Android versions. But on newer versions (I guess > 4.X) it just shows a black screen without any Bitmaps. For example if I use gl.glClearColor(0.1f, 0.2f, 0.3f, 0.5f); in my onSurfaceCreated method, it changed from black to the color. So I think the problem must be the camera looking in the wrong direction or something, because the background-color is drawn.

Since I am pretty new to OpenGL, I wanted to ask if there are any connections between Android versions and the OpenGL-camera or something like that?

Many people say my Bitmap-Sizes have to be powers of 2, but it doesnt solve anything.

Here is my Renderer:

    public class GlRenderer implements Renderer {

@Override
public void onDrawFrame(GL10 gl) {

    // clear Screen Buffer
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    // Reset the Modelview Matrix
    gl.glLoadIdentity();

    gl.glTranslatef(0.0f, 0.0f, -5.0f);     // move 5 units INTO the screen
                                            // is the same as moving the camera 5 units away

    updateLogic(gl); 

    drawEverything(gl);
}

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GL10.GL_PROJECTION);                     // or some matrix uniform if using shaders
    gl.glLoadIdentity();
    gl.glOrthof(0, width, height, 0, -1, 1); // this will allow to pass vertices in 'canvas pixel' coordinates
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
}

@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    gl.glDisable(GL10.GL_DITHER);
    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);

    gl.glEnable(GL10.GL_TEXTURE_2D);            //Enable Texture Mapping ( NEW )
    gl.glShadeModel(GL10.GL_SMOOTH);            //Enable Smooth Shading
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);    //Set Background
    gl.glEnable(GL10.GL_BLEND);
    gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); 
}

}

genpfault
  • 51,148
  • 11
  • 85
  • 139

1 Answers1

0

Not sure if this is the issue you are having, but try changing the following line:

gl.Orthof(0, widht, height, 0, -1, 1);

to

gl.Orthof(0, widht, height, 0, 1, -1);

Notice that the near/far values are inverted. See this for a description of this maddness :)

free3dom
  • 18,729
  • 7
  • 52
  • 51
  • Its a 2D surface without depth, so this didnt change anything. Still black screen :( – user2757036 Sep 08 '13 at 15:33
  • The rest of the code you provided looks okay. However since you don't show any rendering and/or model creation code it is impossible to determine what else could be wrong. Might be your winding order, or maybe some state that is set somewhere. – free3dom Sep 08 '13 at 18:00
  • I think I found a solution. Will post here – user2757036 Sep 08 '13 at 18:11
  • I tried many things, and it seems that since I have gl.Orthof(0, widht, height, 0, -1, 1); I will have to delete gl.glTranslatef(0.0f, 0.0f, -5.0f); I do not fully understand this, but it works :) – user2757036 Sep 08 '13 at 18:17
  • Oh yeah, that should do it - I missed that call ;) The reason that it works when you remove it is that it translates all coordinates by -5.0f (since your onDraw() call operates on the model view). That puts all of them outside the view frustum. Since OpenGL is not actually working in 2D, the z dimension still exists, it is usually just on a single plane. – free3dom Sep 08 '13 at 20:29