버텍스 속성을 실행중인 쉐이더 프로그램에 전달할 때 문제가 있습니다. 위치와 RGBA 색상이라는 두 가지 속성을 전달하고 싶습니다. 속성 위치 바인딩은 해당 위치에서 작동합니다. 그러나 색상에 대해서는 작동하지 않습니다. 따라서 모든 지오메트리는 결국 검정색으로 렌더링됩니다.GLSL 1.5 및 OpenGL 3.3 : 버텍스 쉐이더로 색상 전달이 실패한 것 같습니다.
이 내가 할 것입니다 :
GLuint programHandler;
// create program
// compile & attach vertex shader
// compile & attach fragment shader
glBindAttribLocation(programHandler, 0, "InPosition");
glBindAttribLocation(programHandler, 1, "InColor");
glBindFragDataLocation(programHandler, 1, "FragColor");
glLinkProgram(programHandler);
glUseProgram(programHandler);
// initialize uniform variables
// I'm trying to get the attribute locations now.
// I expect location "0" for InPosition and location "1" for InColor.
// In fact, it gets me a "-1" for InColor. I simply cannot see the reason for that behaviour
GLint positionLocation = glGetAttribLocation(programHandler, "InPosition"); // returns 0
GLint colorLocation = glGetAttribLocation(programHandler, "InColor"); // returns -1
glEnableVertexAttribArray(positionLocation);
glEnableVertexAttribArray(colorLocation); // fails!
내 버텍스 쉐이더는 아주 기본적인 것입니다.
#version 150 core
precision highp float;
// input
in vec4 PassColor;
// output
out vec4 FragColor;
void main(void) {
FragColor = PassColor;
}
이유는 무엇입니까 바인딩 "포지션"작업과 "InColor"
이#version 150 core
// input
uniform mat4 ModelviewMatrix;
uniform mat4 ProjectionMatrix;
in vec3 InPosition;
in vec4 InColor;
// output
out vec4 PassColor;
void main(void) {
// passing color through to fragment shader
PassColor = InColor;
// transformation
gl_Position = ProjectionMatrix * ModelviewMatrix * vec4(InPosition, 1.0);
}
내 조각 쉐이더가 단순히 색을 반환해야합니다 : 난 정말 할 모든 정점을 변환하고, 프레 그먼트 쉐이더에 색상을 전달입니다 하지 않습니다? GLSL 컴파일러가 쉐이더 코드를 최적화하여 사용하지 않는 변수를 바인딩 할 수 없다는 것을 알고 있습니다. 하지만 왜 여기에 색상을 최적화해야하는지 모르겠습니다. 결국, 조각 쉐이더로 전달하여 사용합니다.
'glGetError()'가 있습니까? 또한 GPU와 드라이버 버전은 무엇입니까? – Kos