Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 凯文·博洛塔勒OpenGL ES 2教程代码错误?_Java_Android_Opengl Es 2.0 - Fatal编程技术网

Java 凯文·博洛塔勒OpenGL ES 2教程代码错误?

Java 凯文·博洛塔勒OpenGL ES 2教程代码错误?,java,android,opengl-es-2.0,Java,Android,Opengl Es 2.0,我得到了凯文·博洛塔勒的“Android实用OpenGL ES 2”。我刚开始阅读和做教程 在第四章关于添加颜色和阴影的教程之前,一切都很好 所以第三章的代码是(有很多东西,所以我添加了一个链接)。 一切都很好 在第四章中,我们改变了这些东西的绘制方式,改变了着色器 这里只有黑屏,没有这么好的图片 首先,我们更改了着色器 顶点着色器 attribute vec4 a_Position; attribute vec4 a_Color; varying vec4 v_Color; void ma

我得到了凯文·博洛塔勒的“Android实用OpenGL ES 2”。我刚开始阅读和做教程

在第四章关于添加颜色和阴影的教程之前,一切都很好

所以第三章的代码是(有很多东西,所以我添加了一个链接)。 一切都很好

在第四章中,我们改变了这些东西的绘制方式,改变了着色器

这里只有黑屏,没有这么好的图片

首先,我们更改了着色器

顶点着色器

attribute vec4 a_Position;

attribute vec4 a_Color;
varying vec4 v_Color;
void main()
{
    v_Color = a_Color;

    gl_Position = a_Position;
    gl_PointSize = 10.0;
}
帧着色器

precision mediump float;
varying vec4 v_Color;

void main(){
     gl_FragColor = v_Color;
}
此外,我们在Render类中添加了新内容,并删除了一些内容

变数

private static final int POSITION_COMPONENT_COUNT=2;
private static final int BYTES_PER_FLOAT=4;
private static final String A_COLOR="a_Color";
private static final int COLOR_COMPONENT_COUNT=3;
private static final int STRIDE = (POSITION_COMPONENT_COUNT+COLOR_COMPONENT_COUNT)*BYTES_PER_FLOAT;

private int aColorLocation;
以这种方式更改方法(以前的情况)

怎么了?为什么会有黑屏?也许我错过了什么

完全回购是

UPD: 我实际上运行代码

UPD2:

正如Reto Koradi所注意到的,我忘记添加
GlenableVertexAttributeArray(aPositionLocation)在代码中。
我添加了它,现在有一个白色像素的黑屏

UPD3:

UPD4: 输出错误

[2014-08-21 18:17:00-模拟器] sdk/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp:glAttachShader:156 错误0x501[2014-08-21 18:17:00-仿真器] sdk/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp:glValidateProgram:1931 错误0x501[2014-08-21 18:17:00-仿真器] sdk/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp:glGetProgramiv:1148 错误0x501[2014-08-21 18:17:00-仿真器] sdk/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp:glGetProgramiv:1148 错误0x501[2014-08-21 18:17:00-仿真器] sdk/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp:glGetAttriblation:825 错误0x501[2014-08-21 18:17:00-仿真器] sdk/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp:glGetAttriblation:825 错误0x501


我看到缺少的唯一一件事是,代码从未启用“位置顶点”属性。此调用应位于
onSurfaceCreated()
中,其中设置了顶点属性:

glEnableVertexAttribArray(aPositionLocation);

移动
GlenableVertexAttributeArray(颜色定位)位于
glvertexattributepointer(颜色位置、颜色分量计数、GL浮动、,
假、步幅、顶点数据)
并将其替换为
OnSurfaceCreate中的
GlenableVertexAttributeArray(aPositionLocation)

这是如下所示

vertexData.position(0);
        glVertexAttribPointer(aPositionLocation,POSITION_COMPONENT_COUNT,GL_FLOAT,false,STRIDE,vertexData);
        glEnableVertexAttribArray(aPositionLocation);

        vertexData.position(POSITION_COMPONENT_COUNT);
        glVertexAttribPointer(aColorLocation,COLOR_COMPONENT_COUNT,GL_FLOAT,false,STRIDE,vertexData);
        glEnableVertexAttribArray(aColorLocation);

链接回购协议中的代码看起来与您在此处发布的代码不同。所以不清楚你到底在跑什么。我注意到,repo中的代码请求一个带有深度缓冲区的配置,但您没有清除深度缓冲区。尝试将clear调用更改为
glClear(GL\u COLOR\u BUFFER\u BIT | GL\u DEPTH\u BUFFER\u BIT)
@RetoKoradi I在正常工作时链接到版本。但这是不同的绘画和着色方式stuff@RetoKoradiglClear没有任何变化你在实际设备上而不是在模拟器上试过吗?@Zhuinden我买了飞利浦w3568,所以yepwell,我现在加了它黑屏上只有白点:3
vertexData.position(0);
        glVertexAttribPointer(aPositionLocation,POSITION_COMPONENT_COUNT,GL_FLOAT,false,STRIDE,vertexData);
        glEnableVertexAttribArray(aPositionLocation);

        vertexData.position(POSITION_COMPONENT_COUNT);
        glVertexAttribPointer(aColorLocation,COLOR_COMPONENT_COUNT,GL_FLOAT,false,STRIDE,vertexData);
        glEnableVertexAttribArray(aColorLocation);