Pregunta

I'm working on a simple 3D model loader using OpenGL and I wanted to add texture support. However, not wanting to needlessly rewrite an image library, I downloaded SOIL (Simple OpenGL Image Library) that I learned about in the NeHe tutorial on texture mapping. It has a few very useful functions that take care of loading images of many times and passing them to OpenGL.

The problem is this: In the NeHe tutorial code, the SOIL function

SOIL_load_OGL_texture(char *, param,param,param) 

exactly as promised and the polygons are mapped with the correct picture. However, I've made a class that loads OBJ and MTL files (3D model files). When I try to use the SOIL function to load a texture inside this class, my program crashes.

  • I am using GNU C++ with Code::Blocks (I also tried this code in Dev-C++)
  • I receive no errors or warnings from the compiler with -g -Wall.
  • I have linked and included everything properly in my project (if I copy/paste the NeHe code, it runs properly).
  • The SOIL command does not work inside any class (I tried making another class that only executed the SOIL function and I got the same problem).
  • The file paths passed to the function are all correct. I have tried relative and absolute, with all formats of forward and back slashes. I copied and pasted absolute paths that worked in the NeHe code to my code and it does not work.
  • The rest of my code works fine - I can get my shape rendered with its ambient/diffuse/etc. colors and other settings applied properly.
¿Fue útil?

Solución

Sounds almost like you don't have a valid OpenGL context at the time when you're calling that function.

Are you certain that SOIL is called only after your opengl context is initialized? (e.g. no static construction of objects that are constructed at program initialization). A quick way to check this is to put a breakpoint on your opengl initialization and see if you hit the BP or if your program crashes first.

Also, make sure that SOIL call is on the same thread as your opengl context.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top