Why does the function glViewport () give me errors?

MINH TO

I tried doing OpenGL using GLFW. I was beginning to make a window

#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>

int main() {
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    GLFWwindow* window = glfwCreateWindow(500, 500, "Test", NULL, NULL);

    if (window == NULL) {
        std::cout << "GLAD failed.";
    }

    glfwMakeContextCurrent(window);
    void frameBufferSizeCallback(GLFWwindow* window,int width,int height);
    glfwSetFramebufferSizeCallback(window, frameBufferSizeCallback);
    glViewport(0, 0, 500, 500);//Error here

    while (!glfwWindowShouldClose(window)) {
        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}

void frameBufferSizeCallback(GLFWwindow* window,int width,int height) {
    glViewport(0,0,width,height);
}

I get some error saying Exception thrown at 0x00000000 in OpenGLTest0.exe: 0xC0000005: Access violation executing location 0x00000000. And the window I created doesn't even respond to anything including Task Manager "end task. I was using Visual Studio 2017 and had to "end task" the whole aplication in order to remove the window. Also I am on Windows 10.

Could somebody tell me where I am wrong? I thank you in advance!

fufupati

You need to initalize the glad library, without that it can't load in the function pointers.

if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
    std::cout << "Failed to initialize GLAD" << std::endl;
    return -1;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why does my function give me "this is not red"?

Why does gin + SocketIO give me EOF errors?

Why does my custom Binomial Function give me an $Inf$ in return?

Why does python give me a TypeError for this function? (new to coding)

Why does the strcat function give me a segmentation fault?

Why does vectorizing my Matlab function give me a warning?

Why does the variable give me a TypeError but the function doesn't?

why does using cin function give me error?

Why does this give me an IndexError?

Why does xrandr give me errors if I try and use commands on my computer, but not if I ssh into it?

Why does lapply with closures give errors?

repeatCount function does not give me the right answer. Why does this happen?

Why does BeautifulSoup give me the wrong text?

Why does "cgps -s" give me no results?

Why does mktime give me an hour less?

Why does " $Namefile* " give me such a result?

Why does this html code give me an error?

Why does Vlookup give me the wrong answer?

Why does this IQueryable issue give me an error?

Why does glewInit() give me a segfault?

What does the anonymous function give me?

Why does JS Fiddle give me the error `Uncaught TypeError: undefined is not a function `?

C, Why does my custom free function give me the "pointer being freed was not allocated" error

Why does a SELECT INTO sql statement give me an error in this Pl/SQL Function?

Why does the ngrams() function give distinct bigrams?

Why is this constexpr-function giving me errors?

Why does PyCharm give unresolved reference errors on some Numpy imports?

why is the picture not displayed on the pygame window? the code does not give errors

Why is this element null and why does it give me an input element?