• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

## Recommended Posts

jollyjeffers    1570
hi all, I''m trying to do something that I thought was immensly simple - but its proven to be a complete nightmare I wanted to do something like:
iBackgroundTex = pGFX->CreateImageFor2D( "\Graphics\Splash.bmp" );
such that I could load a texture stored in a sub-folder (Graphics would be directly below the executables "home"). However, it throws exceptions every time I try that, the following works:
iBackgroundTex = pGFX->CreateImageFor2D( "Splash.bmp" );
I''m guessing its something to do with path-relative filenames etc... I couldn''t find anything about that in either my C or C++ books. I get compiler warnings for "G" and "S" being invalid escape symbols, is this it? is the compiler somehow corrupting my string? I tried with "\\Graphics\\Splash.bmp", but it made no difference. any hints?! please Jack DirectX 4 VB: All you need for multimedia programming in Visual Basic Formula 1 Championship Manager, My Game Project.

##### Share on other sites
NE1    122
Use double back-slash "\\" like this:

iBackgroundTex = pGFX->CreateImageFor2D( "\\Graphics\\Splash.bmp" );

iBackgroundTex = pGFX->CreateImageFor2D( "\Graphics\Splash.bmp" );

##### Share on other sites
CraZeE    217
for starters,a nice practice is to directly use forward slashes... its unix-frenly. anyway, to ur immediate problem i think it is indeed ur path specification.

when u specified "\Graphics\Splash.bmp" i dun think ur making the program search in the current folder... instead the first slash may imply the root. try appending a "." like this:
 "./Graphics/Splash.bmp"

however, IF that works, it''s not always guaranteed to do it correctly. remember windows links? notice the "working directory" setting? That can alter where the ''current'' directory points to. A better method wold be to use a function to get the executables path and work it out from there. Can''t rememebr the funciton though... help anyone?

##### Share on other sites
Guest Anonymous Poster
Uhm did you read the post at all?

It should work. Try using ''/'' instead of ''\\''. That''s what I do.

path = "data/sheepbeard.bmp"

##### Share on other sites
Dreamforger    122
like you aleady guessed you need the double backslashes. But thats probably not the problem.

If you program resides in
C:\myApps\theOne

and the graphics are in
C:\myApps\theOne\Graphics

your path should not start with a \ else it's resolve relative to the root of the drive. Independant of where you call your program, the path you give in your post resolves to
C:\Graphics\Splash.bmp
if the app was launched anywhere on C:

So just drop the first backslash and slash everything else double
Graphics\\Splash.bmp
and you have a path relative to your excutable

EDIT: whoooha 3 answers within a minute and another one who wasn't there when I started writing :-)
---------------------------
I may be getting older, but I refuse to grow up

[edited by - Dreamforger on May 26, 2003 10:15:55 AM]

##### Share on other sites
The way you are doing it, you need double backslashes \\ . The reason is because a single slash is used to denote escape sequences e.g. \n is for a new line or \t for a TAB etc.

It "thinks" your trying to use escape sequences \G and \S which don't exist (probably). Also, your path should just start with the folder name if it is relative e.g. "Graphics\\Splash.bmp" or with the drive letter if it is absolute e.g. "C:\\Graphics\\Crap.bmp".

[edited by - Ethereal on May 26, 2003 10:57:34 AM]

##### Share on other sites
jollyjeffers    1570
thanks for all the replies as always GDNet is all-helpful!

the final line of code that did the trick:

  iBackgroundTex = pGFX->CreateImageFor2D( "Graphics/Splash.bmp" );

I did consider using the / instead \ notation, but I thought that was unix and that \ was windows... or does that not matter inside code?

cheers,
Jack

DirectX 4 VB: All you need for multimedia programming in Visual Basic
Formula 1 Championship Manager, My Game Project.