Reputation: 2209
Im trying to display some points on the screen with opengl es. here is the code of ondraw:
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glColor4f(0, 255, 0, 0);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, buffer);
gl.glDrawArrays(GL10.GL_POINTS, 0, points.length);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
Can someone tell me what I'm doing wrong???
EDIT: the code to generate the buffer and points
points = new float[12288];
int pos = 0;
for (float y = 0; y < 64; y++) {
for (float x = 0; x < 64; x++) {
points[pos++] = x/100;
points[pos++] = y/100;
points[pos++] = 0;
}
}
ByteBuffer vertexByteBuffer = ByteBuffer.allocateDirect(points.length * 4);
vertexByteBuffer.order(ByteOrder.nativeOrder());
// allocates the memory from the byte buffer
buffer = vertexByteBuffer.asFloatBuffer();
// fill the vertexBuffer with the vertices
buffer.put(points);
// set the cursor position to the beginning of the buffer
buffer.position(0);
and the error at logcat:
04-17 06:38:11.296: A/libc(24276): Fatal signal 11 (SIGSEGV) at 0x41719000 (code=2)
This error happens at gl.glDrawArrays
Upvotes: 3
Views: 3780
Reputation: 35923
I believe this is the problem:
gl.glDrawArrays(GL10.GL_POINTS, 0, points.length);
glDrawArrays
takes the number of vertices that you want to draw. You are giving it the number of floats, which is 3x too big. Therefore opengl is actually attempting to read 12288 vertices = 36,xxx floats from your points array, which way exceeds the bounds of your array.
Upvotes: 2
Reputation: 13477
Problem: You have not called glBindBuffer but you then called glDrawArrays; this will cause a segfault.
I had the same problem when I tried to use an IBO buffer without first binding the buffer using the glBindBuffer command. For example, one of my draw functions looks like this:
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, common.vbo);
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, common.ibo);
GLES20.glVertexAttribPointer(handleManager.switchPosition, 2, GLES20.GL_FLOAT, false, 0, 0);
GLES20.glEnableVertexAttribArray(handleManager.switchPosition);
GLES20.glDrawElements(GLES20.GL_TRIANGLES, common.iboPointCount, GLES20.GL_UNSIGNED_BYTE, 0);
GLES20.glDisableVertexAttribArray(handleManager.switchPosition);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
All of the glBindBuffer commands make it possible to operate on the attribute data that you are trying to get the shader to recognise.
Upvotes: 0