Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onDrawFrame not being called on Android

Tags:

java

android

I am having a problem where the renderer object doesn't seem to get its onDrawFrame called at all. The debugger never hits a breakpoint inside the function. Thus, my square isn't drawing. Here is the the code, let me know if you need anything else:

public class renderer implements GLSurfaceView.Renderer {

Square square;

public void onDrawFrame(GL10 unused) {
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    square.Draw();
}

public void onSurfaceChanged(GL10 gl, int width, int height) {
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
}

public void onSurfaceCreated(GL10 unused, int width, int height) {
    GLES20.glViewport(0, 0, width, height);

}

public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    square = new Square(5, 5);

}

The main activity is:

public class gameActivity extends Activity {
/** Called when the activity is first created. */

private GLSurfaceView mGLView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    staticHolder.context = getApplicationContext();
    mGLView = new GLSurface(this);
    setContentView(mGLView);
}
@Override
protected void onPause() {
    super.onPause();
    // The following call pauses the rendering thread.
    // If your OpenGL application is memory intensive,
    // you should consider de-allocating objects that
    // consume significant memory here.
    mGLView.onPause();
}

@Override
protected void onResume() {
    mGLView.onResume();
}


class GLSurface extends GLSurfaceView
{
    renderer r = new renderer();
    public GLSurface(Context context)

    {
        super(context);

        setEGLContextClientVersion(2);
        setRenderer(r);
        setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
    }
}

}

Currently the screen is just black. Is there any idea of why the openGL is not rendering properly?

like image 794
Serguei Fedorov Avatar asked Jul 01 '12 02:07

Serguei Fedorov


1 Answers

Ok, this was really stupid but there was no problem to begin with. The issue is that Eclipse/Java don't care about ambiguity like C# and other languages do (correct me if im wrong though). The issue was that I managed to duplicate the same class in different locations, with one updated and the other not. The end result was that it was grabbing the first one it could find.

Lesson learned, look out for ambiguity yourself because the compiler/parser will not tell you!

like image 54
Serguei Fedorov Avatar answered Sep 30 '22 11:09

Serguei Fedorov