我通过freeglut取得了成功 我如何通过glfw初始化它? 这是OpenGL4.0之后的新功能。 这是我的初始化代码
在glfwInit()之后:
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE,GLFW_OPENGL_CORE_PROFILE);
glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
这是我的一些着色器代码:
subroutine vec4 ShaderVertType();
subroutine uniform ShaderVertType DotModel;
subroutine(ShaderVertType)
vec4 ShaderForOBJ_Solid()
{
model_position = vec3(model_matrix*vPosition);
//vec4 trans_pos = normalize(vPosition)*0.5+0.5;
v_flight_space_pos = light_space_matrix*vec4(model_position,1.0f);
normal_trans_matrix = transpose(inverse(model_matrix));
//mat4 trans_matrix = projection_matrix*view_matrix;
T = normalize(vec3(normal_trans_matrix*vec4(vTangent,1.0f)));
//B = normalize(normal_trans3*vBiTangent);
N = normalize(vec3(normal_trans_matrix*vec4(vNormal,1.0f)));
B = normalize(vec3(normal_trans_matrix*vec4(vBiTangent,1.0f)));
//T = normalize(-dot(N,T)*N);
//B = cross(T,N);
f_vNormal = normalize(vec3(normal_trans_matrix*vec4(vNormal,1.0f))); //normalize(vec3( inverse(transpose((model_matrix)))*normalize(texture(NormalMapData,trans_pos.xy).rgba)));
vec4 final_pos = projection_matrix*(view_matrix*(model_matrix*vPosition));
return final_pos;
}
它可以返回一个非负数,但在设置时不起作用
glUseProgram(shaderManager->GetProgramHandle("mainShader"));
GLuint frag_index = glGetSubroutineIndex(CURRENT_PROGRAM, GL_FRAGMENT_SHADER, "ShaderForOnlyTex");
GLuint ver_index = glGetSubroutineIndex(CURRENT_PROGRAM, GL_VERTEX_SHADER, "ShaderForOBJ_Solid");
不行:
glUniformSubroutinesuiv(GL_VERTEX_SHADER, 1, &frag_index);
glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 1, &ver_index);