2011-11-07 3 views
0

우선,이 질문에서 비슷한 해결책을 가진 다른 질문이 중복되지 않습니다. 스레드 및 다양한 스레드 문제가 있지만 다양한 스레드를 사용하지 않는, 내 문제가 동일하지 않습니다.ERROR/libEGL (206) : 현재 컨텍스트없이 OpenGL ES API를 호출하십시오.

저는 OpenGL es 1과 Android 1.5가있는 간단한 사각형이 있습니다. 사각형은 화면 중앙에 그려집니다.

사용자가 화면을 누르거나 화면에서 손가락을 움직이면 정사각형이 해당 위치로 이동하기를 원합니다. 이것을 위해 나는 GLuUnProject로 tryed했는데, 나는 손가락으로 터치 한 창 XY 좌표와 일치하는 OpenGL 좌표를 얻으려고 시도했다. (나중에 좌표로 다각형을 변환하기 위해) LogCat에서 좌표를 쓰고있다.

내가 받고있는 좌표는 실제 좌표가 아니며 좌표가 잘못되었습니다. 또한 질문의 오류가 발생합니다. ERROR/libEGL(206): call to OpenGL ES API with no current context

로그 캣 :

11-07 09:43:40.012: DEBUG/XXXXXXXXX(203): X: -1.2918732 
11-07 09:43:40.023: DEBUG/XXXXXXXXX(203): Y: 0.050911963 
11-07 09:43:40.042: ERROR/libEGL(203): call to OpenGL ES API with no current context 
11-07 09:43:40.042: ERROR/libEGL(203): call to OpenGL ES API with no current context 
11-07 09:43:40.042: DEBUG/XXXXXXXXX(203): X: -1.2943747 
11-07 09:43:40.052: DEBUG/XXXXXXXXX(203): Y: 0.04674524 
11-07 09:43:40.152: ERROR/libEGL(203): call to OpenGL ES API with no current context 
11-07 09:43:40.152: ERROR/libEGL(203): call to OpenGL ES API with no current context 
11-07 09:43:40.172: DEBUG/XXXXXXXXX(203): X: 0.77298313 
11-07 09:43:40.182: DEBUG/XXXXXXXXX(203): Y: -0.5083332 
11-07 09:43:40.223: ERROR/libEGL(203): call to OpenGL ES API with no current context 
11-07 09:43:40.223: ERROR/libEGL(203): call to OpenGL ES API with no current context 
11-07 09:43:40.223: DEBUG/XXXXXXXXX(203): X: 0.77298313 
11-07 09:43:40.223: DEBUG/XXXXXXXXX(203): Y: -0.5083332 
11-07 09:43:40.402: ERROR/libEGL(203): call to OpenGL ES API with no current context 
11-07 09:43:40.402: ERROR/libEGL(203): call to OpenGL ES API with no current context 
11-07 09:43:40.402: DEBUG/XXXXXXXXX(203): X: -1.2943747 
11-07 09:43:40.402: DEBUG/XXXXXXXXX(203): Y: 0.04674524 
11-07 09:43:41.952: ERROR/libEGL(203): call to OpenGL ES API with no current context 
11-07 09:43:41.952: ERROR/libEGL(203): call to OpenGL ES API with no current context 
11-07 09:43:41.952: DEBUG/XXXXXXXXX(203): X: 0.77298313 
11-07 09:43:41.952: DEBUG/XXXXXXXXX(203): Y: -0.5083332 
11-07 09:43:42.042: ERROR/libEGL(203): call to OpenGL ES API with no current context 
11-07 09:43:42.042: ERROR/libEGL(203): call to OpenGL ES API with no current context 

내 코드 :

public class MySurfaceView extends GLSurfaceView implements Renderer { 
private float INITIAL_Z = -35.0f; 
private Context context; 
private Square square; 
private float xrot;     //X Rotation 
private float yrot;     //Y Rotation 
private float zrot;     //Z Rotation  
private float z = INITIAL_Z;   //Profundidad en el eje Z 
private float x = 0.0f;    //eje X 
private float y = 0.0f;    //eje Y 

private MatrixGrabber mg = new MatrixGrabber(); //create the matrix grabber object in your initialization code  
private GL10 MyGl; //To make gl variable accesible on all the methods of the class 
byte horizontal=-1; //0: LEFT 1:CENTER 2:RIGHT 
byte vertical=-1; //0: TOP 1:CENTER 2:BOTTOM 
float startX=-1; 
float startY=-1; 
float xMovement=0.0f; 
float yMovement=0.0f; 
private boolean movement_mode=false; 

public MySurfaceView(Context context, Bitmap image, int width, byte horizontal, byte vertical) { 
    super(context); 
    this.context = context; 
    setEGLConfigChooser(8, 8, 8, 8, 16, 0); //fondo transparente 
    getHolder().setFormat(PixelFormat.TRANSLUCENT); //fondo transparente 
    //Transformamos esta clase en renderizadora 
    this.setRenderer(this); 
    //Request focus, para que los botones reaccionen 
    this.requestFocus(); 
    this.setFocusableInTouchMode(true); 
    square = new Square(image); 
    this.horizontal=horizontal; 
    this.vertical=vertical; 
} 

public void onSurfaceCreated(GL10 gl, EGLConfig config) { 
    MyGl=gl; 
    gl.glDisable(GL10.GL_DITHER);    //dithering OFF 
    gl.glEnable(GL10.GL_TEXTURE_2D);   //Texture Mapping ON 
    gl.glShadeModel(GL10.GL_SMOOTH);   //Smooth Shading 
    gl.glClearDepthf(1.0f);      //Depth Buffer Setup 
    gl.glEnable(GL10.GL_DEPTH_TEST);   //Depth Testing ON 
    gl.glDepthFunc(GL10.GL_LEQUAL); 
    gl.glClearColor(0,0,0,0); //fondo transparente 
    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);   
    //Cargamos la textura del cubo. 
    square.loadGLTexture(gl, this.context);  
} 

