抱歉我的语言(不是我的母语,我只是在学习)
Okey,我在演示游戏中遇到黑底问题 当我为天空放置不同的纹理(我制作了“天空盒”)时,背景仍然是黑色
我意识到这是由于以下原因:
normalAttribute = glGetAttribLocationARB(program, "aNormal");
glEnableVertexAttribArrayARB(normalAttribute);
但是当我尝试删除她或更改glDisableVertexAttribArrayARB时-我得到以下信息:
如果不删除(但背景为黑色)
我的加载程序方法:
static int createShader(String resource, int type) throws IOException {
int shader = glCreateShaderObjectARB(type);
ByteBuffer source = ioResourceToByteBuffer(resource, 1024);
PointerBuffer strings = BufferUtils.createPointerBuffer(1);
IntBuffer lengths = BufferUtils.createIntBuffer(1);
strings.put(0, source);
lengths.put(0, source.remaining());
glShaderSourceARB(shader, strings, lengths);
glCompileShaderARB(shader);
int compiled = glGetObjectParameteriARB(shader, GL_OBJECT_COMPILE_STATUS_ARB);
String shaderLog = glGetInfoLogARB(shader);
if (shaderLog.trim().length() > 0) {
System.err.println(shaderLog);
}
if (compiled == 0) {
throw new AssertionError("Could not compile shader");
}
return shader;
}
void createProgram() throws IOException {
program = glCreateProgramObjectARB();
int vertexShader = createShader("org/lwjgl/demo/opengl/assimp/magnet.vs",
GL_VERTEX_SHADER_ARB);
int fragmentShader = createShader("org/lwjgl/demo/opengl/assimp/magnet.fs",
GL_FRAGMENT_SHADER_ARB);
glAttachObjectARB(program, vertexShader);
glAttachObjectARB(program, fragmentShader);
glLinkProgramARB(program);
int linkStatus = glGetObjectParameteriARB(program, GL_OBJECT_LINK_STATUS_ARB);
String programLog = glGetInfoLogARB(program);
if (programLog.trim().length() > 0) {
System.err.println(programLog);
}
if (linkStatus == 0) {
throw new AssertionError("Could not link program");
}
glUseProgramObjectARB(program);
vertexAttribute = glGetAttribLocationARB(program, "aVertex");
glEnableVertexAttribArrayARB(vertexAttribute);
normalAttribute = glGetAttribLocationARB(program, "aNormal");
glEnableVertexAttribArrayARB(normalAttribute);
modelMatrixUniform = glGetUniformLocationARB(program, "uModelMatrix");
viewProjectionMatrixUniform = glGetUniformLocationARB(program, "uViewProjectionMatrix");
normalMatrixUniform = glGetUniformLocationARB(program, "uNormalMatrix");
lightPositionUniform = glGetUniformLocationARB(program, "uLightPosition");
viewPositionUniform = glGetUniformLocationARB(program, "uViewPosition");
ambientColorUniform = glGetUniformLocationARB(program, "uAmbientColor");
diffuseColorUniform = glGetUniformLocationARB(program, "uDiffuseColor");
specularColorUniform = glGetUniformLocationARB(program, "uSpecularColor");
}
我使用它的代码(+使用SkyBox的代码):
对于那些不完全理解问题本质的人: 当我添加一个新程序(在本例中为天空盒)时,背景仍然为黑色。如果删除此行 glEnableVertexAttribArrayARB(normalAttribute),将出现天空,但模型的阴影将消失。
请,我寻求帮助,一个星期都找不到解决方案。