0

I want to compile the vertex shader:

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

like this

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
        }

but i am getting the compilation error

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

In my fragment shader i am also getting a "/" parse error, but i can find it.

I am using glew for extension loading and glfw for input and context. When i run the glewinfo.exe there are some extensions marked as missing, but my AMD Radeon HD 7800 Drivers are up to date.. What is the problem and what am i supposed to do?

these are the glewinfo.exe results: http://m.uploadedit.com/ba3s/148318971635.txt

stimulate
  • 1,059
  • 6
  • 23
  • check what you pass into [`glShaderSource`](http://docs.gl/gl4/glShaderSource) especially your `length` parameter seems to very much not be correct – PeterT Dec 31 '16 at 13:28

1 Answers1

3

The problem is, that you are passing a wrong length to glShaderSource. The last parameter has to contain the number of characters in each string. Since you could pass multiple strings at the same time, this is an array with count (the second parameter) elements.

The correct code in your example would be:

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

Additionally, reading a whole file line by line is also not very efficient.

BDL
  • 18,169
  • 14
  • 45
  • 47
  • Thank you! That did the trick. Can you quick direct me to a way to read a file faster? And what about the missing extensions? Is it common that there are missing this many? – stimulate Dec 31 '16 at 13:39
  • 1
    Unless your graphic card supports them, yes this is normal. – BDL Dec 31 '16 at 13:43
  • 1
    Check this question on how to read a whole file at once: http://stackoverflow.com/questions/116038/what-is-the-best-way-to-read-an-entire-file-into-a-stdstring-in-c – BDL Dec 31 '16 at 13:44