GLSL着色器装载机问题

时间:2010-08-05 18:47:07

标签: opengl graphics glsl

问题是我的glsl加载器不起作用,我不知道我做错了什么。

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);
}

1 个答案:

答案 0 :(得分:3)

您可以使用glGetShaderivglGetShaderInfoLog来了解它认为出了什么问题。我在answer中将一些(经过测试的,有效的)示例代码发布到上一个问题。