Need help: Loading images from certain paths

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

User avatar
StoveBacon
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 98
Joined: Mon Sep 20, 2010 6:09 pm
Favorite Gaming Platforms: PC Xbox360 SNES N64
Programming Language of Choice: c++

Need help: Loading images from certain paths

Post by StoveBacon »

I'm getting back into programming so instead of using Allegro, because I know of its limited capabilities, I switched to SFML. I want to know how to load an image from my graphics folder which is in the projects folder. Heres the structure. Documents>Project>Project>Graphics|debug etc... This is what I have tried..

Code: Select all

Image.LoadFromFile("Graphics/test.png");
Any help would be appreciated... I know it's a very stupid question.
SeaNanners wrote:"I shall be Vince Bonesteel and you will be....Rick McLightning!"
Day[9] wrote:"Read a book to children. Mass genocide. Lunch. The life of Dr. Seuss himself."
PaperDuckyFTW
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 76
Joined: Sat Apr 03, 2010 5:08 am
Programming Language of Choice: C++

Re: Need help: Loading images from certain paths

Post by PaperDuckyFTW »

Place the folder which holds the graphics inside the same folder as the .exe, much like you need to place the .dll in the same directory as the .exe

So for example, cause im bored
Documents > Projects > Awesome Game > Debug > game.exe
-------> makefile
-------> neededlibs.dll
------->Graphics
----->test.png
User avatar
StoveBacon
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 98
Joined: Mon Sep 20, 2010 6:09 pm
Favorite Gaming Platforms: PC Xbox360 SNES N64
Programming Language of Choice: c++

Re: Need help: Loading images from certain paths

Post by StoveBacon »

So then I would do the

Code: Select all

Image.LoadFromFile("Graphics/test.png");
? That still didn't work, the command prompt said unable to open file.
SeaNanners wrote:"I shall be Vince Bonesteel and you will be....Rick McLightning!"
Day[9] wrote:"Read a book to children. Mass genocide. Lunch. The life of Dr. Seuss himself."
User avatar
short
ES Beta Backer
ES Beta Backer
Posts: 548
Joined: Thu Apr 30, 2009 2:22 am
Current Project: c++, c
Favorite Gaming Platforms: SNES, PS2, SNES, SNES, PC NES
Programming Language of Choice: c, c++
Location: Oregon, US

Re: Need help: Loading images from certain paths

Post by short »

KeithStoffel wrote:So then I would do the

Code: Select all

Image.LoadFromFile("Graphics/test.png");
? That still didn't work, the command prompt said unable to open file.
Does

Code: Select all

Image.LoadFromFile("./test.png");
work if your image is in the same directory as your executable?
My github repository contains the project I am currently working on,
link: https://github.com/bjadamson
User avatar
StoveBacon
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 98
Joined: Mon Sep 20, 2010 6:09 pm
Favorite Gaming Platforms: PC Xbox360 SNES N64
Programming Language of Choice: c++

Re: Need help: Loading images from certain paths

Post by StoveBacon »

I'm still getting the unable to open file error
SeaNanners wrote:"I shall be Vince Bonesteel and you will be....Rick McLightning!"
Day[9] wrote:"Read a book to children. Mass genocide. Lunch. The life of Dr. Seuss himself."
like80ninjas
Chaos Rift Regular
Chaos Rift Regular
Posts: 101
Joined: Thu Dec 09, 2010 2:13 am

Re: Need help: Loading images from certain paths

Post by like80ninjas »

