[HGE] can't load resources!

Started by
3 comments, last by sheep19 14 years, 8 months ago
Hello. I started using Haaf's game engine. I'm trying to load a sprite using a resource file. here's my code:

#pragma comment(lib, "hge.lib")
#pragma comment(lib, "hgehelp.lib")

#include <hge.h>
#include <hgesprite.h>
#include <hgeresource.h>

#include "constants.h"

// global variables
HGE *hge = 0;

hgeSprite *s = 0;

// function declarations
bool RenderFunc();
bool FrameFunc();

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
	hge = hgeCreate(HGE_VERSION);

	hge->System_SetState(HGE_FRAMEFUNC, FrameFunc);
	hge->System_SetState(HGE_RENDERFUNC, RenderFunc);
	hge->System_SetState(HGE_WINDOWED, true);
	hge->System_SetState(HGE_USESOUND, false);

	hge->System_SetState(HGE_FPS, constants::FPS);
	hge->System_SetState(HGE_WINDOWED, true);
	hge->System_SetState(HGE_SCREENWIDTH, constants::SCREEN_WIDTH);
	hge->System_SetState(HGE_SCREENHEIGHT, constants::SCREEN_HEIGHT);
	hge->System_SetState(HGE_SCREENBPP, constants::SCREEN_BPP);
	
	if( hge->System_Initiate() )
	{
		hgeResourceManager *manager = new hgeResourceManager("resources.res");
		if( !manager ) exit(-1);

		s = manager->GetSprite("spr");

		if(!s) exit(-2);
	}
	else
	{
		MessageBox(NULL, hge->System_GetErrorMessage(), "Error",
			MB_OK | MB_ICONERROR | MB_APPLMODAL);
	}
	
	delete s;

	hge->System_Shutdown();
	hge->Release();

	return 0;
}
bool RenderFunc()
{
	hge->Gfx_BeginScene();
	hge->Gfx_Clear(0);
	hge->Gfx_EndScene();

	return false;
}

bool FrameFunc()
{
	if( hge->Input_GetKeyState(HGEK_ESCAPE) ) return true;

	return false;
}


The program exits with -2. resources.res

Texture background
{
	filename = story_0.png
}

Sprite spr
{
	texture = background
	rect = 0, 0, 200, 200
}
The image is in the current working directory. Any help?
Advertisement
Are you totally sure the files are in the working directory? Have you set up the debugger so it is so?
It's not a bug... it's a feature!
You should also setup logging so you can see if the engine reports a problem. But, I imagine that Dom_152 is correct and its a file path issue.
RealPath = hge->Resource_MakePath("resources.res");

try this...
Thanks for your help people. I asked the same question on relish games forum and I got a reply that said that the picture and the .res file have to be in executable's directory, not the main.cpp. It works great now!

This topic is closed to new replies.

Advertisement