Results 1 to 5 of 5

Thread: A question regarding an entity's image.

  1. #1

    Question A question regarding an entity's image.

    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,


  2. #2
    Administrator Seth's Avatar
    Join Date
    Jul 2002


    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.
    Last edited by Seth; 11-15-2011 at 10:49 AM. Reason: oops, fixed a code problem I saw
    Seth A. Robinson
    Robinson Technologies

  3. #3

    Default RE: A question regarding an entity's image.

    You are a gentleman and a scholar. Thanks very much.

  4. #4

    Default RE: A question regarding an entity's image.

    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?


  5. #5
    Administrator Seth's Avatar
    Join Date
    Jul 2002


    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.
    Seth A. Robinson
    Robinson Technologies

Similar Threads

  1. Entity Layouts via XML!!!
    By BigBMan in forum Proton SDK
    Replies: 3
    Last Post: 10-28-2011, 05:48 PM
  2. Creating Entity on different map
    By kehran in forum Novashell Game Creation System
    Replies: 2
    Last Post: 07-19-2011, 02:04 AM
  3. SetFont() method for Entity text
    By garcia in forum Novashell Game Creation System
    Replies: 3
    Last Post: 12-08-2010, 05:51 AM
  4. What I would need to do to implement a new entity type or something?
    By speeder in forum Novashell Game Creation System
    Replies: 1
    Last Post: 08-18-2010, 05:10 AM
  5. Rendering into my custom image and then drawing this image to the display
    By ValkaVALES in forum Official ClanLib SDK Forums
    Replies: 4
    Last Post: 07-03-2007, 09:53 AM



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts