SDL/GL with SOIL

Hello, i decided to start programming again after years of break and i wanted to get a "testprogram" up where i can experiment with graphics. Im using SDL for the Window and GL for graphics and i want to load images with SOIL because the colours get messy when i try to do it with SDL_Image. Im getting a "Unhandled Exception" when im calling the SOIL_OGL_Load_Texture. Ive checked filepath and it seems to be correct and i've been scrolling my code for hours now and i need help. I will send the relevant code and see if you guys can spot where i did wrong!


Here is the init process, Maybe im missing something here?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
bool Window::init()
{
	if( SDL_Init( SDL_INIT_EVERYTHING ) < 0 )
	{
		std::cout << "ERROR: could not initialize SDL" << std::endl;
	}

	SDL_GL_SetAttribute(SDL_GL_RED_SIZE,8);
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,8);
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,8);
	SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE,8);
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,16);
	SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE,32);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);

	if(fullscreen)
	{
		if( SDL_SetVideoMode( WIDTH, HEIGHT, BPP, SDL_DOUBLEBUF|SDL_HWSURFACE|SDL_FULLSCREEN|SDL_OPENGL ) == NULL )
		{
			std::cout << "ERROR: could not setup a window" << std::endl;
			return false;
		}
	}
	else
	{
		if( SDL_SetVideoMode( WIDTH, HEIGHT, BPP, SDL_DOUBLEBUF|SDL_HWSURFACE ) == NULL )
		{
			std::cout << "ERROR: could not setup a window" << std::endl;
			return false;
		}
	}

	SDL_WM_SetCaption( CONSTANTS::window::CAPTION, NULL );

	glClearColor(0.0f,0.0f,0.0f,1.0f);
	glViewport( 0, 0, CONSTANTS::window::WIDTH, CONSTANTS::window::HEIGHT);
	glOrtho( 0, CONSTANTS::window::WIDTH, CONSTANTS::window::HEIGHT, 0, -1, 1 );

	glDisable(GL_DEPTH_TEST);					
	glDisable(GL_COLOR_MATERIAL);					
	glEnable(GL_BLEND);							
	glShadeModel(GL_SMOOTH);							
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glMatrixMode(GL_PROJECTION);					
	glLoadIdentity();							

	return true;
}


Here is the code where i load the image.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
GLuint loadImage(const char * pFile)
{
	GLuint TextureID = 0;
	TextureID = SOIL_load_OGL_texture( pFile, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y );
	glBindTexture(GL_TEXTURE_2D,TextureID);

	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

	if(TextureID == 0)
	{
		std::cout << "Error: could not load the texture: \"" << pFile << "\" Check if file is in correct directory" << std::endl;
		return -1;
	}else{
		std::cout << "texture \"" << pFile << "\" loaded. ID: " << TextureID << std::endl; 
		return TextureID;
	}
}


Just tell me if you think the error is somewhere else in the code and i will post it. But i think its somewhere around those parts
Last edited on
Do you think maybe you should be checking if the call to SOIL_load_OGL_texture was successful before you do all that stuff with it?
I have already said that the call is unsuccesful!
Just posted all code togheter.
I have already said that the call is unsuccesful!


No, actually, you said:

Im getting a "Unhandled Exception" when im calling the SOIL_OGL_Load_Texture.


Does the execution actually get down to line 15 where you finally check to see if the call succeeded after you've already used the return value as if it did succeed?

Are you calling this function before an OpenGL context is created?

Have you attempted to "handle" the exception?
Topic archived. No new replies allowed.