Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying simply to display an openGL surface when I click the screen using GLSurfaceView.RENDERMODE_WHEN_DIRTY mode

but the surface does not display when I click it , why ?

my Activity :

public class ViewManager extends Activity {
    private GLSurfaceView surfaceView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        surfaceView = new GLSurfaceView(this);
        surfaceView.setEGLContextClientVersion(2);
        surfaceView.setRenderer(new MyRenderer());
        surfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

        surfaceView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if(event!=null){
                    if (event.getAction()==MotionEvent.ACTION_DOWN)
                        surfaceView.requestRender();
                    return true;
                }else{
                    return false;
                }
            }
        });

    }

    @Override
    protected void onResume() {
        super.onResume();
        surfaceView.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        surfaceView.onPause();
    }
}
share|improve this question

You have never actually added the surfaceView to the activity. So add this at the end of your activity's onCreate method should fix that.

setContentView(surfaceView);
share|improve this answer
    
but if I add the surfaceView to the activity it instantly appears . I want it to appear only when I call the requestRender command – yanish Dec 14 '15 at 7:32
    
Well just take what I just said and replace it with surfaceView.requestRender(); instead. – Christer Dec 14 '15 at 9:00
    
@yanish Well then add it to the activity when you want it to appear? Having it not appear instantly is not the purpose of RENDERMODE_WHEN_DIRTY. – immibis Jan 13 at 6:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.