Improved screenquad

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Improved screenquad

Post by hendu »

I got this from this subforum a long while ago. It's been tuned a bit since then.

lol @ the forum completely mangling the indentation. Oh well.

Code: Select all

class screenQuad {
    public:
      screenQuad(IVideoDriver *xy)
      {
    vd = xy;
 
    const SColor white(255, 255, 255, 255);
    vertices[0].Pos = vector3df(-1, 1, 0);
    vertices[0].TCoords = vector2df(0, 0);
    vertices[0].Color = white;
    vertices[1].Pos = vector3df(1, 1, 0);
    vertices[1].TCoords = vector2df(1, 0);
    vertices[1].Color = white;
    vertices[2].Pos = vector3df(1, -1, 0);
    vertices[2].TCoords = vector2df(1, 1);
    vertices[2].Color = white;
    vertices[3].Pos = vector3df(-1, -1, 0);
    vertices[3].TCoords = vector2df(0, 1);
    vertices[3].Color = white;
    indices[0] = 0;
    indices[1] = 1;
    indices[2] = 3;
    indices[3] = 2;
 
    mat.Lighting = false;
    mat.ZBuffer = video::ECFN_ALWAYS;
    mat.ZWriteEnable = false;
//  mat.SkipArrays = ESA_COLOR | ESA_NORMAL;
 
    for(u32 c = 0; c < MATERIAL_MAX_TEXTURES; c++)
    {
       mat.TextureLayer[c].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
       mat.TextureLayer[c].TextureWrapV = video::ETC_CLAMP_TO_EDGE;
    }
      }
 
      SMaterial& getMaterial() { return mat; }
 
      //Set the texture to render with the quad
      void setTexture(ITexture* __restrict tex, u32 layer = 0)
      {
    mat.TextureLayer[layer].Texture = tex;
      }
 
      ITexture* getTexture(u32 layer = 0) { return mat.TextureLayer[layer].Texture; }
 
      void setMaterialType(E_MATERIAL_TYPE mt) { mat.MaterialType = mt; }
 
      void render(bool setRTToFrameBuff = true)
      {
    if(setRTToFrameBuff)
       vd->setRenderTarget(video::ERT_FRAME_BUFFER);
 
    sq_dorender();
      }
 
      void render(ITexture* rt)
      {
    vd->setRenderTarget(rt);
 
    sq_dorender();
      }
 
   protected:
    S3DVertex vertices[4];
    u16 indices[4];
    SMaterial mat;
 
    IVideoDriver* vd;
 
    void sq_dorender()
    {
        glColor3ub(255, 255, 255);
 
        vd->setMaterial(mat);
        vd->setTransform(ETS_WORLD, core::IdentityMatrix);
        vd->setTransform(ETS_VIEW, core::IdentityMatrix);
        vd->setTransform(ETS_PROJECTION, core::IdentityMatrix);
        vd->drawVertexPrimitiveList(vertices, 4, indices, 2, EVT_STANDARD,
                        EPT_TRIANGLE_STRIP);
    }
};
 
CuteAlien
Admin
Posts: 9647
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Improved screenquad

Post by CuteAlien »

hendu wrote: lol @ the forum completely mangling the indentation. Oh well.
Hm, we tried to improve it this week (going from tabsize 8 to tabsize 4 as that is used in Irrlicht-code). Guess have to experiment some more...
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
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Improved screenquad

Post by hendu »

The ideal behavior would be "don't touch it", ie keep tabs tabs and spaces spaces without any transformations.
CuteAlien
Admin
Posts: 9647
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Improved screenquad

Post by CuteAlien »

hendu wrote:The ideal behavior would be "don't touch it", ie keep tabs tabs and spaces spaces without any transformations.
I don't think that works inside a webbrowser text-element. I mean tabs _are_ replaced in your editor (you can set it in most) - so we have to do something with them here.
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
CuteAlien
Admin
Posts: 9647
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Improved screenquad

Post by CuteAlien »

Just wondering how it messed up in your case - are you using a tabsize of 8 maybe?
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
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Improved screenquad

Post by hendu »

I'm a follower of the One True style of the linux kernel ;) Ie tabs are tabs, no conversion to spaces. The tabs survived in the edit box (via copy-pasting, of course you can't type tabs), but after posting were mangled.
CuteAlien
Admin
Posts: 9647
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Improved screenquad

Post by CuteAlien »

The edit-box is not using the same source-code as the code-section formatting as that's a plugin (also not using a monospace font). But I just tested and yeah - the edit-box seems to interpret tabs as 8 spaces for display. So we have to figure out how to change that as well.

"One True style" probably means tab=8, so it worked for you before, but as Irrlicht uses tab = 4 it pretty much mangled most pasted code so far - especially any code pasted from Irrlicht sources (it always did convert tabs to spaces, you were just one of the few lucky guys so far). I think we should keep tab-size 4, just makes more sense using the Irrlicht formating in the Irrlicht forum. Sorry, followers of One True style have it hard in the c++ world ;-)
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
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Improved screenquad

Post by Mel »

Not bad, with a good combination of Material/renderTarget setting is posible to chain postpro effects with this. Nice!
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Improved screenquad

Post by hendu »

@Mel

That was possible with the old copy as well, my changes are merely optimization: the old one disabled backface culling and used tris, I changed it to tristrip with culling. Less data to upload and half the render cost by skipping back faces. I also moved duplicate code to the private function.
gerdb
Posts: 194
Joined: Wed Dec 02, 2009 8:21 pm
Location: Dresden, Germany

Re: Improved screenquad

Post by gerdb »

I don't think that works (tabs) inside a webbrowser text-element. I mean tabs _are_ replaced in your editor (you can set it in most) - so we have to do something with them here.
if you use <pre> or css attribute font-family:monotype it keeps tabs from text
CuteAlien
Admin
Posts: 9647
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Improved screenquad

Post by CuteAlien »

gerdb: But the code-field does need to interpret it in some way. Otherwise you have no idea on posting anymore how it will look on anyone's else system.
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
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Improved screenquad

Post by robmar »

Just an idea how about to make this into a node class, ISceneScreenQuadNode...
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Improved screenquad

Post by hendu »

Nope, it doesn't make any sense as a scene node. You don't want to draw this randomly among other objects, you use it manually when you know exactly what you want to do.

Parent-children relationships with a screen quad make no sense either.
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Improved screenquad

Post by robmar »

Good point. A plane mesh would be the thing to use I guess for rectangular flat surfaces, which is another thing altogether.
Post Reply