public void onDrawFrame(GL10 gl) { 
    //Limpiamos pantalla y Depth Buffer 
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); 
    gl.glLoadIdentity(); 
    //Dibujado 
    gl.glTranslatef(x, y, z);   //Move z units into the screen 
    //gl.glScalef(0.8f, 0.8f, 0.8f);   //Escalamos para que quepa en la pantalla 
    //Rotamos sobre los ejes. 
    gl.glRotatef(xrot, 1.0f, 0.0f, 0.0f); //X 
    gl.glRotatef(yrot, 0.0f, 1.0f, 0.0f); //Y 
    gl.glRotatef(zrot, 0.0f, 0.0f, 1.0f); //Z 
    //Dibujamos el cuadrado 
    square.draw(gl);  
} 

//si el surface cambia, resetea la vista, imagino que esto pasa cuando cambias de modo portrait/landscape o sacas el teclado físico en móviles tipo Droid. 
public void onSurfaceChanged(GL10 gl, int width, int height) { 
    if(height == 0) {      
     height = 1;       
    } 
    gl.glViewport(0, 0, width, height);  //Reset Viewport 
    gl.glMatrixMode(GL10.GL_PROJECTION); //Select Projection Matrix 
    gl.glLoadIdentity();     //Reset Projection Matrix 
    //Aspect Ratio de la ventana 
    GLU.gluPerspective(gl, 45.0f, (float)width/(float)height, 0.1f, 100.0f); 
    gl.glMatrixMode(GL10.GL_MODELVIEW);  //Select Modelview Matrix 
    gl.glLoadIdentity();     //Reset Modelview Matrix 
} 

public boolean onTouchEvent(MotionEvent event) { 
    float [] outputCoords=getOpenGLCoords(event.getX(), event.getY(), 0); 
    x=(outputCoords[0]/outputCoords[3]); 
    y=(outputCoords[1]/outputCoords[3]); 
    //z=outputCoords[2]/outputCoords[3]; 
    Log.d("XXXXXXXXX", "X: "+x); 
    Log.d("XXXXXXXXX", "Y: "+y);   
    return true; //El evento ha sido manejado 
} 

public float[] getOpenGLCoords(float xWin,float yWin,float zWin) 
{ 
    int screenW=SectionManager.instance.getDisplayWidth(); 
    int screenH=SectionManager.instance.getDisplayHeight(); 
    //CODE FOR TRANSLATING FROM SCREEN COORDINATES TO OPENGL COORDINATES 
    mg.getCurrentProjection(MyGl); 
    mg.getCurrentModelView(MyGl); 
    float [] modelMatrix = new float[16]; 
    float [] projMatrix = new float[16]; 
    modelMatrix=mg.mModelView; 
    projMatrix=mg.mProjection;   
    int [] mView = new int[4]; 
    mView[0] = 0; 
    mView[1] = 0; 
    mView[2] = screenW; //width 
    mView[3] = screenH; //height 
    float [] outputCoords = new float[4]; 
    GLU.gluUnProject(xWin, ((float)screenH)-yWin, zWin, modelMatrix, 0, projMatrix, 0, mView, 0, outputCoords, 0); 
    return outputCoords; 
} 
} 

답변

2

확인이 두 라인 :

mg.getCurrentProjection(MyGl); 
mg.getCurrentModelView(MyGl); 

되어있는 동안 그들은 주 스레드에서 호출이 렌더링에 호출 될 하나. OpenGL 콜백 (예 : gl 변수가 이미있는 onDrawFrame(GL10 gl))에서만 유효하기 때문에 MyGl 속성을 저장할 필요가 없습니다. 프레임의 그리기 때마다 yhe 클래스의 투영 및 모델 뷰 행렬 속성을 만들어 업데이트해야합니다 (gluUnProject를 계산할 필요가있을 때 사용하십시오.)

+0

true, 오류는 사라졌지만 지금은 점점 줄어들고 있습니다. g 또 다른 문제는 X와 Y에 주어진 값이 실제 값이 아니며, 예를 들어 화면의 임의의 영역을 누르는 것과 같은 잘못된 값입니다 : X : 0.0064407806 Y : -0.0072252387, 항상 그런 값 .... 문제는 내가 gluUnProject에 대한 winZ 값으로 0을 전달하고 있다고 생각하지만 winZ 값으로 전달해야하는 것을 알지 못합니다. S – NullPointerException

+0

이는 투영 및 모델 뷰 행렬을 업데이트해야하기 때문입니다. – Max

+0

다음 두 줄을 사용하여 onDrawFrame 메서드에서 해당 객체를 updathing합니다. mg.getCurrentProjection (gl); \t \t mg.getCurrentModelView (gl); – NullPointerException

0

렌더러 구현에서 onSurfaceCreated(), onSurfaceChanged() 및 onDrawFrame()의 매개 변수로 사용중인 GL10 인스턴스를 사용하고있을 가능성이 있습니다. OpenGL ES 2.0을 사용하려는 경우 인스턴스를 대신 사용할 수도 있고 대신 인스턴스를 사용할 수도 있습니다. 대안이 있습니다! 이것으로 인해 해당 매개 변수 이름과 사용되지 않거나 유사한 코드가 네트워크를 통해 보입니다!