Jump to content
  • Advertisement
Sign in to follow this  
gav86

directX n00b query #0001

This topic is 4835 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

OK well here goes! You all convinced me to give it more of a shot, so you can deal with my questions! First up: I'm trying to load a bitmap to a surface and display it to the screen. I *think* I've narrowed down the problem to the following function call:
squaresSurface = getSurfaceFromBitmap("squares.bmp");
the definition for the function getSurfaceFromBitmap() is as follows:
IDirect3DSurface9* getSurfaceFromBitmap(std::string filename)
{
	IDirect3DSurface9* surface;
	D3DXIMAGE_INFO imageInfo;

	// Get the width and height info from this bitmap
	hResult = D3DXGetImageInfoFromFile(filename.c_str(), &imageInfo);
	if (FAILED (hResult))
	{
		MessageBox(NULL, "failed getImageInfoFromFile", "error", MB_OK);
		return NULL;
	}

	hResult = pd3dDevice->CreateOffscreenPlainSurface(imageInfo.Width, imageInfo.Height, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &surface, NULL);
	if (FAILED(hResult))
		return NULL;

	hResult = D3DXLoadSurfaceFromFile(surface, NULL, NULL, filename.c_str(), NULL, D3DX_DEFAULT, 0, NULL);
	if (FAILED(hResult))
		return NULL;

	return surface;
}
Basically the first if(FAILED(hResult)) statement, under the call to D3DXGetImageInfoFromFile(), always returns true. The image is in the same directory as the .exe, and it has no properties such as "archived" (this has caused me a problem in SDL before) the image is a 24bit .bmp from photoshop. Thanks in advance, -gav

Share this post


Link to post
Share on other sites
Advertisement
Hi,

Have you checked that nothing is changing the current working directory earlier in your code? (You can check with _getcwd())

EDIT: Also just noticed that if the "loadSurfaceFromFile" function fails you should free the previously created surface with a surface->Release() call. (or use a COM aware smart pointer).

Mike.

Share this post


Link to post
Share on other sites
Thanks for the reply,

I'm not sure I fully understand you .. . my working knowledge with C++ is fairly limited, although most programming "concepts" i'm familiar with.. . if that makes sense?

Do you think you could try to describe as though you were talking to someone a little less experienced?

-thanks.

Share this post


Link to post
Share on other sites
Sure.

Each running program has a "Current Working Directory" (or CWD). This is simply the directory where file operations that do not specify a full path will occur. The initial CWD of an app is usually the directory that the app is stored in but it may not be if, for example, you are running your app from within VisualStudio.

For example, if you have a program foo.exe that lives in the folder C:\bar and you execute foo and if runs fopen("data.txt","r") or whatever the OS will look for the file "data.txt" within the directoy C:\bar, since that will be the CWD.

Things I would check: If your app is running from within VisualStudio go to the projects properties dialog and under "Debug" set the working directory to what you want it to be.

In regards to my initial post with checking that the CWD has not been changed prior to you load function being called, I would not worry - If you were not aware of the fact it could be changed you most likely haven't changed it (it has to be done explicitly).

If you are sure that the file being loaded exists I'm not sure what else it could be. You could try specifying an absolute path just to see if something is messing with the CWD or something (e.g. "C:\bar\image.bmp")

Hope this helps,

Mike.

Share this post


Link to post
Share on other sites
Just had another thought: Make sure Photoshop is saving the BMP as an uncompressed BMP if you get the option - It could be that D3DX can't handle compressed BMP files.

Share this post


Link to post
Share on other sites
hmm thanks,

the file is not compressed...

I checked the working directory - currently the field is empty.

I tried changing it to the folder where the .exe & .bmp both are, but received an error when i tried to run the program, so changed it back to nothing.

I'll upload a copy of the entire .cpp file perhaps there's something else i've overlooked.

Share this post


Link to post
Share on other sites
OK, I've taken a look and made a few (small) changes and now it works fine for me:

http://members.gamedev.net/mikesspace/gav86_winmain.cpp

Basically getImageInfo worked no problems on my machine, but there where a couple of other things that I changed, mainly to do with releasing unreleased D3D objects and changing the surface's memory pool from SYSTEMMEM to DEFAULT (stretchRect requires surfaces to be in the DEFAULT pool).

Give it a try and see if it works on your machine. Fingers crossed!

VC Related:
In which directory are you putting your bmp? If it is in the project directory then fine, but if it is in the "Debug" or "Release" directory then you should move it into the project directory as this is the default working directory for VC (when you run it through VC).

Mike.

Share this post


Link to post
Share on other sites
thanks, that version you made works fine I'll look it over and figure out where I went wrong..

Also - it goes to show just how "great" the book i'm working from is, it never even mentioned that I have to release a surface once i'm finished with it!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!