Page 1 of 1

Improved screenquad

Posted: Thu Jul 05, 2012 9:36 pm
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);
    }
};
 

Re: Improved screenquad

Posted: Fri Jul 06, 2012 10:19 am
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...

Re: Improved screenquad

Posted: Fri Jul 06, 2012 10:20 am
by hendu
The ideal behavior would be "don't touch it", ie keep tabs tabs and spaces spaces without any transformations.

Re: Improved screenquad

Posted: Fri Jul 06, 2012 10:22 am
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.

Re: Improved screenquad

Posted: Fri Jul 06, 2012 10:33 am
by CuteAlien
Just wondering how it messed up in your case - are you using a tabsize of 8 maybe?

Re: Improved screenquad

Posted: Fri Jul 06, 2012 5:54 pm
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.

Re: Improved screenquad

Posted: Fri Jul 06, 2012 9:15 pm
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 ;-)

Re: Improved screenquad

Posted: Fri Jul 06, 2012 11:02 pm
by Mel
Not bad, with a good combination of Material/renderTarget setting is posible to chain postpro effects with this. Nice!

Re: Improved screenquad

Posted: Sat Jul 07, 2012 11:58 am
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.

Re: Improved screenquad

Posted: Fri Jul 27, 2012 1:37 pm
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

Re: Improved screenquad

Posted: Fri Jul 27, 2012 1:48 pm
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.

Re: Improved screenquad

Posted: Sat Aug 18, 2012 1:01 pm
by robmar
Just an idea how about to make this into a node class, ISceneScreenQuadNode...

Re: Improved screenquad

Posted: Sat Aug 18, 2012 1:08 pm
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.

Re: Improved screenquad

Posted: Sat Aug 18, 2012 2:12 pm
by robmar
Good point. A plane mesh would be the thing to use I guess for rectangular flat surfaces, which is another thing altogether.