2016-12-31 17 views
0

私は頂点シェーダコンパイルする:このOpenGLはGLSLシェーダをコンパイルできません。行方不明?

pShader.ID = glCreateShader(GL_VERTEX_SHADER); 
std::ifstream shaderFile; 
shaderFile.open(pShader.path); 

if (shaderFile.fail()) { 
    printf("!!!\nCannot open Shader File %s ! Shader compilation cancelled!", pShader.path.c_str()); 
} 
else { 
    std::string line; 
    while (getline(shaderFile, line)) { 
     pShader.content += line + '\n'; 
     ++pShader.lines; 
    } 
    const char* shaderContent = pShader.content.c_str(); 
    glShaderSource(pShader.ID, 1, &shaderContent, &pShader.lines); 
    glCompileShader(pShader.ID); 
    GLint success = 0; 
    glGetShaderiv(pShader.ID, GL_COMPILE_STATUS, &success); 
    if (success == GL_FALSE) { 
     //errror checking 
     } 

よう

#version 430 

layout(location = 0)in vec3 vertexPosition; 
layout(location = 1)in vec3 vertexNormal; 
layout(location = 2)in vec2 vertexUV; 

out Vertex{ 
vec2 uv; 
vec4 normal; 
}vertexOut; 

void main(){ 
    gl_Position = vec4(
    vertexPosition.x, 
    vertexPosition.y, 
    vertexPosition.z, 
    1.0f); 
    vertexOut.uv = vertexUV; 
    vertexOut.normal = vec4(vertexNormal, 0.0f); 
} 

をしかし、私はまた、取得しています私のフラグメントシェーダではコンパイルエラー

Vertex Shader failed to compile with the following errors: 
ERROR: 0:3: error(#132) Syntax error "layou" parse error 
ERROR: errror(#273) 1 compilation errors. No code generated 

を取得しています」/"解析エラーですが、私はそれを見つけることができます。

私は入力と文脈のための拡張読み込みとglfwのためにglewを使用しています。 glewinfo.exeを実行すると、いくつかの拡張機能が不足しているとマークされていますが、AMD Radeon HD 7800ドライバは最新のものです。問題とは何ですか?

これらはglewinfo.exe結果である:http://m.uploadedit.com/ba3s/148318971635.txt

+0

['glShaderSource'](http://docs.gl/gl4/glShaderSource)に渡す内容を確認してください。特に、あなたの' length'パラメータは非常に正しくないようです。 – PeterT

答えて

3

問題は、あなたがglShaderSourceに間違った長さを渡していること、です。最後のパラメータには、各文字列の文字数が含まれていなければなりません。同時に複数の文字列を渡すことができるので、これはcount(2番目のパラメータ)要素の配列です。

あなたの例では正しいコードは次のようになります。

const char* code = shaderContent.c_str(); 
int length = shaderContent.size(); 
glShaderSource(pShader.ID, 1, &code, &length); 

また、ラインでファイル全体のラインを読むことも非常に効率的ではありません。

+0

ありがとう!それがトリックでした。 すばやくファイルを読む方法を私に指示できますか?欠落している拡張機能はどうですか?これは多くのことが欠けているのが一般的ですか? – stimulate

+1

グラフィックカードがサポートしていない限り、これは正常です。 – BDL

+1

一度にファイル全体を読む方法に関するこの質問をチェックしてください:http://stackoverflow.com/questions/116038/what-is-the-best-way-to-read-an-entire-file-into-a- stdstring-in-c – BDL

関連する問題