-1

My goal is to make use of compute shaders through C++ and OpenGL. The problem is that when I call glBindImageTexture() after creating and initializing a texture, it just terminates the program. I tried checking everywhere what could be the culprit, but I could not trace it back. I'm using glfw as my window and context manager, and glad (Core 4.6) as the wrapper for OpenGL. The (in my opinion) relevant part of the code is the following:

    int tex_w = 512, tex_h = 512;
    GLuint tex_output;
    glGenTextures(1, &tex_output);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, tex_output);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, tex_w, tex_h, 0, GL_RGBA, GL_FLOAT,
     nullptr);
    glBindImageTexture(0, tex_output, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32F);

This is the command I use to compile the program (I'm using MinGW on windows, 64bit):

g++ *.cpp *.c -o bin/main.exe -Iinclude -Llib -lmingw32 -lglfw3 -lopengl32 -lgdi32 -luser32

Everything works, up until calling the last function. I have checked that my system does have OpenGL 4.6 (at least that's what the checker told me), so it should have glBindImageTexture as well. In case you think the problem doesn't come from this part, here is all my code up until that point: https://pastebin.com/AYFaWpfL

CodeForFun
  • 35
  • 10

1 Answers1

2

glBindImageTexture() is only available in GL 4.2+. Yet you're requesting a GL 3.3 context:

...
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = glfwCreateWindow(800, 600, "Hello", nullptr, nullptr);
...

Request a 4.2+ context if you want to use glBindImageTexture().

Or use the ARB_shader_image_load_store extension entry points if you want to continue to use your GL 3.3 code.

genpfault
  • 51,148
  • 11
  • 85
  • 139
  • 2
    Bindless texturing wouldn't make image load/store automatically available. The section of the linked page titled, "Interactions with OpenGL 4.2, ARB_shader_image_load_store" explains further. – Nicol Bolas Apr 12 '21 at 04:27
  • Oh shoot, you're completely right. I forgot all about that and didn't even notice. Thank you very much, this solves my problem! – CodeForFun Apr 12 '21 at 04:45