Topic: Full GUI

Hi there!

I have a question about a Full GUI system,
I'm gonna describe the different steps for making it :

---------------------------------------------------------------------------------------------
Figure 1 Setup : Simple scene, only one camera, this is just the main game screen (epic drawing skills i know tongue)


PunBB bbcode test


---------------------------------------------------------------------------------------------
Figure 2 Setup : Two scenes ; One with the game and one GUIScene that contain the GUI graphic,
i'm using setCameraLayer to display the GUI graphic

PunBB bbcode test

Result : The interface overlap the main game screen so it's not good.

---------------------------------------------------------------------------------------------
Figure 3 Setup : Everything on a single scene.
The game, two camera, the GUI and a Plane.
The Plane is rendering what Camera 1 see, and i'm using Camera 2 as the main cam

PunBB bbcode test

In Maratis the scene setup looks something like :
PunBB bbcode test



That's working but there's two major problems :

1) isActive(object) doesn't work with that method
2) Sounds. It is not possible to use 3D sounds or sound positionning, forced to make it local

So i'm wondering, is it possible to add something that
makes the Camera 2 gets the Camera 1 proprieties while Camera 2 is the active cam (if you still follow me tongue)

And lastly, is this a correct set-up ? or is theres another solution ?

Re: Full GUI

Hi, I get your problem with sound with the render to texture option.

But I don't understand why you can't use the first setup ?
What do you mean "The interface overlap the main game screen so it's not good." ?

Re: Full GUI

anael wrote:

But I don't understand why you can't use the first setup ?
What do you mean "The interface overlap the main game screen so it's not good." ?

The first method is perfect for small HUDs or sliding menus but for a full GUI,
it's hiding alot of the game screen, if i exaggerate, basically the result is :

PunBB bbcode test

Not sure i want that tongue

I think it might be ok for a game where the camera doesn't move, so maybe i can just move camera back a little, play with the FOV and it should be fine

However for a moving camera that's not gonna work

Re: Full GUI

ok, I understand.

mathematically, with the first method, a larger FOV will produce the same result, even with a moving cam,
the only negative point is that a part of the drawing will be rendered for nothing.

about the sound problem with the render to texture, I don't have a solution that can be done in lua,
the only way I can see is to make a custom game class with a plugin. If you can manage to compile it yourself,
I can make you the code, it's not very complicated.

Re: Full GUI

