1
我正在繪製(我想繪製)視圖中間的一個點,我在AVD(Nexus 4,Android 4.4.2 - API級別19,Intel Atom(x86), RAM 768,使用主機GPU),但是我在使用真實設備[Nexus 5,Nexus 7(2012版)]繪製時遇到了問題。在真實的設備上,只有空白(清晰的顏色)視圖,中間沒有點。繪圖GL_POINTS
下面是一個完整的代碼。這相對簡單。注意我也嘗試了glVertexAttribPointer(glEnableVertexAttribArray)推送點數據(位置)。
你能幫我解決這個問題嗎?
package com.example.point.app;
import android.app.Activity;
import android.content.Context;
import android.opengl.GLES20;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new PointView(this));
}
class PointView extends GLSurfaceView {
public PointView(Context context) {
super(context);
setEGLContextClientVersion(2);
setEGLConfigChooser(8, 8, 8, 8, 16, 0);
setRenderer(new PointRenderer());
}
class PointRenderer implements Renderer {
private void checkError(String message) {
int err = GLES20.glGetError();
if (err != GLES20.GL_NO_ERROR) {
throw new RuntimeException(message + " -> " + err);
}
}
private int createShader(int type, String source) {
int shader = GLES20.glCreateShader(type);
GLES20.glShaderSource(shader, source);
checkError("glShaderSource");
GLES20.glCompileShader(shader);
checkError("glCompileShader");
return shader;
}
@Override
public void onSurfaceCreated(GL10 unused, EGLConfig config) {
int vertex = createShader(GLES20.GL_VERTEX_SHADER, "" +
"void main() {" +
" gl_Position = vec4(0, 0, 0, 1);" +
" gl_PointSize = 100;" +
"}");
int fragment = createShader(GLES20.GL_FRAGMENT_SHADER, "" +
"precision mediump float;" +
"void main() {" +
" gl_FragColor = vec4(1, 0, 1, 1);" +
"}");
program = GLES20.glCreateProgram();
checkError("glCreateProgram");
GLES20.glAttachShader(program, vertex);
checkError("glAttachShader(vertex)");
GLES20.glAttachShader(program, fragment);
checkError("glAttachShader(fragment)");
GLES20.glLinkProgram(program);
checkError("glLinkProgram");
}
@Override
public void onSurfaceChanged(GL10 unused, int width, int height) {
}
@Override
public void onDrawFrame(GL10 unused) {
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
GLES20.glUseProgram(program);
GLES20.glDrawArrays(GLES20.GL_POINTS, 0, 1);
}
private int program;
}
}
}