OpenGL错误C0000编译错误 [英] Opengl error C0000 compiling error
本文介绍了OpenGL错误C0000编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对opengl着色器编译有问题.问题是,当我运行程序时,出现此错误:
I've a problem with opengl shader compiling. The problem is that when I run the program, I obtain this error:
顶点信息
0(1):错误c0000:语法错误,令牌''
相同的消息用于片段对象.最后,我得到一个程序未验证"错误.这是我的初始化着色器代码:
the same message is for the fragment object. At the end I obtain a 'program not validated' error. here's my initialization shader code:
struct ShadeState {
int gl_program_id = 0; // OpenGL program handle
int gl_vertex_shader_id = 0; // OpenGL vertex shader handle
int gl_fragment_shader_id = 0; // OpenGL fragment shader handle
};
// initialize the shaders
void init_shaders(ShadeState* state) {
// load shader code from files
auto vertex_shader_code = load_text_file("shade_vertex.glsl");
auto fragment_shader_code = load_text_file("shade_fragment.glsl");
auto vertex_shader_codes = (char *)vertex_shader_code.c_str();
auto fragment_shader_codes = (char *)fragment_shader_code.c_str();
//devono essere costanti altrimenti glShaderSource non li accetta
//auto vertex_codes = (const GLchar*)vertex_shader_codes;
//auto fragment_codes = (const GLchar*)fragment_shader_codes;
//GLint const vert_size = vertex_shader_code.size();
//GLint const frag_size = fragment_shader_code.size();
// create shaders
state->gl_vertex_shader_id = glCreateShader(GL_VERTEX_SHADER); //come da documentazione
state->gl_fragment_shader_id = glCreateShader(GL_FRAGMENT_SHADER); //come da documentazione
// load shaders code onto the GPU
//glShaderCode non esiste!
glShaderSource(state->gl_vertex_shader_id, 1, (const GLchar**)&vertex_shader_codes, NULL);
glShaderSource(state->gl_fragment_shader_id, 1, (const GLchar**)&fragment_shader_codes, NULL);
// compile shaders
glCompileShader(state->gl_vertex_shader_id);
glCompileShader(state->gl_fragment_shader_id);
// check if shaders are valid
//funzione presente in glcommon.h
error_if_glerror();
error_if_shader_not_valid(state->gl_vertex_shader_id);
error_if_shader_not_valid(state->gl_fragment_shader_id);
// create program
state->gl_program_id = glCreateProgram();
// attach shaders
glAttachShader(state->gl_program_id, state->gl_vertex_shader_id);
glAttachShader(state->gl_program_id, state->gl_fragment_shader_id);
// bind vertex attributes locations
//faccio il bind delle variabili in input del vertex shader
glBindAttribLocation(state->gl_program_id, 0, "vertex_pos"); // primo attributo in shade_vertex
glBindAttribLocation(state->gl_program_id, 1, "vertex_norm"); //secondo attributo in shade_vertex
// link program
glLinkProgram(state->gl_program_id);
// check if program is valid
//funzione presente in glcommon.h
error_if_glerror();
error_if_program_not_valid(state->gl_program_id);
}
我该如何解决?
编辑
shade_vertex.glsl
shade_vertex.glsl
#version 120
attribute vec3 vertex_pos; // vertex position (in mesh coordinate frame)
attribute vec3 vertex_norm; // vertex normal (in mesh coordinate frame)
uniform mat4 mesh_frame; // mesh frame (as a matrix)
uniform mat4 camera_frame_inverse; // inverse of the camera frame (as a matrix)
uniform mat4 camera_projection; // camera projection
varying vec3 pos; // [to fragment shader] vertex position (in world coordinate)
varying vec3 norm; // [to fragment shader] vertex normal (in world coordinate)
// main function
void main() {
// compute pos and normal in world space and set up variables for fragment shader (use mesh_frame)
// project vertex position to gl_Position using mesh_frame, camera_frame_inverse and camera_projection
}
shade_fragment.glsl
shade_fragment.glsl
#version 120
varying vec3 pos; // [from vertex shader] position in world space
varying vec3 norm; // [from vertex shader] normal in world space (need normalization)
uniform vec3 camera_pos; // camera position (center of the camera frame)
uniform vec3 ambient; // scene ambient
uniform int lights_num; // number of lights
uniform vec3 light_pos[16]; // light positions
uniform vec3 light_intensity[16]; // light intensities
uniform vec3 material_kd; // material kd
uniform vec3 material_ks; // material ks
uniform float material_n; // material n
// main
void main() {
// re-normalize normals
// use faceforward to ensure the normals points toward us
// accumulate ambient
vec3 c = vec3(0,0,0)
// foreach light
// compute point light color at pos
// compute light direction at pos
// compute view direction using camera_pos and pos
// compute h
// accumulate blinn-phong model
// output final color by setting gl_FragColor
gl_FragColor = vec4(c,1);
}
推荐答案
我解决了genpfault的问题.我必须写gl位置并添加分号.谢谢大家!
I resolved with the solution of genpfault. I had to write gl position and add the semicolon. Thanks to you all!
这篇关于OpenGL错误C0000编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文