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

Author Topic: Image loading question  (Read 4675 times)

0 Members and 1 Guest are viewing this topic.

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Image loading question
« on: March 26, 2011, 11:36:31 pm »
Hello, when a sf::Image is loaded, and it gives an error of the kind "resolution not supported by graphic card" because it is too big, i know it won't be usable as a Sprite, but are the pixels loaded? as if i wanted to manipulate the image?

Thanks

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Image loading question
« Reply #1 on: March 26, 2011, 11:39:02 pm »
Nop, it's either a full success or a failure, there's nothing in between.

I know I should separate the "image in RAM" and "OpenGL texture" concepts in two separate classes, but... I still haven't found how to make it easy enough :)
Laurent Gomila - SFML developer

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Image loading question
« Reply #2 on: March 26, 2011, 11:52:26 pm »
I suggest a new parameter to LoadFromFile() with a default value.

Image.LoadFromFile("mypng.png", true);

being the "true" something like "Keep the pixels".

sf::Image::LoadFromFile(string Filename, bool KeepPixels = false){...}

What do you think?

No change at all for sfml users and a new option is added if thats the user's will :)

Plus, shouldnt be too painful to implement the new functionality :P

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Image loading question
« Reply #3 on: March 27, 2011, 12:01:46 am »
How would that help to solve your problem? Isn't it the opposite, keeping the pixels but not the texture?
Laurent Gomila - SFML developer

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Image loading question
« Reply #4 on: March 27, 2011, 12:30:45 am »
I meant, in case of failure, allow the user to keep the pixels in sf::Image, while not having a GL texture :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Image loading question
« Reply #5 on: March 27, 2011, 11:15:46 am »
Ah, I thought it was "store pixels in RAM or not".

So... I don't like your idea at all ;) It would produce half-working objects. In my opinion this feature requires a new design, not just a boolean flag in a function.

Something like:
Code: [Select]
sf::Image image;
image.LoadFromFile(...);
// get/set pixels

sf::Texture texture;
texture.LoadFromImage(image);
// bind

But less complicated (three different classes to display something on screen is too much).
Laurent Gomila - SFML developer

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Image loading question
« Reply #6 on: March 27, 2011, 03:35:18 pm »
I agree with your opinion, even tough it still makes sense to me that LoadFromFile actually loads something, even if too big for the gpu :D

LoadFromFile would still return false, as the texture failed to load, but the pixels were actually loaded in memory. I think it makes sense specially because we must check if the image loaded sucessfully or not.

Also, sf::Image could have a new method, for a RAM load only, something only for that purpose :D

But no hurries, think about it and decide whats best, i really trust your judgement :D

Thanks

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Image loading question
« Reply #7 on: March 27, 2011, 05:30:45 pm »
This is a very inconsistent design, if I add the option to load pixels only to the RAM (which is an important feature in my opinion) it will definitely not do it this way.
Laurent Gomila - SFML developer

devlin

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Image loading question
« Reply #8 on: March 27, 2011, 05:58:23 pm »
Perhaps separate Texture and Image? Although that would break a lot of existing code. Another option would be to subclass an ImageBuffer of sorts?

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Image loading question
« Reply #9 on: March 27, 2011, 06:58:22 pm »
Yeah, i agree to leaving Image as it is, and creating something else specificly for this ;D

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Image loading question
« Reply #10 on: March 28, 2011, 03:41:48 am »
I think sf::Texture (being the same as the current sf::Image) and sf::Image (RAM only, Texture can be built from it, possibly?) would be good.
I use the latest build of SFML2

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Image loading question
« Reply #11 on: March 28, 2011, 07:57:05 am »
It's a good design but it makes things really complicated for people who just want to load a sprite:
Code: [Select]
sf::Image image;
image.LoadFromFile("sprite.png");

sf::Texture texture;
texture.LoadFromImage(image);

sf::Sprite sprite;
sprite.SetTexture(texture);

And if you want to modify pixels (set a transparent color, replace pixels, or whatever) you must keep the three objects.
Laurent Gomila - SFML developer

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Image loading question
« Reply #12 on: March 28, 2011, 03:35:45 pm »
Quote from: "Laurent"
It's a good design but it makes things really complicated for people who just want to load a sprite:
Code: [Select]
sf::Image image;
image.LoadFromFile("sprite.png");

sf::Texture texture;
texture.LoadFromImage(image);

sf::Sprite sprite;
sprite.SetTexture(texture);

And if you want to modify pixels (set a transparent color, replace pixels, or whatever) you must keep the three objects.
It shouldn't be required to load a texture from an image, just an option, imo. I think you should still be able to load texture from files/memory/etc, just add images as one more option.
I use the latest build of SFML2

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Image loading question
« Reply #13 on: March 28, 2011, 03:43:31 pm »
Quote
It shouldn't be required to load a texture from an image, just an option, imo. I think you should still be able to load texture from files/memory/etc, just add images as one more option.

Good point.
Laurent Gomila - SFML developer