kbranigan / Simple-OpenGL-Image-Library

Simple image uploader primarily for OpenGL
http://lonesock.net/soil.html
244 stars 105 forks source link

Usage of deprecated glGetString( GL_EXTENSIONS ) #8

Open DashW opened 10 years ago

DashW commented 10 years ago

http://stackoverflow.com/questions/17923782/simple-opengl-image-library-soil-uses-deprecated-functionality

https://www.opengl.org/sdk/docs/man3/xhtml/glGetString.xml

GL_EXTENSIONS has been deprecated as a paremeter to glGetString. All calls to glGetString( GL_EXTENSIONS ) fail under OpenGL 3+ with error GL_INVALID_ENUM. This breaks all query_x_capability functions... which breaks most of SOIL.

Apparently, the correct approach is now to iterate over and compare each extension substring using glGetStringi( GL_EXTENSIONS, i ).

njcrawford commented 9 years ago

I may be interested in implementing this. According to https://www.opengl.org/sdk/docs/man/html/glGetString.xhtml, glGetStringi() is present in 3.0 and up, so this change would exclude devices that only support up to OpenGL 2.1. I think that's probably an acceptable tradeoff, but if anyone thinks differently, please chime in.

For my own reference when I come back to this, the number of extensions can be queried with glGetIntegerv(GL_NUM_EXTENSIONS).

njcrawford commented 9 years ago

I wasn't able to find a cross-platform solution for this issue, but for anyone interested, I have a branch that works for Windows here: https://github.com/njcrawford/Simple-OpenGL-Image-Library/tree/issue-8-attempt2 The definition for GL_NUM_EXTENSIONS introduces a dependency on glext.h from the OpenGL registry, which can be found here: https://www.opengl.org/registry/ (look under the API and Extension Header Files section for downloads)

With that said, I found that my applications were only calling SOIL_load_image_from_memory(), which is a direct pass-through to stbi_load_from_memory(). For my purposes it's far easier to include stb_image.h directly in my source than to update SOIL for OpenGL 3.0 compatibility, so I've stopped working on this issue.

0nix commented 7 years ago

+1 for this issue.

jpaoneMines commented 6 years ago

I've solved this issue by having SOIL depend on GLEW. Would that be an acceptable correction/dependency to submit?

stevenwdv commented 6 years ago

Sad to see this is still not fixed; took me some time to figure out what went wrong :/

njcrawford commented 6 years ago

Just out of curiosity, is anyone using any SOIL functions other than SOIL_load_image() or SOIL_load_image_from_memory()?

stevenwdv commented 6 years ago

@njcrawford I tried to use SOIL_load_OGL_texture but I'm new to OpenGL and stuff so that may be not the best option or something; I don't know what other functions there are exactly and what the differences are.

njcrawford commented 6 years ago

@stevenwdv It's a bit more work, but you can get about the same effect with code like this: (This code came from a working program, but I edited it down for conciseness so I can't guarantee it will work as-is)

int MyLoadImage(const char * filename)
{
int x,y,n;
unsigned char * tempData = stbi_load(filename, &x, &y, &n, 0);

// Generate and activate OpenGL texture handle
int tex;
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);

// Give textures a voxel look - optional
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
// Repeat textures - optional
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

// Match texture data format to the image we loaded
GLuint texDataFormat = 0;
if (n == 3)
{
    texDataFormat = GL_RGB;
}
else if (n == 4)
{
    texDataFormat = GL_RGBA;
}
// Send the image to OpenGL
glTexImage2D(GL_TEXTURE_2D, 0, texDataFormat, w, h, 0, texDataFormat, GL_UNSIGNED_BYTE, tempData);

// Go back to the default texture
glBindTexture(GL_TEXTURE_2D, 0);
// Free stbi data
stbi_image_free((void *)tempData);

return tex;
}
stevenwdv commented 6 years ago

@njcrawford For now I already got it to work with lodepng (after some struggling with the order of bindBuffer etc.), but I will probably switch to some compressed texture format supported by the GPU like S3TS sooner or later; but thanks anyway! Edit: Ah it seems like your solution would also work for these compressed images; didn't notice that at first ;)