La línea de dibujo de OpenGL ES 2.0 basada en movimiento, Line comienza siempre en origen

Acabo de comenzar a aprender OpenGL para Android y estoy teniendo un problema extraño al dibujar líneas. Todo lo que quiero hacer es dibujar una línea basada en un movimiento de dedo. Ahora, tan pronto como empiezo a golpear siempre obtengo una línea siguiendo mi movimiento desde el origen (0,0).

aquí una foto:

http://imageshack.us/photo/my-images/137/screenshot2012061312174.jpg/

Los símbolos de flecha mi movimiento del dedo y la línea que comienza en el origen (círculo rojo) es la línea mencionada folowing mi movimiento entero.

No se moleste con la matriz de Coords Sé que esto no es la mejor práctica, pero debuged el programa entero y no podría finde cualquier error que involucra esta matriz.

Probablemente debo mencionar que los puntos ArrayList contiene todos mis puntos generados.

Estoy tratando de averiguar esto para dejar de fumar un tiempo ahora, pero estoy realmente atrapado cualquier sugerencia podría ser útil

Esta es toda mi clase de render.

clase pública HelloOpenGLES20Renderer implementa GLSurfaceView.Renderer {

private FloatBuffer triangleVB; private int mProgram; private int maPositionHandle; public ArrayList<PointWrapper> points; private int muMVPMatrixHandle; private float[] mMVPMatrix = new float[16]; private float[] mMMatrix = new float[16]; private float[] mVMatrix = new float[16]; private float[] mProjMatrix = new float[16]; private int[] viewport = new int[4]; private ArrayList<Float> coordinates; float[] Coords = new float[100000]; boolean first; private int counter; private PointWrapper last; private final String vertexShaderCode = // This matrix member variable provides a hook to manipulate // the coordinates of the objects that use this vertex shader "uniform mat4 uMVPMatrix; \n" + "attribute vec4 vPosition; \n" + "void main(){ \n" + // the matrix must be included as a modifier of gl_Position " gl_Position = uMVPMatrix * vPosition; \n" + "} \n"; private final String fragmentShaderCode = "precision mediump float; \n" + "void main(){ \n" + " gl_FragColor = vec4 (0.63671875, 0.76953125, 0.22265625, 1.0); \n" + "} \n"; private int loadShader(int type, String shaderCode) { // create a vertex shader type (GLES20.GL_VERTEX_SHADER) // or a fragment shader type (GLES20.GL_FRAGMENT_SHADER) int shader = GLES20.glCreateShader(type); // add the source code to the shader and compile it GLES20.glShaderSource(shader, shaderCode); GLES20.glCompileShader(shader); return shader; } public HelloOpenGLES20Renderer() { points = new ArrayList<PointWrapper>(); first = true; this.counter = 0; last = new PointWrapper(); coordinates = new ArrayList<Float>(); } private float[] convertCoordinates(PointWrapper f) { float[] vector = new float[4]; GLU.gluUnProject(f.point.x, f.point.y, 0.0f, mVMatrix, 0, mProjMatrix, 0, viewport, 0, vector, 0); return vector; } private void initShapes() { ArrayList<PointWrapper> points2 = new ArrayList<PointWrapper>(points); float[] vector; if (!points2.isEmpty()) { if(points2.size()%2==1){ points2.remove(points2.size()-1); } for (int i = counter/2; i < points2.size(); i++) { vector = convertCoordinates(points2.get(i)); Coords[counter] = vector[0] / vector[3]; Coords[counter+1] = -1 * (vector[1] / vector[3]); counter= counter+2; } } // initialize vertex Buffer for triangle ByteBuffer vbb = ByteBuffer.allocateDirect( // (# of coordinate values * 4 bytes per float) Coords.length * 4); vbb.order(ByteOrder.nativeOrder());// use the device hardware's native // byte order triangleVB = vbb.asFloatBuffer(); // create a floating point buffer from // the ByteBuffer triangleVB.put(Coords); // add the coordinates to the // FloatBuffer triangleVB.position(0); // set the buffer to read the first coordinate } public void onSurfaceCreated(GL10 unused, EGLConfig config) { // Set the background frame color GLES20.glClearColor(0.5f, 0.5f, 0.5f, 1.0f); // initialize the triangle vertex array // initShapes(); int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode); int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode); mProgram = GLES20.glCreateProgram(); // create empty OpenGL Program GLES20.glAttachShader(mProgram, vertexShader); // add the vertex shader // to program GLES20.glAttachShader(mProgram, fragmentShader); // add the fragment // shader to program GLES20.glLinkProgram(mProgram); // creates OpenGL program executables // get handle to the vertex shader's vPosition member maPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition"); } public void onDrawFrame(GL10 unused) { // Redraw background color GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); initShapes(); // Add program to OpenGL environment GLES20.glUseProgram(mProgram); // Prepare the triangle data GLES20.glVertexAttribPointer(maPositionHandle, 2, GLES20.GL_FLOAT, false, 0, triangleVB); GLES20.glEnableVertexAttribArray(maPositionHandle); // Apply a ModelView Projection transformation Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0); GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0); GLES20.glLineWidth(5f); GLES20.glDrawArrays(GLES20.GL_LINE_STRIP, 0, counter); } public void onSurfaceChanged(GL10 unused, int width, int height) { GLES20.glViewport(0, 0, width, height); float ratio = (float) width / height; viewport[0] = 0; viewport[1] = 0; viewport[2] = width; viewport[3] = height; // this projection matrix is applied to object coodinates // in the onDrawFrame() method Matrix.frustumM(mProjMatrix, 0, -ratio, ratio, -1, 1, 3, 7); muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix"); Matrix.setLookAtM(mVMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f); } 

}

