2016-12-31 6 views
0

나는 정점 셰이더 컴파일하려면이OpenGL은 GLSL Shader를 컴파일하지 않습니다. 누락 된 확장 프로그램은 무엇입니까?

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 

를 받고 오전 "/"구문 분석 오류가 있지만 찾을 수 있습니다.

저는 입력 내용과 문맥에 gllew를 사용하고 있습니다. 내가없는 것으로 표시된 일부 확장이있는 glewinfo.exe을 실행,하지만 내 AMD 라데온 HD 7800 드라이버가 최신 때 에 .. 문제가 무엇이며 어떻게 내가 어떻게해야 하죠? 당신이 glShaderSource에 잘못된 길이를 전달하는 것으로, http://m.uploadedit.com/ba3s/148318971635.txt

+0

체크 ['glShaderSource'] (http://docs.gl/gl4/glShaderSource)는 특히'length' 매개 변수는 – PeterT

답변

3

문제는 다음과 같습니다

는 glewinfo.exe 결과입니다. 마지막 매개 변수는 각 문자열의 문자 수를 포함해야합니다. 동시에 여러 문자열을 전달할 수 있으므로이 배열은 count (두 번째 매개 변수) 요소가있는 배열입니다.

귀하의 예제에서 올바른 코드는 다음과 같습니다

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