Page 1 of 1

HGE small demo #2: using images from the DataSection

Posted: Thu Jul 10, 2008 2:41 am
by byo
Hi, guys.

This would be another tiny example on how to include images in the executable and use them with HGE. Replace the #PROJECT_PATH and the image file at will.

Code: Select all

IncludeFile "..\HGEWrapper_Include.pbi"

Structure sprite
	x.f
	y.f
	w.l
	h.l
	speed.f
	sprite.l
	tex.l
EndStructure

#PROJECT_PATH = "C:\Purebasic\HGE\Projeto\"
#SCREEN_WIDTH = 320
#SCREEN_HEIGHT = 240

Global img.sprite

ProcedureCDLL frameFunc()  
	If hge_Input_GetKeyState(#HGEK_ESCAPE)
		ProcedureReturn #True
	EndIf

	ProcedureReturn #False    
EndProcedure

ProcedureCDLL renderFunc()
  hge_Gfx_BeginScene(#Null)
  
  hge_Gfx_Clear(0)
  hge_Sprite_Render(img\sprite, #SCREEN_WIDTH/2-img\w/2, #SCREEN_HEIGHT/2-img\h/2)  
  
  hge_Gfx_EndScene()
  
  ProcedureReturn #False
EndProcedure

hge_Create(#HGE_VERSION)
hge_System_SetStateBool(#HGE_WINDOWED, #True)
hge_System_SetStateString(#hge_LOGFILE, #PROJECT_PATH + "byo_demo.log")
hge_System_SetStateFunc(#HGE_FRAMEFUNC, @frameFunc())
hge_System_SetStateFunc(#hge_RENDERFUNC, @renderFunc())
hge_System_SetStateBool(#hge_SHOWSPLASH, #False)
hge_System_SetStateString(#HGE_TITLE, "byo demo")
hge_System_SetStateBool(#HGE_USESOUND, #False)
hge_System_SetStateInt(#hge_SCREENWIDTH, #SCREEN_WIDTH)
hge_System_SetStateInt(#hge_SCREENHEIGHT, #SCREEN_HEIGHT)
hge_System_SetStateInt(#hge_SCREENBPP, 32)

If hge_System_Initiate()
	img\w = 48
	img\h = 39
	img\tex = hge_Texture_Catch(?img1, ?img1End-?img1)
	img\sprite = hge_Sprite(img\tex, 0, 0, img\w, img\h)
	
	hge_System_Start()
	
	hge_System_Shutdown()
	hge_Release()
EndIf
	
	
DataSection
	img1: IncludeBinary "shuttle.png" : img1End:
EndDataSection

Posted: Thu Jul 10, 2008 5:57 am
by Rook Zimbabwe
Great demo BYO!

I am going to say something though... as I read this... we probably don't need HGE.

I haven't seen one thing that Demivec and I aren't doing in pure PB with our particle engine.

OK 1 thing so far... the gravity in my silly plinko game... but heck I learned how to do that my second week with Blitz3D! I know I could do that here...

{{goes off to implement!}}

Posted: Thu Jul 10, 2008 1:08 pm
by untune
More good stuff - I was having a lot of fun messing with the first example last night byo, changing vertex colours etc to simulate lighting. It's all so simple!

I'm at work at the mo but I'll test this one tonight. It would be cool if neotoma or somebody could put a function in the dll to return a pointer to the D3D interface - that way we could probably get under the bonnet and add other effects directly and write our own functions using the D3D API - lighting and suchforth.

Would it be possible?

Posted: Thu Jul 10, 2008 4:38 pm
by byo
Rook Zimbabwe: Indeed. I agree with you that Purebasic builtin 2D game commands are as solid or maybe even more. But HGE has some really fast displace/resize/stretch routines which are really easy to achieve with one or two commands. Take a look at this demo:

http://relishgames.com/forum/viewtopic.php?t=3924


untune: It's a nice idea. Maybe someday when the engine becomes Directx 9.0 fueled we'll have some additions since DirectDraw is getting obsolete with time. I'd take a look at HGE forum because there are some addons/libraries there that could be wrapped in Purebasic. Just a thought. :wink:

Posted: Thu Jul 10, 2008 5:06 pm
by Rook Zimbabwe
See... thats what I want to know! 8) Thanks byo!

Posted: Thu Jul 10, 2008 6:04 pm
by untune
byo wrote:untune: It's a nice idea. Maybe someday when the engine becomes Directx 9.0 fueled we'll have some additions since DirectDraw is getting obsolete with time. I'd take a look at HGE forum because there are some addons/libraries there that could be wrapped in Purebasic. Just a thought. :wink:
Well it's currently DX8 powered so everything in HGE is already 3D and hardware accelerated rather than using the old fashioned DirectDraw interface (I'm not sure if anything still uses DX7! :P)

I've been reading that quite a few people have already shifted it over to DX9 (as the source code is freely available and using the DX9 commands is as simple as changing DX calls from their current DX8 renditions into their DX9 counterparts) and there will probably be a branch off the source which uses DX9 (some people are strict about it staying DX8 and therefore more compatible with older hardware, which is one of it's most important features)

Think about what that would open up though - the use of DX9 technology like advanced shaders and other cool effects. It would be fantastic! And I've done some work (a few years back but still, it's all possible in PB) with the D3D API, I'm pretty sure a pointer to the interface that HGE is using is all that you'd need to get access to the low level D3D functions... making the whole thing even more versatile.

Posted: Thu Jul 10, 2008 10:41 pm
by byo
The links below can be a good read while the official DX9 port isn't yet done:

http://relishgames.com/forum/viewtopic. ... hlight=dx9

http://relishgames.com/forum/viewtopic.php?p=11616

Although unfortunately the forum is pretty much dead and the developers forum hasn't been updated since March 2007. :?