If the location is project/project/graphics/file.png
then this should work "graphics/file.png", assuming you are running the game from your compiler. If you are running the exe from the release or debug folder (i'm assuming you are using VC ) you should add your graphics folder to those folders as well.
User avatar
short
ES Beta Backer
ES Beta Backer
Posts: 548
Joined: Thu Apr 30, 2009 2:22 am
Current Project: c++, c
Favorite Gaming Platforms: SNES, PS2, SNES, SNES, PC NES
Programming Language of Choice: c, c++
Location: Oregon, US

Re: Need help: Loading images from certain paths

Post by short »

What does

Code: Select all

char* buf = (char*) malloc( sizeof(char) * 1000);
getcwd(buf, 1000);
fprintf(stdout, "cdir %s \n", buf);
display?

edit: with microsoft compilers I think you need to use _getcwd instead of getcwd
My github repository contains the project I am currently working on,
link: https://github.com/bjadamson
User avatar
StoveBacon
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 98
Joined: Mon Sep 20, 2010 6:09 pm
Favorite Gaming Platforms: PC Xbox360 SNES N64
Programming Language of Choice: c++

Re: Need help: Loading images from certain paths

Post by StoveBacon »

getcwd/_getcwd identifier not found.
SeaNanners wrote:"I shall be Vince Bonesteel and you will be....Rick McLightning!"
Day[9] wrote:"Read a book to children. Mass genocide. Lunch. The life of Dr. Seuss himself."
User avatar
short
ES Beta Backer
ES Beta Backer
Posts: 548
Joined: Thu Apr 30, 2009 2:22 am
Current Project: c++, c
Favorite Gaming Platforms: SNES, PS2, SNES, SNES, PC NES
Programming Language of Choice: c, c++
Location: Oregon, US

Re: Need help: Loading images from certain paths

Post by short »

what OS are you on? If your windows I think you need to include direct.h, on unix/osx I think you need unistd.h
My github repository contains the project I am currently working on,
link: https://github.com/bjadamson
User avatar
StoveBacon
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 98
Joined: Mon Sep 20, 2010 6:09 pm
Favorite Gaming Platforms: PC Xbox360 SNES N64
Programming Language of Choice: c++

Re: Need help: Loading images from certain paths

Post by StoveBacon »

cdir c:\users\user\documents\project\project\project

That is the output in the console.
SeaNanners wrote:"I shall be Vince Bonesteel and you will be....Rick McLightning!"
Day[9] wrote:"Read a book to children. Mass genocide. Lunch. The life of Dr. Seuss himself."
User avatar
short
ES Beta Backer
ES Beta Backer
Posts: 548
Joined: Thu Apr 30, 2009 2:22 am
Current Project: c++, c
Favorite Gaming Platforms: SNES, PS2, SNES, SNES, PC NES
Programming Language of Choice: c, c++
Location: Oregon, US

Re: Need help: Loading images from certain paths

Post by short »

KeithStoffel wrote:cdir c:\users\user\documents\project\project\project

That is the output in the console.
Is that the same directory your executable is in?
My github repository contains the project I am currently working on,
link: https://github.com/bjadamson
User avatar
StoveBacon
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 98
Joined: Mon Sep 20, 2010 6:09 pm
Favorite Gaming Platforms: PC Xbox360 SNES N64
Programming Language of Choice: c++

Re: Need help: Loading images from certain paths

Post by StoveBacon »

exe is in: Documents>project>project>debug
SeaNanners wrote:"I shall be Vince Bonesteel and you will be....Rick McLightning!"
Day[9] wrote:"Read a book to children. Mass genocide. Lunch. The life of Dr. Seuss himself."
User avatar
short
ES Beta Backer
ES Beta Backer
Posts: 548
Joined: Thu Apr 30, 2009 2:22 am
Current Project: c++, c
Favorite Gaming Platforms: SNES, PS2, SNES, SNES, PC NES
Programming Language of Choice: c, c++
Location: Oregon, US

Re: Need help: Loading images from certain paths

Post by short »

KeithStoffel wrote:exe is in: Documents>project>project>debug
Try putting your image file in Documents>projects>projects>resources>test.png

Code: Select all

Image.LoadFromFile("../resources/test.png");
is that working for you?
My github repository contains the project I am currently working on,
link: https://github.com/bjadamson
User avatar
StoveBacon
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 98
Joined: Mon Sep 20, 2010 6:09 pm
Favorite Gaming Platforms: PC Xbox360 SNES N64
Programming Language of Choice: c++

Re: Need help: Loading images from certain paths

Post by StoveBacon »

Well, there is no more unable to load file error, but I can't see the image, but that is more or less something probably wrong in my code that I will be able to figure out myself. Thanks for your help!!
SeaNanners wrote:"I shall be Vince Bonesteel and you will be....Rick McLightning!"
Day[9] wrote:"Read a book to children. Mass genocide. Lunch. The life of Dr. Seuss himself."
User avatar
StoveBacon
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 98
Joined: Mon Sep 20, 2010 6:09 pm
Favorite Gaming Platforms: PC Xbox360 SNES N64
Programming Language of Choice: c++

Re: Need help: Loading images from certain paths

Post by StoveBacon »

Ah yes, clearing the buffer before drawing it tends to not show anything.
SeaNanners wrote:"I shall be Vince Bonesteel and you will be....Rick McLightning!"
Day[9] wrote:"Read a book to children. Mass genocide. Lunch. The life of Dr. Seuss himself."
Post Reply