开发者

problem Initializing the GLview in android

I have written the following code to initialize the GLview in android. I am relatively new to android application development. I want to use the code for getting the screen capture.

Here is the piece of code I have written:

public class MainActivity extends Activity{

    /** Called when the activity is first created. */

    private EGL10 egl;
    private EGLDisplay display;
    private EGLConfig config;
    Display disp ;
    private EGLContext eglContext;
    private GL10 gl ;
    private EGLSurface surface;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        // ToDo add your GUI initialization code here        
    setContentView(R.layout.main);

    disp = getWindowManager().getDefaultDisplay();

    egl = (EGL10) EGLContext.getEGL();
   display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
   int[] ver = new int[2];
   egl.eglInitialize(display, ver);
    int[] configSpec = {EGL10.EGL_NONE};
    EGLConfig[] configOut = new EGLConfig[1];
    int[] nConfig = new int[1];
    egl.eglChooseConfig(display, configSpec, configOut, 1, nConfig);
    config = configOut[0];
    eglContext = egl.eglCreateContext(display, config, EGL10.EGL_NO_CONTEXT, null);

    SurfaceView view = new SurfaceView(this);
    setContentView(view); 

      SurfaceHolder holder = view.getHolder();
      holder.setType(SurfaceHolder.SURFACE_TYPE_NORMAL);
      try{
            surface = egl.eglCreateWindowSurface(display,config, holder , null);
      }catch(Exception e)
      {
          e.printStackTrace();
      }
    egl.eglMakeCurrent(display, surface, surface, eglContext);
    gl = (GL10) eglContext.g开发者_运维技巧etGL();




    savePNG(0,0,disp.getWidth(), disp.getHeight(),"testpicture.png",gl);


    }

But the application is terminating at

      try{
            surface = egl.eglCreateWindowSurface(display,config, holder , null);
      }catch(Exception e)
      {
          e.printStackTrace();
      }

It is giving the exception

 IlligalArgument exception: Must use SurfaceHolder or SurfaceView  with proper format. not a valid surface.

please rectify this problem.

Thank you.


The GLSurfaceView class provides an easy way to use OpenGL. There's a tutorial here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