GUI-Layer dimensions behave totally weird

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Notion
Posts: 9
Joined: Mon Mar 20, 2017 11:00 pm

GUI-Layer dimensions behave totally weird

Post by Notion »

Hey everyone,

sorry for the kinda "ranty" title, but i spend 5 hours now just trying to figure out how the GUI-Layer dimensioning works and came to the conclusion that its either totally screwed up, or totally not documented.

Basically my problem is: things dont show up, as long as I dont give them HUUUUUUGE dimensions. The text that says "Health:" needs dimensions of at least 1000*1000 or it either wont show up at all, or is some blurry vertical line. buttons for some reasons do show up if positioned in the upper left, but dont show up if positioned anywhere else.
Any help? Known issue? Problem with OpenGL? Any Workarounds? Afaik theres no trivial way to include SFML for the 2d layer, is there?

Heres my code, simply trying to render a static text and some buttons.

Code: Select all

 
#include "MainClass.h"
#include <irrlicht.h>
#include "UIElement.h"
#include "MastEventReceiver.h"
#include <vector>
#include <thread>
#include <chrono>
#include <iostream>
#include <string>
 
 
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
//#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif
 
 
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
 
using namespace std;
 
IrrlichtDevice *device;
IVideoDriver* driver;
ISceneManager* smgr;
IGUIEnvironment* guienv;
 
 
    //Event Handler
    MastEventReceiver receiver;
 
    //GuiElemente
    IGUIStaticText* healthtext;
 
 
int main() {
 
    //Setup Device
                                            //Renderer, Size, fullscreen, stencil, vsync, event receiver
    device = createDevice(video::EDT_OPENGL, dimension2d<u32>(1920, 1080), 32, true, false, true, &receiver);
    if (!device) {
    return 1;
    }
        
    receiver.init();
 
    //Setup Window
    device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");
 
    driver = device->getVideoDriver();
    smgr = device->getSceneManager();
    guienv = device->getGUIEnvironment();
 
    
    //TODO::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    //Setupgui
 
    IGUISkin* skin = guienv->getSkin();
    IGUIFont* font = guienv->getFont("res/fonthaettenschweiler.bmp");
 
    if (font)
        skin->setFont(font);
 
    skin->setFont(guienv->getBuiltInFont(), EGDF_TOOLTIP);
 
 
    healthtext = guienv->addStaticText(L"Health:", rect<s32>(800, 900, 400, 400));
    healthtext->setOverrideColor(SColor(255, 0, 255, 50));
    healthtext->enableOverrideColor(true);
    healthtext->setEnabled(true);
 
    guienv->addButton(rect<s32>(600, 10, 100, 100));
    guienv->addButton(rect<s32>(1080 - 110, 620, 100, 100));
    guienv->addButton(rect<s32>(1080 - 110, 740, 100, 100));
    guienv->addButton(rect<s32>(1080 - 110, 860, 100, 100));
    guienv->addButton(rect<s32>(1080 - 110, 980, 100, 100));
 
 
 
    while (device->run()) {
    
        driver->beginScene(true, true, SColor(255, 0, 0, 0));
 
        smgr->drawAll();
        guienv->drawAll();
 
        driver->endScene();
    }
}
Seven
Posts: 1030
Joined: Mon Nov 14, 2005 2:03 pm

Re: GUI-Layer dimensions behave totally weird

Post by Seven »

guienv->addButton(rect<s32>(600, 10, 600+100, 10+100));
guienv->addButton(rect<s32>(1080 - 110, 620, 1080 - 110+100, 620+100));
guienv->addButton(rect<s32>(1080 - 110, 740, 1080 - 110+100, 740+100));
guienv->addButton(rect<s32>(1080 - 110, 860, 1080 - 110+100, 860+100));
guienv->addButton(rect<s32>(1080 - 110, 980, 1080 - 110+100, 980+100));
Brainsaw
Posts: 1176
Joined: Wed Jan 07, 2004 12:57 pm
Location: Bavaria

Re: GUI-Layer dimensions behave totally weird

Post by Brainsaw »

The constructor of irr::core::rect with the 4 numbers takes the upper left and the lower right corner, but you're right, the documentation (http://irrlicht.sourceforge.net/docu/cl ... 6160ece50a) is not really that clear.

You could use the irr::core::rect(const position2d< T > &pos, const dimension2d< U > &size) constructor if you want to use the size, e.g.

guienv->addButton(rect<s32>(position2di(500, 500), dimension2du(100, 100))

if you want to directly pass the size

http://irrlicht.sourceforge.net/docu/cl ... c6d1556fcc
Dustbin::Games on the web: https://www.dustbin-online.de/

Dustbin::Games on facebook: https://www.facebook.com/dustbingames/
Dustbin::Games on twitter: https://twitter.com/dustbingames
Notion
Posts: 9
Joined: Mon Mar 20, 2017 11:00 pm

Re: GUI-Layer dimensions behave totally weird

Post by Notion »

Thanks so very much! Works pretty well, once you know how its supposed to work :)
Post Reply