Access violation on glCreateShader() despite GLAD initialization?

-2

i'm trying to work with OpenGL, which i did before few times, but now i have problem that when i call glCreateSHader(GL_VERTEX_SHADER) i get error 0xC0000005: Access violation executing location i tried reading multiple articles on Stackoverflow, GLFW sites etc etc but everyone was using glew and i use glad and i couldn't get this to work, here is some code from my Game.cpp file:

int main() {

    DisplayManager display;

    Shader shader;

    display.CreateDisplay(800, 600);

    while (!glfwWindowShouldClose(display.window)) {

        CloseByInput(display.window);

        glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT);

        glfwPollEvents();
        glfwSwapBuffers(display.window);

    }

    glfwTerminate();

    return 0;

}

here is CreateDisplay function from DisplayManager.cpp:

glfwInit();

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

#ifdef __APPLE__

    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);

#endif

    DisplayManager::window = glfwCreateWindow(Width, Height, "Thing", NULL, NULL);

    if (window == NULL) {

        std::cout << "Failed to Create Window" << std::endl;

        glfwTerminate();

        return -1;

    }

    glfwMakeContextCurrent(window);

    if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {

        std::cout << "Failed to initialize glad" << std::endl;

        return -1;

    }

    glViewport(0, 0, Width, Height);

    glfwSetFramebufferSizeCallback(window, frameBufferSizeCallback);

i've initialized glad after glfwMakeContextCurrent(window); and it's initialized okay, it runs but when i get to Creating Shader i run into multiple that error, here is my code for Shader.cpp (Shader class is not finished yet, there are some stuff that are not finished like actually using the shader etc, so just saying):

#include "Shader.h"

Shader::Shader() {

    string VertexSource = GetSource("src/Shaders/VertexShader.shader");
    //string FragmentSource = GetSource("srd/Shaders/FragmentShader.shader");

    unsigned int VertexID = CompileShader(GL_VERTEX_SHADER, VertexSource);
    //unsigned int FragmentID = CompileShader(GL_FRAGMENT_SHADER, VertexSource);

}

string Shader::GetSource(const char* path) {

    ifstream file;
    stringstream buffer;

    string source = "";

    file.open(path);

    if (file.is_open()) {

        buffer << file.rdbuf();

        source = buffer.str();

    } else {

        cout << "Could not open file: " << path << endl;

    }

    file.close();

    return source;

}

unsigned int Shader::CompileShader(GLenum Type, string source) {

    int success;
    char infoLog[512];

    unsigned int ID = glCreateShader(GL_VERTEX_SHADER); //I get error on this line

    const GLchar* src = source.c_str();

    glShaderSource(ID, 1, &src, NULL);
    glCompileShader(ID);

    glGetShaderiv(ID, GL_COMPILE_STATUS, &success);

    if (!success) {

        glGetShaderInfoLog(ID, 512, NULL, infoLog);
        cout << "Errorwith loading: " << Type << " infoLog: " << infoLog << endl;

    }

    return ID;

}

How it's marked in the code, i get error when calling line: unsigned int ID = glCreateShader(GL_VERTEX_SHADER); (also i have the Type hard coded for Vertex Shader for now because i wanted to see if it will change anything, but it didn't) i've red alot of articles on Stackoverflow, if someone needs to know somethign more just tell me in comments

c++
opengl
glad
asked on Stack Overflow May 25, 2021 by ChrisHusky • edited May 25, 2021 by ChrisHusky

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0