20

I tried the program as shown in book OpenGL ES2 for Android, but it's not working!!

I have tested in Odroid E, samsung s3, samsung y, samsung star!!

the gl version suported returns 2, but i get
11-22 15:09:45.804: E/oGl-es v(9047): 2.0:131072
11-22 15:09:45.804: E/libEGL(9047): call to OpenGL ES API with no current context     (logged once per thread)
11-22 15:09:45.804: E/unable to(9047): createShader
11-22 15:09:45.804: E/libEGL(9047): call to OpenGL ES API with no current context (logged once per thread)
11-22 15:09:45.804: E/unable to(9047): createShader
11-22 15:09:45.804: E/libEGL(9047): call to OpenGL ES API with no current context (logged once per thread)
11-22 15:09:45.804: E/Error creating(9047): GL programObject
11-22 15:09:45.812: E/render(9047): set
11-22 15:09:46.062: E/Results of validating program:(9047): 0
11-22 15:09:46.062: E/Results of validating program:(9047): Log:

Below are my code

public class Main_OGLT1 extends Activity {

    MySurface mGLSurfaceView;
private boolean renderSet;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mGLSurfaceView = new MySurface(this);//(this); //instantiation

        ActivityManager actMan = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        ConfigurationInfo mConfigInfo = actMan.getDeviceConfigurationInfo();
        boolean isES2Compat = (mConfigInfo.reqGlEsVersion >= 0x20000);
        Log.e("oGl-es v",mConfigInfo.getGlEsVersion()+":"+ mConfigInfo.reqGlEsVersion);
        if(isES2Compat){


            renderSet = true;
            Log.e("render","set");

        }


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main__oglt1, menu);
        return true;
    }

    @Override
    protected void onResume()
    {
        // The activity must call the GL surface view's onResume() on activity onResume().
        super.onResume();
        mGLSurfaceView.onResume();
    }

    @Override
    protected void onPause()
    {
        // The activity must call the GL surface view's onPause() on activity onPause().
        super.onPause();
        mGLSurfaceView.onPause();
    }

}

The class MySurface :

    public class MySurface extends GLSurfaceView{

    public MySurface(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
        setEGLContextClientVersion(2);
        setRenderer(new MyTestRenderer(getContext()));
    }

 }
genpfault
  • 51,148
  • 11
  • 85
  • 139
nmxprime
  • 1,506
  • 3
  • 25
  • 52

1 Answers1

19

The problem is with glSurfaceView, as it does not run on the OpenGL thread. The glSurfaceView should be on the main android thread.

Here you find additional info about it:

opengl es api with no current context

OpenGL ES 2.0 Context in Android

Hope this help.

Community
  • 1
  • 1
Avanz
  • 7,466
  • 23
  • 54
  • Actually, if i comment setEGLContextClientVersion(2); i get unimplemented gl call log – nmxprime Nov 23 '13 at 08:20
  • The link you posted doesnot correspond to my question, as i dnt initiate anything before calling setRenderer. Also, my device definitely supports openGL ES2 – nmxprime Nov 23 '13 at 09:38
  • This helped. http://stackoverflow.com/questions/17399087/glcreateshader-and-glcreateprogram-fail-on-android but now compiling shader fails stating no main function for shader. but the shader string have void main() – nmxprime Nov 23 '13 at 10:47
  • @nmxprime *"Actually, if i comment setEGLContextClientVersion(2); i get unimplemented gl call log"* I'm not sure why you would do that to begin with. You can't make 2.0 calls without specifying it as the client version. – arkon Oct 05 '14 at 20:44
  • @b1nary.atr0phy, That's a blunter i did while i hadn't know what tat would have mean to be – nmxprime Oct 07 '14 at 04:45