Some questions before starting with Irrlicht

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.

Some questions before starting with Irrlicht

Postby henlambert » Fri May 11, 2012 7:49 am

Hello,

I've run all Irrlicht demos and read a lot of documentation. But there are some questions left before I'm going to start my game development with Irrlicht.

1. Is it possible to call native OpenGL functions within the Irrlicht framework? The example CustomSceneNode shows a way to render a primitive, and the function seems to cover a OpenGL function. But for my project I need straight access to OpenGL (special particle systems etc.).

2. What about large terrains, covered with different textures? The Irrlicht terrain example is based on a heightmap, that's good. But it uses a single texture, that's not suitable for my purpose. Even more: the behaviour of the character depends on the terrain texture (friction coefficient, controllability, speed etc.).

3. As I said, the terrains will be quite large (about 1 million of tris). Does Irrlicht use something like dynamic LOD for the terrain rendering? Or must the terrain splitted into several parts?
henlambert
 
Posts: 11
Joined: Fri Apr 20, 2012 6:36 pm

Re: Some questions before starting with Irrlicht

Postby hendu » Fri May 11, 2012 9:52 am

1) Yes, you can call OpenGL at any point you wish. Just need to be careful the state is correct at that point.

2) Shaders, and a cpu-side representation for your character interaction.

3) No readymade LOD, you'll need to invent something or pick up one of the solutions in the forum. There is the quadtree node for cpu-side splitting, but I don't know if it works well at all for terrain.

edit: Well the terrain scenenode does do LOD, but I found it unsuitable for my purposes and didn't use it.
hendu
 
Posts: 1556
Joined: Sat Dec 18, 2010 12:53 pm

Re: Some questions before starting with Irrlicht

Postby henlambert » Wed May 16, 2012 4:35 pm

1) Yes, you can call OpenGL at any point you wish. Just need to be careful the state is correct at that point.


Sorry, I've some experiences with OpenGL and SDL but are not very familiar with Irrlicht.
I've tried it but all my attempts failed. First the way I do it with SDL. This procedure works very fine and is quite sophisticated. The following code is shortened, of course:

cpp Code: Select all
Pseudo code !
 
int main ()
{
    InitSDL ();         // creating SDL window with OpenGL ...
    InitOgl ();         // setting initial values to OpenGL
    SetViewport ();     // setting viewport to width and height of SDL window
    SetPerspective ();  // setting 3D perspective with GLU using the viewport parameters
 
    while (!done)
    {
        glClear (...);          // fills the buffer with clear color
        Render ();              // renders simple primitives (a triangle and a quad)
        SDL_GL_SwapBuffers();   // swaps the GL buffer to SDL window
    }
    QuitProgram ();     // cleaning up
    return 0;
}
 


And now an attempt to do something like that by using Irrlicht instead of SDL:


cpp Code: Select all
int main ()
{
    InitIrrlicht ();    // creating Irrlicht device
    InitOgl ();
    SetViewport ();
    SetPerspective ();
 
    while (device->run())
    {
        driver->beginScene (true, true, video::SColor(255, 40, 50, 100));
        Render ();
        driver->endScene();
    }
    device->drop ();
    return 0;
}
 

The result is a white, empty window. I hoped that beginScene(...) and clearing the buffers by calling glClear() were comparable, but that seems to be wrong. The same with endScene() and SDL_GL_SwapBuffers(). What is wrong?
henlambert
 
Posts: 11
Joined: Fri Apr 20, 2012 6:36 pm

Re: Some questions before starting with Irrlicht

Postby hendu » Wed May 16, 2012 5:33 pm

That's what I meant with the state ;) beginScene clears some state, which is then set when you render something in irrlicht (the view matrix, among other things). If you're only rendering by yourself, then you need to set the state yourself too.
hendu
 
Posts: 1556
Joined: Sat Dec 18, 2010 12:53 pm

Re: Some questions before starting with Irrlicht

Postby henlambert » Thu May 17, 2012 9:29 am

