[OpenGL] Shader error & info log message is empty?

Hi,
I'm learning opengl and im trying to compile a shader program.

The problem im having is that when i run the following code:

mainer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <GL/glew.h>
#include <GLFW/glfw3.h>

#include "shaders.h"

int main()
{
  ...
  Initializing opengl context
  ...

  GLuint vertexShader;
  compileShader<GL_VERTEX_SHADER>(vertexShader, "vertshader.glsl");
  
  return 0;
}


shaders.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <string>
#include <fstream> 
#include <vector>

bool fileToString(std::ifstream& iStream, std::string& shaderSource)
{
  //Validate stream status
  if(!iStream.good())
    return false;

  //Loop through each line & append to string
  std::string line;
  while(!iStream.eof())
  {
    std::getline(iStream, line);
    shaderSource.append(line);
  }

  return true;
}

bool validateCompilation(GLuint shader)
{
  //Check if there was compile error
  int success;
  glGetShaderiv(shader, GL_COMPILE_STATUS, &success);

  bool compileError = (success == GL_FALSE ? true : false);

  //Print compile error info
  if(compileError)
  {
    //Get log length
    int infoLength = 512;
    glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLength);

    //Get info log message & print it 
    char info[infoLength];
    glGetShaderInfoLog(shader, infoLength, NULL, info);

    std::cout << "SHADER COMPILE ERROR: " << info << std::endl;


  }


  //Return true if no compile error and false otherwise
  return !compileError;
}

template <GLenum SHADER_TYPE>
bool compileShader(GLuint& shader, std::string shaderFile)
{
  //Read shader
  std::ifstream shaderIStream(shaderFile);
  std::string shaderSource;

  if(!fileToString(shaderIStream, shaderSource))
    return false;

  //Create shader obj
  shader = glCreateShader(SHADER_TYPE);

  //Compile shader
  const char* constShaderSource = shaderSource.c_str();
  glShaderSource(shader, 1, &constShaderSource, NULL);

  glCompileShader(SHADER_TYPE);

  //Validate shader
  if(!validateCompilation(shader))
    return false;


  return true;
}


An error occurs when opengl attempts to compile the shader, but the error info log that gets retrieved from opengl is empty,
so it just ends up printing: SHADER COMPILE ERROR: and nothing else.

Basically when i call glGetShaderiv(shader, GL_COMPILE_STATUS, &success) (line 26)
it sets success to GL_FALSE indicating that there was an error
but the info log that i get from glGetShaderInfoLog() appears to be completely empty?

This is the shader program btw:

vertshader.glsl
1
2
3
4
5
6
7
#version 330 core
layout (location = 0) in vec3 aPos;

int main()
{
  gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
}


I would really appreciate it if somebody can figure out what i did wrong here :D
Last edited on
So i figured it out:
i thought you had to pass the shader type to glCompileShader but you were supposed to pass the shader id
Topic archived. No new replies allowed.