Sign in to follow this  

[HGE] can't load resources!

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

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?

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

This topic is 3044 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this