android – OPENGL ES不工作:否当前上下文

前端之家收集整理的这篇文章主要介绍了android – OPENGL ES不工作:否当前上下文前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试过这个程序,如OpenGL ES2 for Android所示,但它不工作!

我已经在Odroid E测试了,三星s3,三星y,三星星!

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

以下是我的代码

  1. public class Main_OGLT1 extends Activity {
  2.  
  3. MySurface mGLSurfaceView;
  4. private boolean renderSet;
  5. @Override
  6. protected void onCreate(Bundle savedInstanceState) {
  7. super.onCreate(savedInstanceState);
  8.  
  9. mGLSurfaceView = new MySurface(this);//(this); //instantiation
  10.  
  11. ActivityManager actMan = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
  12. ConfigurationInfo mConfigInfo = actMan.getDeviceConfigurationInfo();
  13. boolean isES2Compat = (mConfigInfo.reqGlEsVersion >= 0x20000);
  14. Log.e("oGl-es v",mConfigInfo.getGlEsVersion()+":"+ mConfigInfo.reqGlEsVersion);
  15. if(isES2Compat){
  16.  
  17.  
  18. renderSet = true;
  19. Log.e("render","set");
  20.  
  21. }
  22.  
  23.  
  24. }
  25.  
  26. @Override
  27. public boolean onCreateOptionsMenu(Menu menu) {
  28. // Inflate the menu; this adds items to the action bar if it is present.
  29. getMenuInflater().inflate(R.menu.activity_main__oglt1,menu);
  30. return true;
  31. }
  32.  
  33. @Override
  34. protected void onResume()
  35. {
  36. // The activity must call the GL surface view's onResume() on activity onResume().
  37. super.onResume();
  38. mGLSurfaceView.onResume();
  39. }
  40.  
  41. @Override
  42. protected void onPause()
  43. {
  44. // The activity must call the GL surface view's onPause() on activity onPause().
  45. super.onPause();
  46. mGLSurfaceView.onPause();
  47. }
  48.  
  49. }

MySurface类:

  1. public class MySurface extends GLSurfaceView{
  2.  
  3. public MySurface(Context context) {
  4. super(context);
  5. // TODO Auto-generated constructor stub
  6. setEGLContextClientVersion(2);
  7. setRenderer(new MyTestRenderer(getContext()));
  8. }
  9.  
  10. }

解决方法

问题在于glSurfaceView,因为它不会在OpenGL线程上运行. glSurfaceView应该在主要的android线程上.

在这里你可以找到关于它的更多信息

opengl es api with no current context

OpenGL ES 2.0 Context in Android

希望这个帮助.

猜你在找的Android相关文章