Hey all, I hope I'm posting this in the right place
So I'm "refreshing" my OpenGL knowledge by following a series of tutorials, and have gotten to the texturing part.
For loading textures I wanted to try the SOIL library, which seemed pretty good. However when trying to load a texture like so:
GLuint tex_2d = SOIL_load_OGL_texture("img_test.png",
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT);
I am getting a segmentation fault because SOIL is doing this:
if((NULL == strstr( (char const*)glGetString( GL_EXTENSIONS ),
"GL_ARB_texture_non_power_of_two" ) ))
{
/* not there, flag the failure */
has_NPOT_capability = SOIL_CAPABILITY_NONE;
} else
{
/* it's there! */
has_NPOT_capability = SOIL_CAPABILITY_PRESENT;
}
And it appears as if glGetString(GL_EXTENSIONS) is returning NULL.
Upon searching for help on this, i found that calling glGetString with GL_EXTENSIONS has been deprecated and one should now use glGetStringi instead.
So what I did was I updated the SOIL code to use this new way of querying for extensions by implementing this function:
int query_gl_extension( const char *extension)
{
GLuint num_extensions, i;
glGetIntegerv(GL_NUM_EXTENSIONS, &num_extensions);
for(i = 0; i < num_extensions; ++i)
{
const GLubyte *ext = glGetStringi(GL_EXTENSIONS, i);
if(strcmp((const char*)ext, extension) == 0)
return 1;
}
return 0;
}
But this changed nothing. If I use GDB and step through this code, and try to print the value of the variable ext, I get the following:
$2 = (const GLubyte *) 0xfffffffff473d244 <error: Cannot access memory at address 0xfffffffff473d244>
The strange part is; If I try to call glGetStringi(GL_EXTENSIONS, 0) from MY code right before loading the texture with SOIL, it works. So that should rule out my GL context not being active, no?
What could cause glGetStringi(GL_EXTENSIONS, index) to return what seems to be a pointer to random memory when invoked from SOIL, but not when invoked from my code?
My OpenGL version is 3.3 and my OS is Ubuntu 64-bit.
Thanks!