View Full Version : A question regarding an entity's image.

11-10-2011, 02:22 PM
Hi there,

I was just wondering if anyone could dispense some advice on something I am having great trouble implementing.
My plan is to have a very basic "paint" style menu, where the user's click alters the image of an entity.
I have managed to get to a point where a function is called when the "canvas" entity is clicked, and the co-ordinates of the click and the entity itself is passed to said function, but I cannot fathom how to gain access to the image for the entity.
I am not using Irrlicht for this particular menu, but i fear that only Open-gl ES can provide a solution.

Any advice would be greatly appreciated,


11-15-2011, 05:27 AM
Hmm, it's a tricky problem.

I'd probably start with creating a 32 bit image in memory and setting it all to blue, then putting it in a texture and blitting it. After that, you just need to change it, put it in a texture again, and blit it again, everytime the user "draws".

Ok, unchecked code ahead:

//make our raw version of the image

int sizeX = sizeY = 128;
uint32 *pMyPic = new uint32[sizeX*sizeY];

for (int i=0; i < sizeX*sizeY; i++)
pMyPic[i] = MAKE_RGBA(100,0,0,255); //100 blue, 255 alpha so it's not transparent

//put it on a surface and display it
Surface s;
s.InitBlankSurface(sizeX, sizeY);
s.UpdateSurfaceRect(rtRect(0,0,sizeX,sizeY), pMyPic, false);

//wait a frame, and see if a blue square appears. If it does, it worked.

Next, you'd change pMyPic some (possibly from touch input, to draw) then use UpdateSurfaceRect again. This is probably too slow, so in "real life" you'd need to blit only the part that changed (although I seem to remember that being just as slow on iOS..) or you would draw over the screen new images to fake the drawing, then actually update the texture later, after enough changes amass to help with speed.

11-15-2011, 09:09 AM
You are a gentleman and a scholar. Thanks very much. :)

11-21-2011, 12:21 PM
Hi Seth.
Just a quick one. I've got everything working with the exceptoin that I cant get a SoftSurface to render.
I have declared it, and populated it, but I cant get the thing to render. Do i need to attach it to an entity to see it?


11-23-2011, 12:10 PM
Well - SoftSurface is sort of a software surface and can't really draw anything to the screen itself - to render it you have to put it on a GL surface, so to do that:

pretend g_pSurface is a global or something:

Surface *g_pSurface = mySoftSurface.CreateGLTexture(); //up to you to delete it when you're done

then, every frame in your App::Render():


That would be to blit manually.

A different way, putting it into an Entity to draw for you would be like this:

SoftSurface s; //assume you have a valid image in this

//first let's convert it to a GL surface.. we'll do it manually this time

SurfaceAnim *pSurf = new SurfaceAnim;
pSurf->SetTextureType(Surface::TYPE_DEFAULT); //insure no mipmaps are created
pSurf->UpdateSurfaceRect(rtRect(0,0, s.GetWidth(), s.GetHeight()), s.GetPixelData());

//create an entity and give it our custom surface, instead of having it just load a file like we normally do
Entity *pEnt = CreateOverlayEntity(pBG, "MyEntity", "", 0,0);
OverlayRenderComponent *pOverlay = (OverlayRenderComponent*) pEnt->GetComponentByName("OverlayRender");
pOverlay->SetSurface(pSurf, true); //the true says also please delete our custom surface for us when it's done

//it will now render, assuming the entity we attached it to (pBG) has focus to render.