Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
开发者_高级运维 Improve this questionThe problem is that my glsl loader does not work and i dont see what im doing wrong.
void cShader::Load(const char *v_filename,const char *f_filename)
{
char *vs,*fs;
vShaderList = glCreateShader(GL_VERTEX_SHADER);
fShaderList = glCreateShader(GL_FRAGMENT_SHADER);
std::ifstream v_fs;
v_fs.open(v_filename,std::ios::binary);
v_fs.seekg(0,std::ios::end);
int v_filesize = v_fs.tellg();
vs = new char[v_filesize+1];
v_fs.seekg(0,std::ios::beg);
v_fs.read(vs,v_filesize);
v_fs.close();
vs[v_filesize] = '\n';
std::cout.write(vs,v_filesize);
std::ifstream f_fs;
f_fs.open(f_filename,std::ios::binary);
f_fs.seekg(0,std::ios::end);
int f_filesize = f_fs.tellg();
fs = new char[f_filesize+1];
f_fs.seekg(0,std::ios::beg);
f_fs.read(fs,f_filesize);
f_fs.close();
fs[f_filesize] = '\n';
std::cout.write(fs,f_filesize);
const char * vv = vs;
const char * ff = fs;
glShaderSource(vShaderList, 1, &vv,NULL);
glShaderSource(fShaderList, 1, &ff,NULL);
free(vs);free(fs);
glCompileShader(vShaderList);
glCompileShader(fShaderList);
ShaderID = glCreateProgram();
glAttachShader(ShaderID,vShaderList);
glAttachShader(ShaderID,fShaderList);
glLinkProgram(ShaderID);
glUseProgram(ShaderID);
}
You could use glGetShaderiv
and glGetShaderInfoLog
to get some idea of what it thinks is going wrong. I posted some (tested, working) sample code in answer to a previous question.
精彩评论