Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: RenderImage doesn´t exist anymore in SFML.Net 2.2?  (Read 3035 times)

0 Members and 1 Guest are viewing this topic.

Tigre Pablito

  • Full Member
  • ***
  • Posts: 225
    • View Profile
    • Email
RenderImage doesn´t exist anymore in SFML.Net 2.2?
« on: March 19, 2019, 09:13:57 pm »
Hi,

I would like to be able to copy an Image onto another Image faster than with the Copy() function. A time ago I posted in the forum and I was told to use RenderTexture. I tried that, but without success. A few days ago I googled and found RenderImage class. But it seems it doesn´t  exist in SFML.Net 2.2 ... ? Why? Or am I wrong?

If RenderImage class is not available, could someone tell me the way to do this (if there is)?
Thanks
Pablo

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: RenderImage doesn´t exist anymore in SFML.Net 2.2?
« Reply #1 on: March 20, 2019, 07:55:21 am »
RenderImage is the former name of RenderTexture, in SFML 1.x.

If you have problems with RenderTexture, then describe them and we'll try to help.
Laurent Gomila - SFML developer

Tigre Pablito

  • Full Member
  • ***
  • Posts: 225
    • View Profile
    • Email
Re: RenderImage doesn´t exist anymore in SFML.Net 2.2?
« Reply #2 on: March 22, 2019, 03:34:01 am »
Hi

How could I use the RenderTexture to make my tiles (Images) be drawn onto the bigger Image?

I tried this

// I need to "tile copy" Image tile (128x128) onto Image image (16000x3000)
RenderTexture rt;
Sprite spr;
rt = new RenderTexture(XLIM, YLIM);
rt.Clear();
for (a=0;a<XLIM/128;a++)
    for (b=0;b<YLIM/128;b++){
        spr = new Sprite(new Texture(tile))
        spr.Position=new Vector2f(a*128, b*128);       
        rt.Draw(spr);
}
rt.Display();

image.Copy(rt.Texture.CopyToImage());
//

Is this the fastest way?

Thank you very much

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: RenderImage doesn´t exist anymore in SFML.Net 2.2?
« Reply #3 on: March 22, 2019, 06:38:23 am »
I would probably do it this way, yes. Is it too slow for you?

Be aware that a texture size of 16000x3000 may not be supported by many GPUs.
Laurent Gomila - SFML developer

Tigre Pablito

  • Full Member
  • ***
  • Posts: 225
    • View Profile
    • Email
Re: RenderImage doesn´t exist anymore in SFML.Net 2.2?
« Reply #4 on: March 26, 2019, 03:49:01 am »
Hi,

I would probably do it this way, yes. Is it too slow for you?

Actually, my code, which before took several seconds on performing an "image building" with a lot of SetPixel() calls, now with the RenderTexture code added, it takes more or less the same. So I assume it must be very fast  :)

Be aware that a texture size of 16000x3000 may not be supported by many GPUs.

My system supports only 1024x1024 Textures (so, I have to split the level image into several Textures, as you told me several years ago ... remember? ;D) ... what is 16000x3000 are the Image and the RenderTexture  ;)

Thanks a lot for your help

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: RenderImage doesn´t exist anymore in SFML.Net 2.2?
« Reply #5 on: March 26, 2019, 07:52:21 am »
Quote
Actually, my code, which before took several seconds on performing an "image building" with a lot of SetPixel() calls, now with the RenderTexture code added, it takes more or less the same.
Maybe this is because you're loading the same texture again and again for every single tile that you draw, instead of just once at init time.

Quote
what is 16000x3000 are the Image and the RenderTexture
As its name implies, a RenderTexture is (has) a Texture, so when you create a 16000x3000 RenderTexture you're also creating a 16000x3000 Texture.
Laurent Gomila - SFML developer

Tigre Pablito

  • Full Member
  • ***
  • Posts: 225
    • View Profile
    • Email
Re: RenderImage doesn´t exist anymore in SFML.Net 2.2?
« Reply #6 on: April 01, 2019, 03:16:24 am »
Quote
Quote
Actually, my code, which before took several seconds on performing an "image building" with a lot of SetPixel() calls, now with the RenderTexture code added, it takes more or less the same.
Maybe this is because you're loading the same texture again and again for every single tile that you draw, instead of just once at init time.

I meant that other stuff my code did was the cause of the delay, and that adding the RenderTexture code didn´t extend it. The code I posted before was "abbreviated" ... I assumed you would assume that  ;), ... I am an "a bit old" programmer  8)
Actually my code is (now, with the fix of the Texture size)

        private void FillWithTile(int tile)
        {
            RenderTexture rt = new RenderTexture(1024, 1024);
            Texture img = new Texture(Images.bkgnds[tile]);
            Sprite spr = new Sprite(img);
            int a, b;

            rt.Clear();
            for (a = 0; a < 8; a++)
                for (b = 0; b < 8; b++)
                {
                    spr.Position = new Vector2f(a * 128, b * 128);
                    rt.Draw(spr);
                }
            rt.Display();

            for (a = 0; a < XLIM / 1000; a++)
                for (b = 0; b < YLIM / 1000; b++)
                    image.Copy(rt.Texture.CopyToImage(), (uint)(a * 1024), (uint)(b * 1024));
        }
 

Quote
Quote
what is 16000x3000 are the Image and the RenderTexture
As its name implies, a RenderTexture is (has) a Texture, so when you create a 16000x3000 RenderTexture you're also creating a 16000x3000 Texture.

Yes, I realized just now that, though it didn't throw an error, it wasn´t drawing the tiles (now it is)

Thank you
« Last Edit: April 01, 2019, 07:52:41 am by Laurent »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: RenderImage doesn´t exist anymore in SFML.Net 2.2?
« Reply #7 on: April 01, 2019, 07:55:19 am »
You should call rt.Texture.CopyToImage() once and store the result, it is an expensive call.

And I don't get why you're dividing XLIM and YLIM by 1000 and not 1024.
Laurent Gomila - SFML developer

Tigre Pablito

  • Full Member
  • ***
  • Posts: 225
    • View Profile
    • Email
Re: RenderImage doesn´t exist anymore in SFML.Net 2.2?
« Reply #8 on: April 02, 2019, 10:55:17 pm »
You should call rt.Texture.CopyToImage() once and store the result, it is an expensive call.

One always learns something new  :) ... but ... I should have guessed that. Thanks  :D

And I don't get why you're dividing XLIM and YLIM by 1000 and not 1024.

The image is 16000x3000, if I divide by 1024 an space on the image's right and bottom would remain not "painted", because (16000 / 1024) * 1024 = 15360, not 16000. Also it happens with 3000 / 1024.

So I had to divide by 1000 to get all the image "painted", ... or maybe I should have done this?

Math.Ceiling((double)XLIM / 1024.0)

but I didn't worry about that because that "image creating" won't happen on game release, and in this case it is the same

 

anything