Page 1 of 2

Converting from Windows GDI to Irrlicht

Posted: Sun Mar 05, 2006 7:50 pm
by Das Gurke
Well, I just discovered Irrlicht and decided this will be the thing to migrate my 2D Game from the Windows GDI. The "drawing" Part of this is extremly easy.

Code: Select all

// Das Feld ist ein freies -> fixed.bmp
			if(Gamefield.pFields[(y * Gamefield.iXSize) + x].iStatus == FIELD_STATUS_FREE)
			{
				// Surface des Bitmaps als StandardSurface einsetzen
				BitBlt(dcBackBuffer,x*FIELD_SIZE,y*FIELD_SIZE,51,51,dcFreeSurface,0,0,SRCCOPY);
			}
But before I overload myself:

How complicated is it to set the engine up in a way that I'll just have to replace this stuff? I had a look in the tutorials and it seemed fairly easy. Or is there anything beyond i should consider?

Posted: Sun Mar 05, 2006 10:41 pm
by r3i
Sorry I don't understand...what kind of actions your game must do?
:oops: sorry

Posted: Mon Mar 06, 2006 8:39 am
by Martins
I am really a novice with Irrlicht, but I think it is very easy to
do wat you want with:
irr::video::IVideoDriver::draw2DImage(const wchar_t * text,
const core::rect< s32 > & position,
video::SColor color,
bool hcenter = false,
bool vcenter = false,
const core::rect< s32 > * clip = 0
)
Your bmp can be easily loaded with:
virtual ITexture* irr::video::IVideoDriver::getTexture ( const c8 * filename )
What I feel is that Irrlicht is the most friendly framework especially for beginners (like myself).

Posted: Mon Mar 06, 2006 2:30 pm
by Das Gurke
r3i wrote:Sorry I don't understand...what kind of actions your game must do?
:oops: sorry
No reason to feel sorry! I will explain myself a little further.

I am programming a Bomberman and divided the gamefield into something like a 2D Chessboard. Every field on this board has a so called "Field_State" which defines what happens if a player touches this field and which graphic has to be rendered.

As you can see my routine draws a surface according to the field type.

Martins

Thanks, if its really as easy as that! Do i have to use the irrlicht draw loop? Probably yes but maybe ... ^^

Posted: Mon Mar 06, 2006 2:43 pm
by r3i
:) now I understand!
Beautiful idea *^^
I think that you must use the loop, because an user must move, so you must update the status of every cell of the field every time the bomberman moves.

You can use Collision or checking only coordinates, but in all the way you must control the bomberman position every time an make some operations.

Do you?

Hope I helped you *^^

Posted: Mon Mar 06, 2006 2:49 pm
by Das Gurke
Huh, maybe we are talking about something different again ^^

The game does exist so far. Movement, Collision System etc is integrated. It just sucks CPU Power like hell, because it does not use hardware acceleration (due to WinGDI). The only thing I want to change is the drawing part. Things like Alpha Channels etc would be too great ;)

If you want to have a look at the game: http://dev.gurxite.de

Edit: Its in german, but that shouldn't be a real trouble ^^

Posted: Mon Mar 06, 2006 9:28 pm
by r3i
uhoa!!!!
Beautiful site!!!
I understand you target.
I suggest to make in main loop because if user send the game in background or pause it, it'll lost the video output... take some tests :)
I know because this is the problem of many splashscreen for games.

Posted: Mon Mar 06, 2006 10:45 pm
by Das Gurke
Yes, at the moment I'm really in trouble with my splashscreens ... But I guess I got the hang out of it, the load screen is perfectly drawn by Irrlicht now.

Next Step, Stepping from Loadscreen into the game ... Lets see how I come along ...

btw:
The page is made using the CMS Joomla, really a great piece of software :D

Posted: Tue Mar 07, 2006 10:03 pm
by r3i
:D CMS!!
I'm implementing it in the web agency where I'm working!!!

