2 Replies - 917 Views - Last Post: 03 September 2012 - 10:38 PM Rate Topic: -----

#1 rethc  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 76
  • Joined: 23-April 12

SDL OpenGL images not loading in DevC++

Posted 03 September 2012 - 07:50 PM

Im converting my game im working on from codeblocks to dev-c++ 5.2.03 portable to work on it at school, but im running into some problems. The texture for the game arn't loading when i run the program. The images just shows up white but if i draw QUADS without the texture it shows up fine.

I'm using SDL_image library to load .png files and they are located in the project directory. I have also tried using other formats like .jpg but i get the same result.

I think there might be something wrong with the load function. It is from a tutorial but it works fine in codeblocks. Also, if try to load a file that doesn't exist it doesn't return with an error, like it does with codeblocks.

GLuint Game::loadTexture(const string &fileName)
{
	//Load surface
	SDL_Surface *image = IMG_Load( fileName.c_str() );

	if (!image)
	{
		return 1;
	}

	SDL_DisplayFormatAlpha(image);

	//Create texture
	unsigned object(0);

	glGenTextures(1, &object);
	glBindTexture(GL_TEXTURE_2D, object);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image->w, image->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels);

	//Free surface
	SDL_FreeSurface(image);

	return object;
}

Game::Game()
{
   initGL();
   desk_texture = 0;
   desk_texture = loadTexture("desk.png");
}

void Game::render()
{
   glEnable(GL_TEXTURE_2D);
   glBindTexture(GL_TEXTURE_2D, desk_texture);
   glBegin(GL_QUADS);
          glTexCoord2d(0,0);
          glVertex2f(30, 30);  
	  glTexCoord2d(1,0);
	  glVertex2f(60, 30);  
	  glTexCoord2d(1,1);
	  glVertex2f(60, 60); 
	  glTexCoord2d(0,1);
	  glVertex2f(30, 60); 
   glEnd();
   glDisiable(GL_TEXTURE_2D);
}



In the linker parameter it has:
-lmingw32 -lSDLmain -lSDL -lopengl32 -lSDL_image

This post has been edited by rethc: 03 September 2012 - 07:51 PM


Is This A Good Question/Topic? 0
  • +

Replies To: SDL OpenGL images not loading in DevC++

#2 Mina-no-Hime  Icon User is offline

  • D.I.C Head

Reputation: 98
  • View blog
  • Posts: 176
  • Joined: 23-August 12

Re: SDL OpenGL images not loading in DevC++

Posted 03 September 2012 - 07:55 PM

Where is "desk.png" located in relation to the executable file? Because that's what's going to matter in this case -- and different IDEs will output to different folders when building, and others will even change the working directory when running (so for example, Code::Blocks may execute it as if the .exe file is running from the project directory).

Put the desk.png file in the same directory as the executable, then manually run it -- if it works then, your issue is related to the working directory when debugging.

As a side note, I strongly recommend that you instead find a portable version of Code::Blocks (such as this), because Dev-C++ is a terrible thing to work with.
Was This Post Helpful? 1
  • +
  • -

#3 rethc  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 76
  • Joined: 23-April 12

Re: SDL OpenGL images not loading in DevC++

Posted 03 September 2012 - 10:38 PM

View PostMina-no-Hime, on 03 September 2012 - 07:55 PM, said:

Where is "desk.png" located in relation to the executable file? Because that's what's going to matter in this case -- and different IDEs will output to different folders when building, and others will even change the working directory when running (so for example, Code::Blocks may execute it as if the .exe file is running from the project directory).

Put the desk.png file in the same directory as the executable, then manually run it -- if it works then, your issue is related to the working directory when debugging.

As a side note, I strongly recommend that you instead find a portable version of Code::Blocks (such as this), because Dev-C++ is a terrible thing to work with.


I tried the codeblocks portable you linked before dev-c++ but i couldn't get it to link to the SDL libraries properly.

The program works now, it was just the computer i was working on before couldn't load it
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1