5
\$\begingroup\$

I'm creating a game in C++ using OpenGL, and decided to go with the SOIL library for image loading, as I have used it in the past to great effect. The problem is, in my newest game, trying to load an image with SOIL throws the following runtime error: enter image description here

This error points to this part:

// SOIL.c
int query_NPOT_capability( void )
{
/*  check for the capability    */
if( has_NPOT_capability == SOIL_CAPABILITY_UNKNOWN )
{
    /*  we haven't yet checked for the capability, do so    */
    if(
        (NULL == strstr( (char const*)glGetString( GL_EXTENSIONS ),
            "GL_ARB_texture_non_power_of_two" ) )
        ) //############ it points here ############//
    {
        /*  not there, flag the failure */
        has_NPOT_capability = SOIL_CAPABILITY_NONE;
    } else
    {
        /*  it's there! */
        has_NPOT_capability = SOIL_CAPABILITY_PRESENT;
    }
}
/*  let the user know if we can do non-power-of-two textures or not */
return has_NPOT_capability;
}

Since it points to the line where SOIL tries to access the OpenGL extensions, I think that for some reason SOIL is trying to load the texture before an OpenGL context is created. The problem is, I've gone through the entire solution, and there is only one place where SOIL has to load a texture, and it happens long after the OpenGL context is created.

This is the part where it loads the texture...

   //Init glfw
if (!glfwInit())
{
    fprintf(stderr, "GLFW Initialization has failed!\n");
    exit(EXIT_FAILURE);
}
printf("GLFW Initialized.\n");

//Process the command line arguments
processCmdArgs(argc, argv);

//Create the window
glfwWindowHint(GLFW_SAMPLES, g_aaSamples);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
g_mainWindow = glfwCreateWindow(g_screenWidth, g_screenHeight, "Voxel Shipyard", g_fullScreen ? glfwGetPrimaryMonitor() : nullptr, nullptr);
if (!g_mainWindow)
{
    fprintf(stderr, "Could not create GLFW window!\n");
    closeOGL();
    exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(g_mainWindow);
printf("Window and OpenGL rendering context created.\n");

//Create the internal rendering components
prepareScreen();

//Init glew
glewExperimental = GL_TRUE;
int err = glewInit();
if (err != GLEW_OK)
{
    fprintf(stderr, "GLEW initialization failed!\n");
    fprintf(stderr, "%s\n", glewGetErrorString(err));
    closeOGL();
    exit(EXIT_FAILURE);
}
printf("GLEW initialized.\n"); <-- Sucessfully creates an OpenGL context

//Initialize the app
g_app = new App();
g_app->PreInit();
g_app->Init();
g_app->PostInit(); <-- Loads the texture (after the context is created)

...and debug printing to the console CONFIRMS that the OpenGL context was created before the texture loading was attempted.

So my question is if anyone is familiar with this specific error, or knows if there is a specific instance as to why SOIL would think OpenGL isn't initialized yet.

\$\endgroup\$

1 Answer 1

6
\$\begingroup\$
if(
    (NULL == strstr( (char const*)glGetString( GL_EXTENSIONS ),
        "GL_ARB_texture_non_power_of_two" ) )
    ) //############ it points here ############//

You are creating an OpenGL 3.2 context. glGetString(GL_EXTENSIONS) returns NULL because it has been deprecated in 3.0 and removed in 3.1. It was replaced by glGetStringi(GL_EXTENSIONS, i).

See also here.

A quick fix would be to request a no higher than 3.0 context. But if you need > 3.0 functionality you will have to patch the SOIL library to use the correct method to test for extensions as described in the link above. This would have to be done everywhere glGetString(GL_EXTENSIONS) is called.

\$\endgroup\$
4
  • 3
    \$\begingroup\$ Or use compatibility mode (which I'm surprised is not the default in GLFW) so that no deprecated functions are actually removed. The only platform where deprecations really matter currently is OSX as there you can only get the higher versions when in core/non-compat mode. \$\endgroup\$ Commented Oct 28, 2013 at 17:37
  • \$\begingroup\$ @SeanMiddleditch I tried both of these solutions. I changed the loading method to have SOIL only load the unsigned byte data, and then I generated the textures myself. This resulted in everything being a bright pink color. Then I also tried using the original loading code, but also changing to compatibility mode, which also got rid of the errors, but also resulted in everything being a bright pink color. \$\endgroup\$
    – sm81095
    Commented Oct 28, 2013 at 18:06
  • \$\begingroup\$ Does anyone know if there is something in OpenGL that makes textures pink? Like missing textures or something? \$\endgroup\$
    – sm81095
    Commented Oct 28, 2013 at 19:21
  • \$\begingroup\$ @SeanM.: "something". It could be one of a dozen things. Usually I've seen things like that when your texture is not bound properly or what the texture upload errored out. Try using something like gDEBugger (preferably the up-to-date AMD version, not the ancient Gremedy version). \$\endgroup\$ Commented Oct 28, 2013 at 20:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .