Page 1 of 1

GUI-Layer dimensions behave totally weird

Posted: Sun Apr 16, 2017 11:14 pm
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();
    }
}

Re: GUI-Layer dimensions behave totally weird

Posted: Mon Apr 17, 2017 1:06 am
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));

Re: GUI-Layer dimensions behave totally weird

Posted: Mon Apr 17, 2017 5:37 am
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

Re: GUI-Layer dimensions behave totally weird

Posted: Mon Apr 17, 2017 11:21 am
by Notion
Thanks so very much! Works pretty well, once you know how its supposed to work :)