2011-01-07 2 views
1

다음 코드를 작성하여 android에서 GLview를 초기화했습니다. 나는 상대적으로 안드로이드 애플리케이션 개발에 새로운 편이다. 화면 캡처를위한 코드를 사용하고 싶습니다. 여기 문제 android에서 GLview 초기화

내가 작성한 코드의 조각 :

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.getGL(); 




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


    } 

그러나 응용 프로그램은

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

이 문제를 해결하시기 바랍니다 예외를주고있다

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

에 종료됩니다 .

감사합니다.

답변

1

GLSurfaceView 클래스를 사용하면 OpenGL을 쉽게 사용할 수 있습니다. 자습서가 있습니다 here

+1

제안 해 주셔서 감사합니다. 정말 도움이됩니다. 하지만 여전히 GLSurface.Renderer 인터페이스를 사용하여 코드를 작성하는 방법을 파악하는 데 문제가 있습니다. 당신이 나를 도와 줄 수 있다면 그것은 당신의 큰 도움이 될 것입니다. – ujjawal