GlTexImage3D exception

I am trying to compile this application in VS13. I linked all the libraries this way: glew32.lib from glew-1.10.0 \ lib \ Release \ Win32 put glew32.dll in the same folder as Debug linked glfw3

When I run this code, it throws an exception in glTexImage3D; he says: "Access violation executing location 0x00000000."

    #include <GL/glew.h>
#include <GL/glfw3.h>

#include <cstdlib>
#include <iostream>

GLenum volumeTexture;

int main() {
    // Initialize GLFW
    if (!glfwInit()) {
        std::cerr << "Failed to initialize GLFW! I'm out!" << std::endl;
        exit(-1);
    }

    glewExperimental = GL_TRUE;
    GLenum err = glewInit();

    if (GLEW_OK != err)
    {
        /* Problem: glewInit failed, something is seriously wrong. */
        fprintf(stderr, "Error: %s\n", glewGetErrorString(err));

    }

    // Use red to clear the screen
    glClearColor(1, 0, 0, 1);
    glGenTextures(1, &volumeTexture);
    glBindTexture(GL_TEXTURE_3D, volumeTexture);

    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER);
    glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 256, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);

I noticed that the error resolves if I add

glTexImage3D = (PFNGLTEXIMAGE3DPROC) wglGetProcAddress("glTexImage3D");

but then I get the same exception later when I run glGenFramebuffers (I get it even if I comment out the glTexImage3D line) Am I linking something wrong?

+4
source share
1 answer

Your sequence is incorrect.

glewInit() , GL . GL (, glTexImage3D()) NULL.

glfwInit() GL .

glfwCreateWindow() glfwMakeContextCurrent().

+3

Source: https://habr.com/ru/post/1544756/


All Articles