2010-08-05 90 views
0

問題是,我的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

你應該回答的第一件事是什麼不起作用?它崩潰?你有空白的屏幕?等 – 2010-08-05 18:49:31

+0

啊這是頂點着色器文件是錯誤的(我複製一個錯誤)。抱歉。 – user389006 2010-08-05 21:45:09

+1

vs = new char [...];免費(vs); 你真的在問問題。使用delete [] vs; – Bahbar 2010-08-06 07:38:51

回答

3

你可以使用glGetShaderivglGetShaderInfoLog得到它認爲什麼錯誤的一些概念。我在answer中發佈了一些(測試過的,有效的)示例代碼到以前的問題。