OGLES2 custom rendering

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
cww
Posts: 27
Joined: Sun Jul 28, 2013 1:29 pm

OGLES2 custom rendering

Post by cww »

I recently updated my usage of ogles branch from revision 4898 to 5001 and noticed that there are big improvements, especially for OGLES2 driver where the shaders were overhauled (kudos to the effort). However, one side effect it had on me is that it breaks some of my existing code which uses the OGLES2 driver to overlay my custom GUI layer.

Below are extracted code snippets that captures the essence of how I use it. Basically, I make the coordinate corresponds to screen and then load the texture and render the polygons (need not be rectangle). These code snippets still works if I use OGLES1.

As I had also made changes to OGLES2 to enable skeleton animation, going back to OGLES1 is not an option for me.

Hence, will appreciate some pointers on how to achieve the equivalent effect, e.g. should I use setMaterial() + drawPrimitiveList(), or some other ways.

Thanks!

Code: Select all

 
    // update matrices so that coordinate corresponds to screen
    irr::core::matrix4 mat1;
    irr::core::matrix4 mat2 = mat1.buildNDCToDCMatrix(driver.getViewPort(), 1.0f);
    mat2.getInverse(mat1);
    
    driver.setTransform(irr::video::ETS_PROJECTION, irr::core::matrix4());
    driver.setTransform(irr::video::ETS_VIEW, irr::core::matrix4());
    driver.setTransform(irr::video::ETS_WORLD, mat1);
 

Code: Select all

 
    // set texture
    driver->disableTextures(1);
    if (! driver->setActiveTexture(0, texture)) {
        LogI("driver->setActiveTexture(0, texture) failed\n");
        return;
    }
 

Code: Select all

 
    // after setting texture, only call the following if it is OGLES2 (not called for OGLES1)
    driver->setRenderStates2DMode(true, true, true);
 

Code: Select all

 
// finally, draw vertices
glDisable(GL_CULL_FACE);
driver->drawVertexPrimitiveList2d3d(
    &polygon->Vertices[0],
    polygon->NumVertex,
    &polygon->Indices[0],
    polygon->NumIndex / 3,
    irr::video::EVT_STANDARD,
    irr::scene::EPT_TRIANGLES);
 
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: OGLES2 custom rendering

Post by CuteAlien »

Please do one thing first before you continue with any experiments: Update svn to 5002. There's an important bugfix in there when it comes to textures (alpha-textures to be exact). Maybe you are lucky and that solves your troubles already.
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
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: OGLES2 custom rendering

Post by Nadro »

Hi,

1. As CuteAlien said you should update your repo to r5002.

2. You should avoid pure OpenGL calls like a:

Code: Select all

glDisable(GL_CULL_FACE);
For a better performance we added an internal OGL cache called Bridge Calls, so you should replace above call with:

Code: Select all

driver->getBridgeCalls()->setCullFace(false);
or just use SMaterial field (the best solution).

3. When you want to render object you should call:

Code: Select all

 // your matrices calc.
driver->setMaterial(currentMaterial);
driver->drawVertexPrimitiveList(...); // it will call setRenderStates3DMode
You should remove setRenderStates2DMode, disableTextures and setActiveTexture calls.

Cheers,
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
cww
Posts: 27
Joined: Sun Jul 28, 2013 1:29 pm

Re: OGLES2 custom rendering

Post by cww »

Hi CuteAlien and Nadro,

Thanks for the pointers. I will test it out soon and let u know the outcome :D
cww
Posts: 27
Joined: Sun Jul 28, 2013 1:29 pm

Re: OGLES2 custom rendering

Post by cww »

Hi Nadro, CuteAlien,

I have upgraded to 5004. Unfortunately, it still doesn't work. I am supposed to see a button that is magenta in colour, and in stead the whole screen is magenta. I suspect there is some coordinates conversion error but could be due to my own issue, so will investigate a bit on my side first. But if you can think of any reason for this please let me know.

Separately, I also use CBillboardSceneNode to render a health bar which is supposed to be red in colour. Now it is always white. Took a quick look at the source code for CBillboardSceneNode and notices it setMaterial using the default constructed material. Does the material need to be modified? I tried using some other MaterialType (without changing other params) but does not resolve the issue (though using EMT_ONETEXTURE_BLEND makes the health bar black).

Thanks!
cww
Posts: 27
Joined: Sun Jul 28, 2013 1:29 pm

Re: OGLES2 custom rendering

Post by cww »

A quick update to the CBillBoardSceneNode, I managed to get the health bar back to red colour by modifying private Material in the constructor of the class:

Code: Select all

 
    Material.Lighting = false;
    Material.MaterialType = irr::video::EMT_ONETEXTURE_BLEND;
    Material.MaterialTypeParam = irr::video::pack_textureBlendFunc(
                                    irr::video::EBF_SRC_ALPHA,
                                    irr::video::EBF_ONE_MINUS_SRC_ALPHA,
                                    irr::video::EMFN_MODULATE_1X,
                                    irr::video::EAS_TEXTURE | irr::video::EAS_VERTEX_COLOR);
    Material.BlendOperation = irr::video::EBO_ADD;
 
But since it is a generic class, I am not sure if this is the desired default...
cww
Posts: 27
Joined: Sun Jul 28, 2013 1:29 pm

Re: OGLES2 custom rendering

Post by cww »

The rendering problem was confirmed due to some other compatibility issue on my side due to some true type font code that I had adapted. Thanks for the pointers on how to set up for custom rendering on the latest code. With these and changing back to bitmap font fixed the issue. Cheers!
Post Reply