Iw2D + IwUI

Home / Forums / Marmalade Archive / Iw2D / Iw2D + IwUI
4 replies [Last post]
by: AirplayMM
Status: Offline
Joined: 2012-05-13
Points: 40

Could someone plz give me an example (main loop) for mixing Iw2D and IwUI ?
Right now i use the following:

//... initializations
while(1)
{
s3eDeviceYield(0);
s3eKeyboardUpdate();
s3ePointerUpdate();

IwGetUIController()->Update();
IwGetUIView()->Update(1000/20);

// ... do my logic

// Rendering
IwGxClear(IW_GX_COLOUR_BUFFER_F | IW_GX_DEPTH_BUFFER_F);
// do my Iw2D drawings ...
Iw2DSurfaceShow();
}

by: DGuy
Status: Offline
Joined: 2011-04-06
Points: 4210
Hi,

Hi,

A simplified version of my main loop looks something like this:

NOTE: I used callbacks, set via s3eDeviceRegister() to get keyboard/mouse/touch input.

while( !s3eDeviceCheckQuitRequest() )
{
IwGetUIController()->Update(); // process/handle UI related input

// handle any non-UI related input (using input obtained via callbacks)

// update game logic

Iw2DSurfaceClear( … ); // NOTE: When using Iw2D, should clear the screen like this

// Render Iw2D & IwGx graphics

IwGetUIView()->Update( … ); // update UI view & animation

IwGetUIView()->Render(); // render the UI

Iw2DSurfaceShow(); // NOTE: When using Iw2D, should present the screen like this

s3eDeviceYield(); // Callbacks called during yield if/when needed
}

Hope this helps,
-David

by: mirrorlink
Status: Offline
Joined: 2012-03-14
Points: 160
don't forget

don't forget Iw2DFinishDrawing() to guarantee the drawing order (z-buffer)! (usually, you render the UI after drawing with iw2d)

by: AirplayMM
Status: Offline
Joined: 2012-05-13
Points: 40
Thx for the answers. It looks

Thx for the answers. It looks like that *any* combination will work, so i am looking for the *right* *optimal* way. This is now how i do it:

while(!s3eDeviceCheckQuitRequest())
{
s3eDeviceYield(0);
s3eKeyboardUpdate();
s3ePointerUpdate();

IwGetUIController()->Update();
IwGetUIView()->Update(1000/20); // 1000/20 = 20fps

IwGxClear(IW_GX_COLOUR_BUFFER_F | IW_GX_DEPTH_BUFFER_F);
IwGxSetScissorScreenSpace(VIEW::SCR_X, VIEW::SCR_Y, VIEW::SCR_W, VIEW::SCR_H);
g_game->Draw(); // my 2D drawings ...
Iw2DFinishDrawing();
IwGxClearScissorScreenSpace();

IwGetUIView()->Render();
IwGxFlush();

IwGxSwapBuffers();
}

by: DGuy
Status: Offline
Joined: 2011-04-06
Points: 4210
Hi,

Hi,

When using Iw2D, you should use Iw2DSurfaceShow(), not IwGxSwapBuffers()

From the docs:

"void Iw2DSurfaceShow()

Finish any pending drawing and present the surface. The default surface must be the current drawing surface. This function must be called instead of other Show() functions like s3eSurfaceShow() and IwGxSwapBuffers()."

-David

Latest Posts

Latest Comments

Top Contributors

  • Chris D : 27,010
  • MonRoyals : 26,970
  • Salman : 26,720
  • Jez Hammond : 20,130
  • pjan : 11,150
  • gjw : 10,350
  • Paolo Oliverio : 9,640
  • Beaker_2 : 8,390
  • Kite : 8,210
  • bluescrn : 7,810