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
StoveBacon
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++
Post
by StoveBacon » Sat May 14, 2011 7:26 pm
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
Posts: 76 Joined: Sat Apr 03, 2010 5:08 am
Programming Language of Choice: C++
Post
by PaperDuckyFTW » Sat May 14, 2011 8:04 pm
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
StoveBacon
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++
Post
by StoveBacon » Sat May 14, 2011 8:10 pm
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."
short
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
Post
by short » Sat May 14, 2011 8:50 pm
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
work if your image is in the same directory as your executable?
StoveBacon
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++
Post
by StoveBacon » Sat May 14, 2011 8:51 pm
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
Posts: 101 Joined: Thu Dec 09, 2010 2:13 am
Post
by like80ninjas » Sat May 14, 2011 9:26 pm
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.
short
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
Post
by short » Sat May 14, 2011 9:45 pm
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
StoveBacon
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++
Post
by StoveBacon » Sat May 14, 2011 10:00 pm
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."
short
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
Post
by short » Sat May 14, 2011 10:26 pm
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
StoveBacon
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++
Post
by StoveBacon » Sat May 14, 2011 10:42 pm
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."
short
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
Post
by short » Sat May 14, 2011 10:46 pm
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?
StoveBacon
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++
Post
by StoveBacon » Sat May 14, 2011 10:53 pm
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."
short
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
Post
by short » Sat May 14, 2011 10:56 pm
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?
StoveBacon
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++
Post
by StoveBacon » Sat May 14, 2011 11:00 pm
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."
StoveBacon
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++
Post
by StoveBacon » Sat May 14, 2011 11:01 pm
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."