SOIL issues

I am somewhat new to classes and OpenGL, but I am trying to make a program incorporating them. I originally loaded textures using SOIL.h in my main .cpp file and everything worked fine. Now I am trying to add the loading of the texture and drawing it into a class. When I compile it (using Dev c++), my compiler doesn't flag any errors, but when it runs the program, the program shuts down before the window even pops up. When I remove the code for loading the texture in the constructor the program works, minus the fact that it doesn't display texture. Any ideas of what is wrong or how I can fix it?
There are several problems with this:

1) You are trying to learn several, completely unrelated concepts at once. You will either go mad or give up at some point.
2) The "Dev" in "Dev C++" stands for "Devil".
3) What the heck is "SOIL"?
4) We can't help you if you won't tell us what the problem is.
Last edited on
SOIL is an image library which I found that can be used as a texture.
Also, I don't know what the issue is either. If I did, I could possibly fix it myself. Basically all I know is that when I load textures from within a class using a separate .cpp and .h files, the program compiles, but when it runs, it closes before the window is even displayed. I assume there is some error that occurs, so windows closes the application.
We still don't know what you're actually doing, so unless we have a psychic here you'd have to show us.
In my class in the constructor this seems to be causing the error:
Texture[0] = SOIL_load_OGL_texture ("images/image1.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT);
Once I remove this line, the program runs properly (without any texture).
in the class in the drawing function:
1
2
3
4
5
6
7
8
9
10
11
12
glBindTexture(GL_TEXTURE_2D, Texture[0]);
glBegin (GL_QUADS);
glColor3f (1.0f, 1.0f, 1.0f);
glTexCoord2f (0.0, 0.0);
glVertex2f (xPt, yPt);
glTexCoord2f (0.0, 1.0);
glVertex2f (xPt, yPt + height);
glTexCoord2f (1.0, 1.0);
glVertex2f (xPt + width, yPt + height);
glTexCoord2f (1.0, 0.0);
glVertex2f (xPt + width, yPt);
glEnd ();

does this help?
I see... intermediate mode... it's... evil... argh. Nope sorry, can't help. Did you check if the texture is actually properly loaded?
Last edited on
no but I used the same code in my main .cpp file and it worked fine.
In that case, the problem isn't the code. Does SOIL need any initialization?
First, stop using Dev-C++
It hasnt been updated since 2005; and has almost 400 known bugs.
The issue your having could be simply a compiler bug.

Second, when you do something like that in a class, rather then a simple function; you
need to double and triple check that all your initilizations, resources, etc etc are
being properly used in that scope/class.

Third, stop using Dev-C++
Code::Blocks, VC++ Express, Eclipse........ theres more too.

also, doesnt the dev-c++ latest version (which is again... 6 yrs old) follow an old c++ standard?
eventually your going to download code that wont run on it anyway

like the new nullptr.
int *somePointer = nullptr;


Life will be easier if you get something else, i understand it probably shipped on some CDROM with a beginners books "like it did for me"; and it just feels like home... but youll be surprized how fast that feeling passes when you get an IDE that just runs better.
Last edited on
also, doesnt the dev-c++ latest version (which is again... 6 yrs old) follow an old c++ standard?


Nope, that's not the problem - it DOES ship with a completely outdated and buggy version of MinGW though.
I noticed that this:
Texture[0] = SOIL_load_OGL_texture ("images/image1.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT);
creates errors when the image exists. When I type in random letters for a file name, the program runs properly, except that the texture isn't there. Any ideas on what could cause this?

Also, if I was to switch my IDE, what would be the best option?
Also, I found that loading texture in the constructor is an issue. I thought that the constructor's main purpose was to define variables when the class is loaded. Why does this not work?
It's got nothing to do with the constructor. A constructor works exactly the same as any other function (because it IS any other function). I assume that you create the object before creating a valid opengl context.
Topic archived. No new replies allowed.