You're right, I've to refresh the OpenGL state in each frame. Now I can see something on the screen but it's not correct. Here the modified code (see the comments):


cpp Code: Select all
void Render () {
        glEnable (GL_DEPTH_TEST);
        glDepthMask (GL_TRUE);
        glDepthFunc (GL_LEQUAL);
        glShadeModel (GL_SMOOTH);
       
        glDisable (GL_BLEND);
        glDisable (GL_LIGHTING);
 
 
        glColor3f (1.0, 1.0, 1.0);  // should be white
        // This call has no effect, the figures appear black
 
 
        glLoadIdentity ();
        glTranslatef (-1.5, 0.0, -4.0);
 
        glBegin(GL_TRIANGLES);
                glVertex3f (-1.0,-1.0, 0.0);
                glVertex3f ( 1.0,-1.0, 0.0);
                glVertex3f ( 0.0, 1.0, 0.0);
        glEnd();
 
// The triangle is not visible, only the quad. After replacing the triangle
// with a second quad 2 quads are drawn at the intended position
 
/*
        glBegin(GL_QUADS);
                glVertex3f (-1.0, 1.0, 0.0);
                glVertex3f ( 1.0, 1.0, 0.0);
                glVertex3f ( 1.0,-1.0, 0.0);
                glVertex3f (-1.0,-1.0, 0.0);
        glEnd();
*/

 
        glTranslatef (3.0, 0.0, -0.0);
        glBegin(GL_QUADS);
                glVertex3f (-1.0, 1.0, 0.0);
                glVertex3f ( 1.0, 1.0, 0.0);
                glVertex3f ( 1.0,-1.0, 0.0);
                glVertex3f (-1.0,-1.0, 0.0);
        glEnd();
 
}
 
 
int main()
{
        // Irrlicht stuff at the beginning
    MyEventReceiver receiver;
        IrrlichtDevice* device = createDevice(video::EDT_OPENGL,
                        dimension2d<u32>(640, 480), 32, false, false, false, &receiver);
        if (device == 0) return 1;
        IVideoDriver* driver = device->getVideoDriver();
        ISceneManager* smgr = device->getSceneManager();
        smgr->addCameraSceneNodeFPS();
 
 
        while(device->run())
       {
        driver->beginScene(true, true, SColor(255, 40, 50, 100));   // blue
 
        glViewport (0, 0, 640, 480);
 
        glMatrixMode (GL_PROJECTION);
        glLoadIdentity ();
        gluPerspective (75, 640.0 / 480.0, 0, 500);
        glMatrixMode (GL_MODELVIEW);
        glLoadIdentity ();
 
        glClearColor (1, 0, 0, 1);  // red, overwrites the color of beginScene
        glClearStencil (0.0);
        glClearDepth (1.0);
        glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
 
        Render();
 
        driver->endScene();
 
        }
 
        device->drop();
        return 0;
}
 

I suppose that Irrlicht enables texturing, so I disabled it as well as lighting. I can't see any reason why the triangle is not be rendered. glClear overwrites the colour of beginScene, that's ok, but I can't understand why glColor in the render function doesn't work.
henlambert
 
Posts: 11
Joined: Fri Apr 20, 2012 6:36 pm

Re: Some questions before starting with Irrlicht

Postby hendu » Thu May 17, 2012 9:40 am

Irrlicht also touches the winding order IIRC, so your triangle is backface-culled. As for the black color, it's been a long time since I did immediate mode, can't remember exactly how the color setting went.

But anyway, no need to guess, we have the source to beginScene, no? :)
hendu
 
Posts: 1556
Joined: Sat Dec 18, 2010 12:53 pm

Re: Some questions before starting with Irrlicht

Postby smso » Thu May 17, 2012 11:07 am

You need:

cpp Code: Select all
        driver->setMaterial(...);
        driver->setTransform(...);
 

or equivalent in:
cpp Code: Select all
Render()



Regards
smso
smso
 