Nice... I'll get some idea!
;) www.justweb.it -< I'm here as apprentice

Posted: Wed Mar 08, 2006 11:00 am
by Das Gurke
Just wanted to blow out that I did it :D

Big Thx!

Works just as I wanted it, only a few flaws to clean!

Posted: Wed Mar 08, 2006 11:44 am
by r3i
:D wanna see wanna see!

Posted: Thu Mar 09, 2006 10:54 am
by Das Gurke
Huh, not much to see by now and not quite ready. But sek, I will quickly pack the actual version.

Maybe you can give me another hint:
The Program sucks 90% CPU if not active, 0-3 when active. Any usual mistake that I could have made?

If anyone is interested in Sourcecode or whatever feel free to ask btw, Open Source hooray :D The whole stuff is only commented in german tough :oops:

Graphics can be swapped easily and are normaly not made by me, due to some changes you must take mine now though *g*

http://www.GurXite.de/files/Irr%20BMan%20Shot.rar

Posted: Thu Mar 09, 2006 11:00 am
by r3i
Yeah it sucks because maybe you put it on background but app continue to draw scene.
In your loop ( if you've used one ) check as condition:
while( device->run() ){
if( device->isWindowActive() ) {
//begin scene
//draw
//end scene
}
}

device->run() check if all is running
device->isWindowActive() check if window is active: the app is in foreground
:)

Posted: Thu Mar 09, 2006 11:04 am
by Das Gurke
Not quite :cry:

The Load Screen at the very beginning uses this code.

Code: Select all

while(IrrDevice->run() && IrrDriver)
	{
		// Wir wollen nur was rendern wenn das Fenster aktiv ist
		if (IrrDevice->isWindowActive())
		{
			// Später wichtig für Zeitmessung, eher irrelevant im Intro aber wir sind ja Perfektionisten
			DWORD	dwRenderTime;

			dwRenderTime = GetTickCount();

			// Wer will schon den Mauszeiger sehen?
			IrrDevice->getCursorControl()->setVisible(false);

			// Lasset die Scene beginnen
			IrrDriver->beginScene(true, true, irr::video::SColor(0,0,0,0));

			// Laden wir das Hintergrundbild
			IrrDriver->draw2DImage(tBackground, irr::core::position2d<irr::s32>(g_iXOffsetSplash,0),
												irr::core::rect<irr::s32>(0,0,512,512),
											    NULL , irr::video::SColor(255,255,255,255), true);

			// Lassen wir etwas transparentes um den Cursour entstehen
			irr::core::position2d<irr::s32> m = IrrDevice->getCursorControl()->getPosition();

			IrrDriver->draw2DImage(tCursor, irr::core::position2d<irr::s32>(m.X - 2, m.Y - 2),
											irr::core::rect<irr::s32>(0,0,64,64),
											NULL , irr::video::SColor(255,255,255,255), true );


			// Zeit in ms vergangen
			dwRenderTime = GetTickCount() - dwRenderTime;
	
			// Für diese Zeit CPU an andere Anwendungen abgeben
			if(dwRenderTime < 33)
			{
				Sleep(33 - dwRenderTime);
			}

			// Und da ist die Szene rum *g*
			IrrDriver->endScene();

			// Für Abbruchance sorgen
			if(IsKeyDown(VK_SPACE))
			{
				// Schleife beendet, aber müssen wir das Spielfeld anpassen?
				if(Config.iFullscreen == false)
				{
					// Fenster resize
				}

				// Wir haben geladen -> Gamestate Play
				return (GAMESTATE_PLAY);
				break;
			}
		}
	}
Edit:

Trouble is it sucks MORE CPU if in Background ... [...]

:idea:

Endless Loop? Seeeecond ^^

... OUCH!

Yes, when the window was not active I have created in infinite loop ...

Posted: Thu Mar 09, 2006 11:13 am
by r3i
:)