That's right i understand what you mean,  but i'm still prefering the second option, as hiding some part of the screen could lead to more trouble (for example let's say a turret that starts shooting when it's visible, it will start shooting even when it's hide by the interface)

And thanks for you proposal, i can *try* to compile tongue but will it fix the isActive(object) too ?

Re: Full GUI

there is no reason I see that would make isActive not working, maybe you mean "isVisible" ?
because isVisible depends on the active view, in this case it tells you if the object is visible from Camera 2 and not camera 1 as expected.

By making a plugin, we can use a smaller sub-window (viewport) without using render to texture so the active camera will be camera 1.

Re: Full GUI

Oops my bad, it was "isVisible" indeed, sorry !
Your plugin would be the ideal solution then smile
(although i will probably need some instructions)

Re: Full GUI

ok smile

did you ever tried to compile this example ?
http://www.maratis3d.org/?p=563

because the code you need will be a minor modification of this.

Re: Full GUI

Honestly not, C++ stuff has always freak me out
But it's ok i'm gonna try to compile it smile

Re: Full GUI

tell me if something is not going well,
it should be ok, there is a visual studio project in the example

- install visual studio (version 2005 works, express edition is free, I'm not sure with the more recent versions)
- open the .sln file
- check the paths in the project properties
OR be sure the .sln file access maratis SDK folder this way : "..\..\..\..\SDK"
OR open the vcproj file with a text editor and replace "..\..\..\..\SDK" by your own path
- compile in "release" mode

Re: Full GUI

Alright, i used 2010 express edition (i remember having trouble with 2005 version, that was always missing window.h)

So, opening the .sln file makes the program crash, but it's ok with the vcproj (it just ask for converting it)

Weirdly, setting paths in the Game header (in the tree view), was not enough,
i had to manually enter paths for every .cpp files, after that, it worked wink

(ps. I didn't find the "release" mode option, where is this ? (in french if possible tongue))

Re: Full GUI

"release" should be somewhere in the top bar,
usually a project is in "debug" mode by default, if you see "debug" somewhere, clic on it to change to release.

when you compile, the project should create a file named "Game.dll"
if it's not done by visual studio, copy it inside the maratis project folder

Re: Full GUI

Ok i get it... it was one of the most obvious item in the top bar *facepalm*
Well thank you, everything's fine now smile

Re: Full GUI

so the example run fine with the GUI and the rotating box and all ?

if yes, now you can replace the code of MGame.cpp by this :

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// SimpleGamePlugin
// MyGame.cpp
// 
// Code : Anael Seghezzi
/////////////////////////////////////////////////////////////////////////////////////////////////////////

#include "MyGame.h"


// constructor
MyGame::MyGame(void):
MGame()
{}

// destructor
MyGame::~MyGame(void)
{}


// GUI scene and objects
MScene * GUIScene = NULL;


// custom begin scene
void MyGame::onBeginScene(void)
{
    MGame::onBeginScene(); // call the default MGame begin scene
    
    MEngine * engine = MEngine::getInstance(); // get the engine instance
    MLevel * level = engine->getLevel(); // get the current level
    
    // get GUI scene
    GUIScene = level->getSceneByName("GUIScene");
}

// custom update
void MyGame::update(void)
{
    // custom GUI
    if(GUIScene) // check if the scene exist
    {
        // update GUI scene
        GUIScene->update();
        GUIScene->updateObjectsMatrices();
    }
    
    MGame::update(); // call the default MGame update (update current scene physics, animations, script... as done by default)
}

// custom draw
void MyGame::draw(void)
{
    MEngine * engine = MEngine::getInstance(); // get the engine instance
    MRenderingContext * render = engine->getRenderingContext(); // get the rendering context
    
    // use a smaller viewport for the current scene
    int viewport[4];
    render->getViewport(viewport);
    
    int marginX = viewport[2]*0.1f; // create a 10% margin of the current screen width : change this for your game
    int marginY = viewport[3]*0.1f; // create a 10% margin of the current screen height : change this for your game
    render->setViewport(viewport[0]+marginX, viewport[1]+marginY, viewport[2]-marginX*2, viewport[3]-marginY*2);

    MGame::draw(); // call the default MGame draw (this will draw the current scene as done by default)
    
    // restore the viewport
    render->setViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
    
    
    // custom GUI
    if(GUIScene) // check if the scene exist
    {
        if(GUIScene->getCamerasNumber() > 0) // check if there is a camera in the GUI scene
        {
            MOCamera * camera = GUIScene->getCameraByIndex(0); // get the first camera
            
            render->clear(M_BUFFER_DEPTH); // clear depth buffer (to not be affeted by the current scene)
            
            // draw GUI on top
            camera->enable();
            GUIScene->draw(camera);
        }
    }
}

- Then use your own game instead of the example or copy the dll in your game directory.
- name your GUI scene "GUIScene" or change the reference name in Game.cpp
- don't use render to texture or scene layer for the gui (it's all done by the cpp)

The code create a smaller viewport to render the current scene and draw the scene named "GUIScene" on top.

The part dealing with the viewport size is this :

int marginX = viewport[2]*0.1f; // create a 10% margin of the current screen width : change this for your game
int marginY = viewport[3]*0.1f; // create a 10% margin of the current screen height : change this for your game

Et voila, a custom game plugin, you'll see it's no so complicated once you understand c/c++ syntax.
In c++ you can access the engine directly, so anything can be done.

Re: Full GUI

That's working great! thanks you!

But i noticed the game window is always centered,
to make it more usable, could it be possible to set-up
4 margins and make the game screen fit inside it ? (dont know if that's realistic)
or adjust the game window position with (X, Y, width, height) values ?

that would allow to make interfaces like This one or This one

Oh and it doesn't worked when using "release" mode (had alot of errors popping up), only debug mode worked

Et voila, a custom game plugin, you'll see it's no so complicated once you understand c/c++ syntax.
In c++ you can access the engine directly, so anything can be done.

Yeah it makes want to investigate that stuff, but... i already know how it will end tongue (bad)

Re: Full GUI

Sure, you can do this if you still use percents (if the screen need to adapt to the resolution) :

    int marginLeft = viewport[2]*0.1f;
    int marginRight = viewport[2]*0.1f;
    int marginTop = viewport[3]*0.1f;
    int marginBottom = viewport[3]*0.1f;

    render->setViewport(
           viewport[0]+marginLeft,
           viewport[1]+marginBottom,
           viewport[2]-marginRight-marginLeft,
           viewport[3]-marginBottom-marginTop
    );

or if you want to enter pixel coords direcly :

    int X = 10; // pos x
    int Y = 10; // pos y
    int W = 500; // width
    int H = 300; // height

    render->setViewport(
           X,
           viewport[3]-H-Y,
           W,
           H
    );

Re: Full GUI

Outstanding big_smile works like a charm ! Many Thanks wink

Re: Full GUI

I am trying to do a GUI myself now, and I am running into all sorts of snags. sad

Re: Full GUI

Tutorial Doctor wrote:

I am trying to do a GUI myself now, and I am running into all sorts of snags. sad

What's going on?

Re: Full GUI

Hi Vegas. Trying to see how to go about making an easy to use GUI system for the starter pack.

Right now I just have an orthographic camera in a separate scene, and am using enableCamerLayer to display it over a camera. The main issue is positioning things over the camera at a precise point.

I figured I would have to use getWindowScale also so that things are positioned relative to the window size.

What does renderToTexture do for your GUI?

I want to make it easily editable for beginning Maratis users (no complicated setup).

Re: Full GUI

I want to make it easily editable for beginning Maratis users (no complicated setup).

For a HUD with no interactions,
if you want to display some informations like in FPS games, using camera layering is enough,
if you want a full interface, go with Anael's method, even if you need VS, you can easily set up the window exactly where you want to

But for a clickable interface, when we will be able to use physic detection from one scene to another,
it will be very easy but for now it will be quite bulky (could work with a set up like in my first post figure 3)

The main issue is positioning things over the camera at a precise point.

I have a blender file that may help you - i hope i didn't deleted/modified it - keep you in touch

for the WindowScale unfortunately i never made tests with that stuff

Re: Full GUI

Here's a project and it's dll, a blender file and a gimp file. containing all you need for an 1024x768 interface (but nothing else than THIS resolution) 

The pane on the GUIScene will totally fit what the camera sees but.. dont go full screen nor increase window size >.<

If you want to make your own interface with anael's method,

Let's say this is your interface (grey area for the UI, transparent area for the game) :

PunBB bbcode test

First move your cursor at the extreme left and top of the transparent area (the red pixel)
these are X and Y position of your game window

PunBB bbcode test

Then select the whole transparent area and take note of the width/height

PunBB bbcode test

put all the values in the code ;

    int X = 10; // pos x
    int Y = 10; // pos y
    int W = 500; // width
    int H = 300; // height

    render->setViewport(
           X,
           viewport[3]-H-Y,
           W,
           H
    );

compile, run game ; it's gg.

Hope it helps

Re: Full GUI

When I try to open the project, it says the program can't run because MSVCR100D.dll is missing from my computer.

It tells me to re-install the program to fix the problem.

Re: Full GUI

A great classic !

you will get that dll for sure if you install VS2010 (don't know about the others VS)
or maybe this will work : http://www.microsoft.com/en-us/download … px?id=5555