Posts: 217
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Re: Some questions before starting with Irrlicht

Postby henlambert » Thu May 17, 2012 3:45 pm

Irrlicht also touches the winding order IIRC, so your triangle is backface-culled.

Good hint. I've changed the order of the vertices (clockwise now) and the triangle is visible.

But anyway, no need to guess, we have the source to beginScene, no?

Yes, of course, but I can't find it. The suitable header IVideoDriver.h and the associated implementation ???.cpp is not to be found in the downloaded Irrlicht source folder. A hint?

@smso
driver->setMaterial(...);
driver->setTransform(...);


setMaterial doesn't work, with the standard material (white) the entire window is coloured white and the shapes are invisible. setTransform is not necessary since all transform params can be correctly set by glTranslatef etc. However, the goal ist to bypass the Irrlicht controls at some special points of the program.
henlambert
 
Posts: 11
Joined: Fri Apr 20, 2012 6:36 pm

Re: Some questions before starting with Irrlicht

Postby hendu » Thu May 17, 2012 7:35 pm

Grep is your friend ;)

$ grep -l beginScene *p
CD3D8Driver.cpp
CD3D9Driver.cpp
CNullDriver.cpp
COpenGLDriver.cpp
CSoftwareDriver2.cpp
CSoftwareDriver.cpp
hendu
 
Posts: 1556
Joined: Sat Dec 18, 2010 12:53 pm

Re: Some questions before starting with Irrlicht

Postby henlambert » Fri May 18, 2012 7:23 am

$ grep -l beginScene *p


Indeed, grep helps. I found out that beginScene can't cause that colour problem. So I deleted this command, and it works in the same way as with beginScene. Apparently beginScene does almost the same as glClear.

There is only one Irrlicht command left that could be relevant: createDevice. Probably there are some OpenGL settings in this function that might be responsable. But to say the truth: For me, that code is too difficult to understand. It doesn't make sense to study the code for days or weeks - without a realistic chance of being successful.

Ok, it was a trial. Thank you very much for your help.

Reinhard
henlambert
 
Posts: 11
Joined: Fri Apr 20, 2012 6:36 pm

Re: Some questions before starting with Irrlicht

Postby REDDemon » Fri May 18, 2012 8:28 am

making your self a lod system is much easy (unless you start dealing with syncro problem like terrain streaming).

the reason for wich (i think, just my opinion) irrlicht is missing a LOD system is because any lod system isn't so general to be included in the engine. (there are lots of snippets made by the community wich are not included in the engine and there are also further snippets in IrrExt project).

You should use irrlicht just because of its community, you will not find a community like that one elsewhere.

wellcome, and yes you can use OpenGL with IRrlicht,
my personal advice is to use Irrlicht +GLEW, (just add source files of glew to your project)

GLEW is maybe a big library (1+MB on mingw), but is very usefull and has alot of run-time checks, most GL libraries use GL ext pointer (wich is no longer maintained and requires users' effort to do run-time check).
OpenGL is not hard. What you have to do is just explained in specifications. What is hard is dealing with poor OpenGL implementations.
User avatar
REDDemon
 
Posts: 831
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: Some questions before starting with Irrlicht - solved

Postby henlambert » Fri May 18, 2012 9:28 am

The missing colors of the primitives - it was a stupid error: I forgot to disable the texture mapping:

cpp Code: Select all
glDisable (GL_TEXTURE_2D);

Enabling and disabling textures is one of the mostly used OpenGL settings and I should have noticed that Irrlicht prefers textured materials as default behaviour. Again: a stupid error.

@REDDemon
Now that I'm sure to be able to use native OpenGL I'm going to explore further features of Irrlicht. Thank you for your hints, I'll check them carefully And thank you for encouraging me to use Irrlicht.
henlambert
 
Posts: 11
Joined: Fri Apr 20, 2012 6:36 pm


Return to Beginners Help

Who is online

Users browsing this forum: Google [Bot] and 1 guest