• Advertisement
Sign in to follow this  

you know this one

This topic is 4432 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

Hi. Programs are getting too big for just "WinMain.cpp" and "WinMain.h"... I have a LoadTexture() function (shown below) that I have stored in my "Graphics.cpp" and listed in "Graphics.h". When I call it from within "Game.cpp", it DOES compile, but fails when I run the program. If I move the entire function into "Game.cpp", it'll run. Any thoughts? Thanks.
LPDIRECT3DTEXTURE9 LoadTexture(char *filename, D3DCOLOR transcolor)
{
	//the texture pointer
	LPDIRECT3DTEXTURE9 texture = NULL;
    
	//the struct for reading bitmap file info
	D3DXIMAGE_INFO info;
    
	//standard Windows return value
	HRESULT result;
	//TCHAR * DXGetErrorString9(HRESULT hr);


	//get width and height from bitmap file
	result = D3DXGetImageInfoFromFile(filename, &info);
	if (result != D3D_OK){
		const char *MyString = DXGetErrorString9(result);
		MessageBox(g_hWnd, MyString, "Error", MB_OK);
		return NULL;
	}

	//create the new texture by loading a bitmap image file
	D3DXCreateTextureFromFileEx( 
	    g_D3DDevice,         //Direct3D device object
	    filename,            //bitmap filename
	    info.Width,          //bitmap image width
	    info.Height,         //bitmap image height
	    1,                   //mip-map levels (1 for no chain)
	    D3DPOOL_DEFAULT,     //the type of surface (standard)
	    D3DFMT_UNKNOWN,      //surface format (default)
	    D3DPOOL_DEFAULT,     //memory class for the texture
	    D3DX_DEFAULT,        //image filter
	    D3DX_DEFAULT,        //mip filter
	    transcolor,          //color key for transparency
	    &info,               //bitmap file info (from loaded file)
	    NULL,                //color palette
	    &texture );          //destination texture

	//make sure the bitmap texture was loaded correctly
	if (result != D3D_OK)
	    return NULL;

	return texture;
}

[edit: added source tags -SiCrane]

Share this post


Link to post
Share on other sites
Advertisement
To span programs across multiple files in C++/C:
Move all relevant constants, public function prototypes, etc. to the file's .h.
Include that .h file inside of all .cpp files where functions from the previous file are used
Insure your compiler will compile and link the files together (this is dependent on the compiler).

Of course, someone will also point you to a link on how to do it, but I don't have one handy. Google for the answer.

Share this post


Link to post
Share on other sites
~OP~

PROBLEM SOLVED! Now I know how to use multiple header and source files correctly. I must have skipped the book that fully explained this. Probably programming101. lol :-)

Thank you guys very, very much!

Share this post


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

  • Advertisement