some noob questions

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.
Eventide
Posts: 23
Joined: Fri Jul 19, 2013 4:46 am

Re: some noob questions

Post by Eventide »

It's weird to say that again but, didn't worked... Tryied with TextureLayer[0], TextureLayer[1] and TextureLayer[2], not using as a pointer anymore and with various values...
Eventide
Posts: 23
Joined: Fri Jul 19, 2013 4:46 am

Re: some noob questions

Post by Eventide »

Just realised that AntiAlias isn't a bool value, but any value that i put in there don't do any change... This is really weird, nobody knows what is going on?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: some noob questions

Post by hybrid »

You don't need antialias, but either mipmap (which needs to be set in texture creation flags before creating the texture) or texture filterin (bilinear, trilinear and/or anisotropic)
Eventide
Posts: 23
Joined: Fri Jul 19, 2013 4:46 am

Re: some noob questions

Post by Eventide »

hybrid wrote:You don't need antialias, but either mipmap (which needs to be set in texture creation flags before creating the texture) or texture filterin (bilinear, trilinear and/or anisotropic)
So, what's the problem? :S

I already abled/disabled mipmaps and played a lot with LODbias values...
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: some noob questions

Post by hendu »

Obviously if you're changing the right field and not seeing results, you're changing the right field on the wrong object or so ;)

Either post a complete example with models and code so someone friendly can check, or start from one of the examples, changing the filters there.
Eventide
Posts: 23
Joined: Fri Jul 19, 2013 4:46 am

Post by Eventide »

Ok, i already posted some parts of the sourcecode, but i'll post the entire StateManager(which do all drawings) class and main.cpp now, hope someone can find the issue:

statemanager.h:

Code: Select all

 
#ifndef STATEMANAGER_HEADERFILE
#   define STATEMANAGER_HEADERFILE
#   include <irrlicht.h>
#   include "player.h"
 
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
 
extern IrrlichtDevice* device;
 
enum GAMESTATE
{
    GS_RUNNING,
    GS_PAUSED,
    GS_MAINMENU
};
 
class StateManager
{
    private:
        StateManager(){}
        const char* mPath;
        ISceneManager* mSceneManager;
        ICameraSceneNode* mCamera;
        ISceneCollisionManager* mCollisionManager;
        IGUIEnvironment* mGui;
        IGUIFont* mFont;
        ITexture* mStatusBar;
        Player* mPlayer;
        void setup();
        void setupCollision();
        bool drawSkillsInterface = false;
        bool drawInventoryInterface = false;
        bool drawSpellsInterface = false;
        IGUIWindow* inventoryWindow;
        IGUIWindow* skillsWindow;
        IGUIWindow* spellsWindow;
        GAMESTATE state = GS_RUNNING; //será GS_MAINMENU depois
 
    public:
        static StateManager* getInstance()
        {
            static StateManager* inst;
            if(inst)
                return inst;
 
            inst = new StateManager();
            inst->setup();
            return inst;
        }
        void changeScene(const char* path, core::vector3df frompos);
        void update();
        IAnimatedMeshSceneNode* newAnimatedMesh(const char* src, const char* tex);
        void drawScene();
        void inventoryInterface();
        void skillsInterface();
        void spellsInterface();
        void pause();
        void unpause();
};
 
#endif
 
 
statemanager.cpp:

Code: Select all

 
#include "statemanager.h"
 
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
 
extern IVideoDriver* driver;
 
void StateManager::setup()
{
    mSceneManager = device->getSceneManager();
    mSceneManager->loadScene("data/maps/dungeons/dg1.irr");
    mCamera = mSceneManager->addCameraSceneNodeFPS(0, 50.f, 0.1f, -1, 0, 0, true);
    mGui = device->getGUIEnvironment();
    mFont = mGui->getFont("fonthaettenschweiler.bmp");
    IGUISkin* skin = mGui->createSkin(EGST_WINDOWS_METALLIC);
    mGui->setSkin(skin);
    skin->drop();
    mStatusBar = driver->getTexture("data/system/gui/status.jpg");
    mPlayer = new Player();
    mPlayer->setHealth(100);
    mPlayer->setMana(10);
    mPlayer->setLevel(1);
    setupCollision();
}
 
void StateManager::update()
{
    core::line3d<f32> mRay;
    mRay.start = mCamera->getPosition();
    mRay.end = mRay.start + (mCamera->getTarget() - mRay.start).normalize() * 1000.0f;
    scene::ISceneNode * selectedSceneNode =
            mCollisionManager->getSceneNodeFromRayBB(mRay, 1);
    if (selectedSceneNode)
    {
        //printf(selectedSceneNode->getName());
    }
}
 
