Basic Materials

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
booster
Posts: 15
Joined: Thu Nov 19, 2015 8:53 pm

Basic Materials

Post by booster »

Hi, I seem to be missing something here when it comes to using basic materials without lighting. How to make the following cube red (without lights). Cheers

Code: Select all

 
#include <irrlicht.h>
#include "driverChoice.h"
 
//#include <iostream>
//using namespace std;
 
using namespace irr;
 
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
 
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#endif
 
int main(){
    
    IrrlichtDevice *device = createDevice(video::EDT_OPENGL);
    IVideoDriver* driver = device->getVideoDriver();
    ISceneManager* smgr = device->getSceneManager();
    
    //smgr->setAmbientLight(video::SColorf(0.3,0.3,0.3,1));     //  r,g,b,a
    
    //ILightSceneNode* light1 = smgr->addLightSceneNode( 0, core::vector3df(-20,100,-20), video::SColorf(0.3f,0.3f,0.3f), 1.0f, 1 );
    
    ISceneNode* cube = smgr->addCubeSceneNode();
    cube->setPosition(vector3df(0,0,0));
    cube->setScale(vector3df(1,1,1));
    
    cube->getMaterial(0).Shininess = 15.0f;
    cube->getMaterial(0).SpecularColor.set(0,200,50,50);            //  a,r,g,b
    cube->getMaterial(0).AmbientColor.set(0,255,0,0);
    cube->getMaterial(0).DiffuseColor.set(0,0,255,0);
    //cube->getMaterial(0).EmissiveColor.set(0,0,0,255);
    cube->getMaterial(0).Lighting = false;  //.set(false);
    //cube->setMaterialFlag(video::EMF_LIGHTING, false);
    
    ICameraSceneNode* cam = smgr->addCameraSceneNode();
    cam->setTarget(vector3df(0,0,0));   //  cube->getPosition());
    cam->setPosition(vector3df(10,10,10));
    
    while(device->run() && device){
        driver->beginScene(true, true, video::SColor(0,55,55,55));
        smgr->drawAll();
        driver->endScene();
    }
    
    device->drop();
}
 
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Basic Materials

Post by mongoose7 »

At the moment it is green?
booster
Posts: 15
Joined: Thu Nov 19, 2015 8:53 pm

Re: Basic Materials

Post by booster »

For me its white or black (dependent upon lighting bool)
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Basic Materials

Post by mongoose7 »

Well, if you turn on lighting without a light, the colour will be black.

As regards the white colour, this is the colour of the vertices. There is an OpenGL setting to take the colour from the material, but I don't know how to get Irrlicht to set it. As a workaround, you can either set the colour of the vertices, or set a texture which has the colour you want.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Basic Materials

Post by CuteAlien »

You can set vertex colors with IMeshManipulator::setVertexColors and you get the meshmanipulator from the scenemanager.
All the colors in the material only matter if you have enabled light.

Also check example 22 MaterialViewer (I recommend using the one from trunk which has some improvements). Clear the texture and then you can experiment around with the different settings and how they effect each other.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply