PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

CreateSurface()

I'm trying to Create a surface and I need help.

First off, all the examples have images as a resource, which is fine and I can get the images to display just fine when I do it that way, but I would like to load files from a directory of my choosing, so I tried using

Code:
m_splash.CreateSurface(GDSURFACE_SYSTEMMEMORY, TEXT("splash.png"));


Which, according to the documentation, should load the file from the directory in which the executable resides in, but that does not work. I tried giving the absolute path of

G:\GapiDraw300Eval\samples\win32\Minimal\common\res\splash.png

but that did not work either.

Am I just not understanding this and am doing it wrong? Can someone help me so I can load my images from a specific directory? i.e. given that my executable is in \mygame and my data files are in \mygame\data how can I load the files from the data directory then? I can't seem to make this work.
Code:
CGapiSurface surface;
HRESULT hr = surface.CreateSurface(GDSURFACE_SYSTEMMEMORY, _T("data\\image.png")); if(FAILED(hr)) return hr;


Check the return value.
Actually it will not use the path of the EXE, but the current path:

http://www.gapidraw.com/doc/300/doc-surface-frame.htm
(from the documentation on CreateSurface)
"If pImageFile does not begin with "\" or "x:\", GapiDraw will use the current path and append the image file name"

//Johan
Ok, that's it, I've had it...

G.R., you should create a thread with a subject of "If you are having GD problems..." and a body of nothnig but "CHECK THE RETURN CODE!". Then, Johan, please make that post sticky!

:)

(I'm kidding of course, but you know what, I'm not sure in all seriousness that it would be a bad idea!)
:D
ppcStudios wrote:
Code:
CGapiSurface surface;
HRESULT hr = surface.CreateSurface(GDSURFACE_SYSTEMMEMORY, _T("data\\image.png")); if(FAILED(hr)) return hr;


Check the return value.



Failed with an hr of 0xC8660060. I can't find any reference to that code, so I don't know why it's failing.
Anonymous":251rrvs7]

Found the error code, it says bitmap not found, so what am I doing wrong? Here is what I have...

G:\GapiDraw300Eval\samples\win32\Minimal\xp\Debug\minimal.exe

That's the location of my executable.

G:\GapiDraw300Eval\samples\win32\Minimal\xp\Debug\data\splash.png

Thats the location of my png file.



WHOA. I just figured it out. I guess the way the program is executed in Visual studio is different from simply executing it from the directory itself. Everything seems to work if I execute the program from the directory, but if I run the debugger, it doesn't work. That sucks, but atleast it works I guess.

Anyone know a remedy for that?
Yes, I remember that problem cropping up a while back for me as well. I don't recall what I did about it, but one thing you will want to do I think is find the location of your executable and construct your string accordingly.

I'm sure there's about 50 ways to do it, but here's the code I currently use:

Code:

DWORD getModuleDirectory(HMODULE hModule, LPTSTR szPath, DWORD dwLength) {

DWORD dwLen;
LPTSTR p;
if (0 == (dwLen = GetModuleFileName(hModule, szPath, dwLength))) {
return(0);
}
p = szPath + dwLen;
while (p != szPath) {
if (TEXT('\\') == *--p) {
*(++p) = 0;
break;
}
}
return(p - szPath);

}


Call it with:

TCHAR gameEXEPath[152];
getModuleDirectory(GetModuleHandle(NULL), gameEXEPath, sizeof(gameEXEPath) / sizeof(TCHAR));
Well, that works great. Thanks. But now I can't seem to figure out how to append my filename to the end of directory. I've been doing lots of C# programming lately, so I'm thinking string = string + string, but I don't think it will be that easy because I'm dealing with TCHAR buffers. I've gone all retarded with this lower level stuff. Any hints or tips you can throw my way? hehe...
_tcscat(gameEXEPath, TEXT("filename"));

As a rule, all the functions that work on TCHARs start with _t, so they are pretty easy to find in help. There's _tcscpy, _tcscmp, and so on, all the basic stuff you'll need.

(And don't worry, I do Java all day, so having to think more low-level at night, I know the feeling :) )
fzammetti: Is it ok if I add your code to the GapiDraw 3.01 readme?
http://www.gapidraw.com/doc/300/doc-readme.htm
Absolutely. I don't think I wrote it myself from scratch anyway, so it's probably not mine to give permission for anyway :)

Might this make a good candidate for an addition to GD itself next version?

WHOA. I just figured it out. I guess the way the program is executed in Visual studio is different from simply executing it from the directory itself. Everything seems to work if I execute the program from the directory, but if I run the debugger, it doesn't work. That sucks, but atleast it works I guess.

Anyone know a remedy for that?


the 'start in' directory is specified in the project settings - under the debug tab iirc.