void StateManager::setupCollision()
{
    IMetaTriangleSelector* meta = mSceneManager->createMetaTriangleSelector();
    core::array<ISceneNode*> nodes;
    mSceneManager->getSceneNodesFromType(scene::ESNT_ANY, nodes);
     for (u32 i=0; i < nodes.size(); ++i)
    {
        scene::ISceneNode * node = nodes[i];
        scene::ITriangleSelector * selector = 0;
 
        switch(node->getType())
        {
            case scene::ESNT_CUBE:
                case scene::ESNT_ANIMATED_MESH:
                // Because the selector won't animate with the mesh,
                // and is only being used for camera collision, we'll just use an approximate
                // bounding box instead of ((scene::IAnimatedMeshSceneNode*)node)->getMesh(0)
                    selector = mSceneManager->createTriangleSelectorFromBoundingBox(node);
                    break;
 
            case scene::ESNT_MESH:
                case scene::ESNT_SPHERE: // Derived from IMeshSceneNode
                    selector = mSceneManager->createTriangleSelector(((scene::IMeshSceneNode*)node)->getMesh(), node);
                    break;
 
            case scene::ESNT_TERRAIN:
                selector = mSceneManager->createTerrainTriangleSelector((scene::ITerrainSceneNode*)node);
                break;
 
            case scene::ESNT_OCTREE:
                selector = mSceneManager->createOctreeTriangleSelector(((scene::IMeshSceneNode*)node)->getMesh(), node);
                break;
 
            default:
                // Don't create a selector for this node type
                break;
        }
        if(selector)
        {
            // Add it to the meta selector, which will take a reference to it
            meta->addTriangleSelector(selector);
            // And drop my reference to it, so that the meta selector owns it.
            selector->drop();
        }
        for (u32 i = 0; i < node->getMaterialCount(); i++)
        {
            for (u32 t=0; t<MATERIAL_MAX_TEXTURES; t++)
            {
                node->getMaterial(i).TextureLayer[t].AnisotropicFilter = 16;
                node->getMaterial(i).TextureLayer[t].TrilinearFilter = true;
                node->getMaterial(i).TextureLayer[t].LODBias = 64;
            }
        }
    }
    ISceneNodeAnimator* anim = mSceneManager->createCollisionResponseAnimator(
        meta, mCamera, core::vector3df(5,5,5),
        core::vector3df(0,0,0));
    meta->drop(); // I'm done with the meta selector now
    mCamera->addAnimator(anim);
    anim->drop(); // I'm done with the animator now
    mCamera->setPosition(core::vector3df(0.f, 20.f, 0.f));
    ISceneNode * cube = mSceneManager->getSceneNodeFromType(ESNT_CUBE);
    if(cube)
        mCamera->setTarget(cube->getAbsolutePosition());
 
    mCollisionManager = mSceneManager->getSceneCollisionManager();
}
 
void StateManager::drawScene()
{
    mSceneManager->drawAll();
    driver->draw2DImage(mStatusBar, core::position2d<s32>(25, 0),
                core::rect<s32>(0, 0, 256, 32), 0,
                video::SColor(255, 255, 255, 255), false);
 
    unsigned int hp = mPlayer->getHealth();
    char s[strlen("HP: ")+sizeof(hp)-2];
    sprintf(s,"HP: %u",hp);
    wchar_t t[strlen("HP: ")+sizeof(hp)-2];
    for (unsigned int i=0;i<strlen(s);i++)
    {
        t[i] = (wchar_t)s[i];
    }
    mFont->draw(t,
                    core::rect<s32>(30,5,256,32),
                    video::SColor(255,255,255,255));
    unsigned int mp = mPlayer->getMana();
    char s2[strlen("MP: ")+sizeof(mp)-2];
    sprintf(s2,"MP: %u", mp);
    wchar_t t2[strlen("MP: ")+sizeof(mp)-2];
    for (unsigned int i=0;i<strlen(s2);i++)
    {
        if (i != strlen(s2))
            t2[i] = (wchar_t)s2[i];
    }
    mFont->draw(t2,
                    core::rect<s32>(100,5,256,32),
                    video::SColor(255,255,255,255));
    unsigned int lvl = mPlayer->getLevel();
    char s3[strlen("Level: ")+sizeof(lvl)-2];
    sprintf(s3,"Level: %u", lvl);
    wchar_t t3[strlen("Level: ")+sizeof(lvl)-2];
    for (unsigned int i=0;i<strlen(s3);i++)
    {
        if (i != strlen(s3))
            t3[i] = (wchar_t)s3[i];
    }
    mFont->draw(t3,
                    core::rect<s32>(170,5,256,32),
                    video::SColor(255,255,255,255));
    mGui->drawAll(); //Não usado por enquanto, se persistir em não usar delete isso.
}
 
void StateManager::changeScene(const char* path, core::vector3df frompos)
{ //to-do: criar sistema de portas/portais e derivados para saber qual é a nova posição da camera a partir da posição antiga
    mSceneManager->clear();
    mSceneManager->loadScene(path);
    mPath = path;
    setupCollision();
}
 
