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.

Improved screenquad

Postby hendu » Thu Jul 05, 2012 9:36 pm

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.

cpp 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);
    }
};
 
hendu
 
Posts: 1552
Joined: Sat Dec 18, 2010 12:53 pm

Re: Improved screenquad

Postby CuteAlien » Fri Jul 06, 2012 10:19 am

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.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5349
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: Improved screenquad

Postby hendu » Fri Jul 06, 2012 10:20 am

The ideal behavior would be "don't touch it", ie keep tabs tabs and spaces spaces without any transformations.
hendu
 
Posts: 1552
Joined: Sat Dec 18, 2010 12:53 pm

Re: Improved screenquad

Postby CuteAlien » Fri Jul 06, 2012 10:22 am

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.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5349
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: Improved screenquad

Postby CuteAlien » Fri Jul 06, 2012 10:33 am

Just wondering how it messed up in your case - are you using a tabsize of 8 maybe?
IRC: #irrlicht on irc.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5349
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: Improved screenquad

Postby hendu » Fri Jul 06, 2012 5:54 pm

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.
hendu
 
Posts: 1552
Joined: Sat Dec 18, 2010 12:53 pm

Re: Improved screenquad

Postby CuteAlien » Fri Jul 06, 2012 9:15 pm

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.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5349
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: Improved screenquad

Postby Mel » Fri Jul 06, 2012 11:02 pm

Not bad, with a good combination of Material/renderTarget setting is posible to chain postpro effects with this. Nice!
http://santiagong.daportfolio.com/
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
User avatar
Mel
Competition winner
 
Posts: 1783
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Improved screenquad

Postby hendu » Sat Jul 07, 2012 11:58 am

@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.
hendu
 
Posts: 1552
Joined: Sat Dec 18, 2010 12:53 pm

Re: Improved screenquad

Postby gerdb » Fri Jul 27, 2012 1:37 pm

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
gerdb
 
Posts: 168
Joined: Wed Dec 02, 2009 8:21 pm
Location: Dresden, Germany

Re: Improved screenquad

Postby CuteAlien » Fri Jul 27, 2012 1:48 pm

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.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5349
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: Improved screenquad

Postby robmar » Sat Aug 18, 2012 1:01 pm

Just an idea how about to make this into a node class, ISceneScreenQuadNode...
robmar
 
Posts: 565
Joined: Sun Aug 14, 2011 11:30 pm

Re: Improved screenquad

Postby hendu » Sat Aug 18, 2012 1:08 pm

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.
hendu
 
Posts: 1552
Joined: Sat Dec 18, 2010 12:53 pm

Re: Improved screenquad

Postby robmar » Sat Aug 18, 2012 2:12 pm

Good point. A plane mesh would be the thing to use I guess for rectangular flat surfaces, which is another thing altogether.
robmar
 
Posts: 565
Joined: Sun Aug 14, 2011 11:30 pm


Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 1 guest