gpt4 book ai didi

android - 绘图 GL_POINTS

转载 作者:搜寻专家 更新时间:2023-11-01 07:59:00 25 4
gpt4 key购买 nike

我正在 View 中间绘制(我想绘制)一个点,我在 AVD(Nexus 4、Android 4.4.2 - API 级别 19、Intel Atom (x86)、RAM 768 ,使用主机 GPU),但我在真实设备 [Nexus 5、Nexus 7(2012 版)] 上绘制时遇到问题。在真实设备上只有空白(清晰的颜色) View ,中间没有任何点。

这是完整的代码。比较简单。请注意,我还尝试通过 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;

}

}

}

最佳答案

我读取错误并使用了 float

"gl_PointSize = 100;" -> "gl_PointSize = 100.0;"

此更改后,我看到了预期的结果。

关于android - 绘图 GL_POINTS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24055683/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com