IAnimatedMeshSceneNode* StateManager::newAnimatedMesh(const char* src, const char* tex)
{
    IAnimatedMesh* mesh = mSceneManager->getMesh(src);
    if(!mesh)
    {
        device->drop();
        return NULL;
    }
    IAnimatedMeshSceneNode* ret = mSceneManager->addAnimatedMeshSceneNode(mesh);
    if(ret)
    {
        ret->setMaterialFlag(EMF_LIGHTING, false);
        ret->setMD2Animation(scene::EMAT_STAND);
        ret->setMaterialTexture(0, driver->getTexture(tex));
        return ret;
    }
    return NULL;
}
 
void StateManager::pause()
{
    if(state ==  GS_RUNNING)
    {
        state = GS_PAUSED;
        mCamera->setInputReceiverEnabled(false);
        device->getCursorControl()->setVisible(true);
    }
}
 
void StateManager::unpause()
{
    if(state == GS_PAUSED)
    {
        state = GS_RUNNING;
        mCamera->setInputReceiverEnabled(true);
        device->getCursorControl()->setVisible(false);
    }
}
 
void StateManager::inventoryInterface()
{
    if(!drawInventoryInterface)
    {
        if((!drawSkillsInterface) and (!drawSpellsInterface))
        {
            drawInventoryInterface = true;
            inventoryWindow = mGui->addWindow(rect<s32>(10, 50, 150, 400), false, L"Inventory");
            pause();
        }
    }
    else
    {
        drawInventoryInterface = false;
        inventoryWindow->remove();
        unpause();
    }
}
 
void StateManager::skillsInterface()
{
    if(!drawSkillsInterface)
    {
        if((!drawInventoryInterface) and (!drawSpellsInterface))
        {
            drawSkillsInterface = true;
            skillsWindow = mGui->addWindow(rect<s32>(10, 50, 150, 400), false, L"Skills");
            pause();
        }
    }
    else
    {
        drawSkillsInterface = false;
        skillsWindow->remove();
        unpause();
    }
}
 
void StateManager::spellsInterface()
{
    if(!drawSpellsInterface)
    {
        if((!drawInventoryInterface) and (!drawSkillsInterface))
        {
            drawSpellsInterface = true;
            spellsWindow = mGui->addWindow(rect<s32>(10, 50, 150, 400), false, L"Spells");
            pause();
        }
    }
    else
    {
        drawSpellsInterface = false;
        spellsWindow->remove();
        unpause();
    }
}
 
main.cpp:

Code: Select all

 
#include <irrlicht.h>
#include "statemanager.h"
#include "eventmanager.h"
 
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
 
IVideoDriver* driver;
IrrlichtDevice* device;
 
int main()
{
    irr::SIrrlichtCreationParameters params;
    params.DriverType=EDT_OPENGL;
    params.WindowSize=dimension2d<u32>(800, 600);
    params.Bits=32;
    params.Fullscreen=false;
    params.Stencilbuffer=true;
    params.Vsync=true;
    params.AntiAlias=10;
    params.EventReceiver=0;
 
    device = createDeviceEx(params);
 
    if (!device)
        return 1;
 
    device->setWindowCaption(L"Dimension Door");
    driver = device->getVideoDriver();
    driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);
    StateManager* state_manager = StateManager::getInstance();
    device->getCursorControl()->setVisible(false);
    EventManager* event_manager = new EventManager();
    device->setEventReceiver(event_manager);
    while(device->run())
    {
        driver->beginScene(true, true, SColor(255,100,101,140));
        state_manager->drawScene();
        driver->endScene();
        state_manager->update();
        event_manager->checkKeys();
    }
    device->drop();
    return 0;
}
 
Thanks in advance.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: some noob questions

Post by hybrid »

Why do you change the LODBias? And what happens if you load your mesh without the .irr file, but directly from the original mesh file?
Eventide
Posts: 23
Joined: Fri Jul 19, 2013 4:46 am

Re: some noob questions

Post by Eventide »

hybrid wrote:Why do you change the LODBias? And what happens if you load your mesh without the .irr file, but directly from the original mesh file?
I changed LODBias because people said to change mipmap value and mostly because of the wiki:
This value can make the textures more or less blurry than with the default value of 0.
Didn't tried to load the mesh directly but i really don't want it... The main reason that made me use irrlicht is because i loved irredit, and why should this make diference? Nodes from .irr files have known bugs?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: some noob questions

Post by hybrid »

Texture creation flags are not preserved in .irr files, so you can have a different result with both ways. But more important, you should make sure that the mesh is loadable in the expected way by some method first, before checking if there is a better way.
LODBias makes the mipmaps appear earlier or later. But if mipmapping does not work at all, LODBias won't help.
Eventide
Posts: 23
Joined: Fri Jul 19, 2013 4:46 am

Re: some noob questions

Post by Eventide »

Ok, i tried to load the meshes directly, didn't changed any other piece of code, and the result is the same... I'm starting to get confused...
Eventide
Posts: 23
Joined: Fri Jul 19, 2013 4:46 am

Re: some noob questions

Post by Eventide »

I can't understand, every demo that i run look like fine and when i see the source code, there isn't anything that i'm doing with my code, like LODbias or other filters, there isn't texture creation flags too, it's probably a problem with wingcc DLL, no?
Post Reply