Hi,
I'm working on an OpenGL project and I get an error that says "No shaders attached to current program" only in the release build. If I build it in debug mode I don't get this error. I know this is a link error, but I don't understand why I'm only getting it in release mode?
I'm building this project as a dll file that then gets called from a normal exe file.
here i my code
#pragma once
#include <GLEW/GL/glew.h>
#include <vector>
#include "../../../IO/FileReader.h"
#include "../../../Math/Math.h"
#ifdef COMPILE_BLUE_FLAME_ENGINE
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT __declspec(dllimport)
#endif
namespace BFE
{
namespace Graphics
{
class DLLEXPORT GLShader
{
private:
GLint result = GL_FALSE;
int errorLength;
GLuint programID;
private:
void LoadAndSpliteShader(const char* shaderFile, std::string *vertexShader, std::string *fragmentShader);
GLuint &CompileShader(std::string shaderCode, GLenum shaderType);
public:
GLShader();
~GLShader();
void Load(const char* fileName);
void SetUniformFloat(const char* varibleName, const float &value) const;
void SetUniformVector2(const char* varibleName, const Math::Vector2 &vector) const;
void SetUniformVector3(const char* varibleName, const Math::Vector3 &vector) const;
void SetUniformVector4(const char* varibleName, const Math::Vector4 &vector) const;
//void SetUniformMatrix4(const char* VaribleName, const Math::Matrix4 &Matrix) const;
void Bind();
void Unbind();
};
}
}
---
---
---
---
void GLShader::LoadAndSpliteShader(const char* shaderFile, std::string *vertexShader, std::string *fragmentShader)
{
std::string strShaderCode = IO::FileReader::ReadFile(shaderFile);
int vertexPosition = strShaderCode.find("#Vertex Shader");;
int fragmentPosition = strShaderCode.find("#Fragment Shader");;
int vertexLength = 15;
int fragmentLength = 17;
//Splite vertex shader
std::string tempVertexShader = strShaderCode.substr(vertexPosition + vertexLength);
*vertexShader = tempVertexShader.substr(vertexPosition, fragmentPosition - fragmentLength);
//Splite fragment shader
*fragmentShader = strShaderCode.substr(fragmentPosition + fragmentLength);
}
GLuint &GLShader::CompileShader(std::string shaderCode, GLenum shaderType)
{
GLuint shaderID = glCreateShader(shaderType);
const char* cShaderCode = shaderCode.c_str();
glShaderSource(shaderID, 1, &cShaderCode, 0);
glCompileShader(shaderID);
glGetShaderiv(shaderID, GL_COMPILE_STATUS, &result);
glGetShaderiv(shaderID, GL_INFO_LOG_LENGTH, &errorLength);
if (errorLength > 0)
{
std::vector<char> shaderErrorMessage(errorLength + 1);
glGetShaderInfoLog(shaderID, errorLength, NULL, &shaderErrorMessage[0]);
printf("Compile Error: %s\n", &shaderErrorMessage[0]);
}
return shaderID;
}
void GLShader::Load(const char* fileName)
{
std::string vertexShaderCode, fragmentShaderCode;
LoadAndSpliteShader(fileName, &vertexShaderCode, &fragmentShaderCode);
GLuint vertexShader = CompileShader(vertexShaderCode, GL_VERTEX_SHADER);
GLuint fragmentShader = CompileShader(fragmentShaderCode, GL_FRAGMENT_SHADER);
programID = glCreateProgram();
glAttachShader(programID, vertexShader);
glAttachShader(programID, fragmentShader);
glLinkProgram(programID);
glGetProgramiv(programID, GL_LINK_STATUS, &result);
glGetProgramiv(programID, GL_INFO_LOG_LENGTH, &errorLength);
if (errorLength > 0)
{
std::vector<char> ProgramErrorMessage(errorLength + 1);
glGetProgramInfoLog(programID, errorLength, NULL, &ProgramErrorMessage[0]);
printf("Link Error: %s\n", &ProgramErrorMessage[0]);
}
glDetachShader(programID, vertexShader);
glDetachShader(programID, fragmentShader);
glDeleteShader(vertexShader);
glDeleteShader(fragmentShader);
}