gracias de antemano

 for (int i = counter/2; i < points2.size(); i++) { vector = convertCoordinates(points2.get(i)); Coords[counter] = vector[0] / vector[3]; Coords[counter+1] = -1 * (vector[1] / vector[3]); counter= counter+2; } 

Usted ha intialized Coords para mantener 100000 floats y los inicializa a 0. En este bucle la última iteración tiene 'counter' con el número de flotadores que ha establecido en su matriz.

Lo que pasa a glDrawArrays debe ser el número de VERTICES a dibujar. por lo que en este caso la mitad de 'contador'.

 GLES20.glDrawArrays(GLES20.GL_LINE_STRIP, 0, counter); 

Tu bucle for está añadiendo 'counter' / 2 cantidad extra de (0,0) vértices al final de tu array. la solución más rápida sería pasar "counter" / 2 a glDrawArrays pero sugeriría un enfoque más claro.

 numOfVertices = points2.size(); //make field int counter = 0; //make local for (int i = 0; i < numOfVertices; i++) { vector = convertCoordinates(points2.get(i)); Coords[counter] = vector[0] / vector[3]; Coords[counter+1] = -1 * (vector[1] / vector[3]); counter= counter+2; } 

y entonces

 GLES20.glDrawArrays(GLES20.GL_LINE_STRIP, 0, numOfVertices); 
  • Recubrimiento opengl en vista de cámara
  • ¿Cómo manejar la limitación de memoria de la GPU para el procesamiento de imágenes de alta resolución en la GPU?
  • Solución para escribir el valor del búfer de profundidad / profundidad en OpenGL ES 2.0
  • Opengl es 2.0 dibujar superposición de mapa de bits en vídeo
  • EglCreateWindowSurface falla con java.lang.IllegalArgumentException
  • Qué superficie utilizar para eglMakeCurrent para el contexto que sólo se convierte en FBOs
  • Multiplicación apropiada de matrices para rotación / traducción
  • La textura de OpenGL no sigue la geometría
  • GlCreateShader y glCreateProgram fallan en android
  • Problema de detección de colisiones basado en píxeles con OpenGLES 2.0 bajo Android
  • No se pueden dibujar vértices con el eje Z en la pantalla
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.