2013-09-06 4 views
0

onTouchEvent()에 의해 트리거 된 애니메이션과 같은 커튼을 만듭니다. 여기에서 사각형의 한쪽 끝을 드래그하여 더 크게 또는 더 작게 만들 수 있습니다. 내 유일한 문제는 전체 화면에 사각형이있는 대신 화면 상단에 작은 선이 생기고 그 선을 확장하거나 축소 할 수 있다는 것입니다. 왜이 코드는 사각형을 그리지 않습니까?OpenGl 드래그 스퀘어

public void onSurfaceChanged(GL10 gl, int width, int height) { 
    gl.glViewport(0, 0, width, height); 
    float ratio = (float) width/height; 
    gl.glMatrixMode(GL10.GL_PROJECTION);  // set matrix to projection mode 
    gl.glLoadIdentity();      // reset the matrix to its default state  
    gl.glOrthof(0, height, width, 0, -3, 8); 

} 

정점 :

private float vertices[] = { 
      -1.0f, 1.0f, 0.0f, // 0, Top Left 
      -1.0f, -1.0f, 0.0f, // 1, Bottom Left 
      1.0f, -1.0f, 0.0f, // 2, Bottom Right 
      1.0f, 1.0f, 0.0f, // 3, Top Right 

}; 

// The order we like to connect them. 
private short[] indices = { 0, 1, 2, 0, 2, 3 }; 

그리고 광장에서 그리기 방법 :

public void draw(GL10 gl,float x,float y) { 
    // Counter-clockwise winding. 
    gl.glFrontFace(GL10.GL_CCW); // OpenGL docs 
    //Point to our vertex buffer 
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer); 
    //Enable vertex buffer 
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); 
    gl.glDrawElements(GL10.GL_TRIANGLES, indices.length, GL10.GL_UNSIGNED_SHORT, indexBuffer); 
    //Draw the vertices as triangle strip 
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length/3); 
    //Disable the client state before leaving 
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); 

} 

답변

1

당신이 누락? 투사 모드를 설정 한 후.

gl.glMatrixMode(GL10.GL_MODELVIEW);  // set modelview matrix to identity. 
gl.glLoadIdentity(); 
+0

아니요. – JY2k

+0

당신은 gl.glFrontFace (GL10.GL_CCW)를 없앨 수 있습니까? // OpenGL 문서 – GizmoThunder