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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - AndrewB

Pages: 1 [2] 3
16
Graphics / Re: Slicing/extracting tiles from a grid of tiles
« on: August 12, 2012, 06:20:25 am »
Yes it is haha that's my bad, I apologize.

For some reason it was stuck in my head that sprites and textures were the same thing even though I was arguing differently.

17
Graphics / Re: Slicing/extracting tiles from a grid of tiles
« on: August 11, 2012, 06:08:33 pm »
This was an example.
Obviously no one does that.
sf::Texture tex;
tex.loadFromFile("whatever.tga");
std::vector<sf::Sprite> sprites;
for (int it=0;i<666;++it)
{
sprites.push_back(sf::Sprite(tex));
sprites[i].setTextureRect(insert rectangle here);
}
 

This code would still store the entire texture file with every new sprite created (from what the description of setTextureRect says). See the function that I posted a few messages back, that's what I'm using. It's basically what you just wrote without using the setTextureRect.

18
Graphics / Re: Slicing/extracting tiles from a grid of tiles
« on: August 11, 2012, 06:01:16 pm »
You can have ONE and only ONE sf::Texture and assign it to each of 225 sf::Sprite s and then set each Sprite's rectangle.

By doing this:
  sf::Texture tiles;
  tiles.loadFromFile("Resources/tiles.tga");
  sf::Sprite spr(tiles);
  spr.setTextureRect(sf::IntRect(0,0,25,25));

Each sprite loaded in memory will be storing the entire tiles.tga image.
EDIT: Just to clarify, the spr sprite in the code above will still be storing the same amount of data on the GPU both BEFORE and AFTER setTextureRect is called.

Could @Laurent please clarify if setTextureRect() frees up the memory of the unused portions of the sprites.

19
Graphics / Re: Slicing/extracting tiles from a grid of tiles
« on: August 11, 2012, 05:52:35 pm »
What? :o
Where is that stated?

http://www.sfml-dev.org/documentation/2.0/classsf_1_1Sprite.php#a3fefec419a4e6a90c0fd54c793d82ec2
Quote
Set the sub-rectangle of the texture that the sprite will display.

The texture rect is useful when you don't want to display the whole texture, but rather a part of it. By default, the texture rect covers the entire texture.

That wording suggests that it's only changing what is going to be displayed.

20
Graphics / Re: Slicing/extracting tiles from a grid of tiles
« on: August 11, 2012, 05:42:14 pm »
That's great and that's why tilesheets are good but why do you 'extract' them into single texture each at runtime instead of using sf::VertexArray or sf::Sprite::setTextureRect ?
Load your texture once and then make every sprite/your one huge vertex array use this texture with proper rectangle/coords.

void loadTextures(std::vector<sf::Texture>& texture_list) {
  sf::Image master;
  master.loadFromFile("Resources/tiles.tga");

  for (int x = 0; x < ps::ktexture_grid_size; x++) {
    for (int y = 0; y < ps::ktexture_grid_size; y++) {
      sf::Texture temp_texture;
      temp_texture.loadFromImage(master, sf::IntRect(x * ps::ktexture_size, y * ps::ktexture_size, ps::ktexture_size, ps::ktexture_size));
      texture_list.push_back(temp_texture);
    }; // for y
  }; // for x
} // void loadtextures

The tiles.tga file is loaded into memory, each texture is then created and stored on the gpu and then the image storing tiles.tga is freed.

From the definition of setTextureRect on the sfml documentation, EVERY texture would have to store the WHOLE tiles.tga image on the GPU (using 225 times more gpu memory than loading the textures individually). setTextureRect just modifies which part of the texture that will be drawn, it still keeps the whole texture in memory.

21
Graphics / Re: Slicing/extracting tiles from a grid of tiles
« on: August 11, 2012, 05:27:31 pm »
Instead of:
sf::Image tiles;
  tiles.loadFromFile("Resources/tiles.tga");
  sf::Image img;
  img.create(25,25);
  img.copy(tiles, 0, 0, sf::IntRect(0, 0, 25, 25));
  sf::Texture tex;
  tex.loadFromImage(img);
  sf::Sprite spr(tex);
You can do:
  sf::Texture tiles;
  tiles.loadFromFile("Resources/tiles.tga");
  sf::Sprite spr(tiles);
  spr.setTextureRect(sf::IntRect(0,0,25,25));

Why do you 'extract' tiles from tilesheet anyway?

That's the method that I'm using now (see above post).

I'm want to keep the tiles in a single image so it's easier to update/change any of the tiles while developing and post-release. Plus it keeps my resources file clean.

Edit: Oh no, I just re-read what you posted. Would that method not keep the entire tiles.tga file loaded for every texture though?

22
Graphics / Re: Slicing/extracting tiles from a grid of tiles
« on: August 11, 2012, 05:20:27 pm »
Before copying "tiles" to "img", "img" must be created (with a valid size). You can't copy an image to an empty one, it doesn't expand automatically.

Thanks Laurent.

I have changed the way I load the textures, removing the need for the new sf::Image.
void loadTextures(std::vector<sf::Texture>& texture_list) {
  sf::Image master;
  master.loadFromFile("Resources/tiles.tga");

  for (int x = 0; x < ps::ktexture_grid_size; x++) {
    for (int y = 0; y < ps::ktexture_grid_size; y++) {
      sf::Texture temp_texture;
      temp_texture.loadFromImage(master, sf::IntRect(x * ps::ktexture_size, y * ps::ktexture_size, ps::ktexture_size, ps::ktexture_size));
      texture_list.push_back(temp_texture);
    }; // for y
  }; // for x
} // void loadtextures

23
Graphics / Re: Slicing/extracting tiles from a grid of tiles
« on: August 11, 2012, 03:11:42 pm »
You'll be having same pixels in memory few times if you do what you did in first post, sprites have subRects you can set to make them use just part of texture.

See: http://en.sfml-dev.org/forums/index.php?topic=8844.msg59455#msg59455

Is that what you meant?

24
Graphics / Re: Slicing/extracting tiles from a grid of tiles
« on: August 11, 2012, 12:36:58 pm »
Problem solved for now - I've cut out the second img and just loaded the texture using sf::Texture.loadFromImage(src, area);

25
Graphics / Re: Slicing/extracting tiles from a grid of tiles
« on: August 11, 2012, 12:05:20 pm »
Quote
The supported image formats are bmp, png, tga, jpg, gif, psd, hdr and pic. Some format options are not supported, like progressive jpeg. If this function fails, the image is left unchanged.

http://www.sfml-dev.org/documentation/2.0/classsf_1_1Image.php#a9e4f2aa8e36d0cabde5ed5a4ef80290b

26
Graphics / Slicing/extracting tiles from a grid of tiles
« on: August 11, 2012, 11:22:40 am »
Hey everyone,

I'm trying to copy a 25x25 pixel area from a master textures file and when I try and run my game this error appears in the output:


This is the code that I'm using:
  sf::Image tiles;
  tiles.loadFromFile("Resources/tiles.tga");

  sf::Image img;
  img.copy(tiles, 0, 0, sf::IntRect(0, 0, 25, 25)); // extracts the first 25x25 tile from "tiles"
 
  sf::Texture tex;
  tex.loadFromImage(img); // loads the texture from "img" which is just the first 25x25 tile

Is there any reason that I'm not seeing that is causing this?

Thanks,
Andrew

27
Oh, may I ask why it's stuck in RC?

28
Graphics / Re: [SFML-2.0-rc][VC++2008] sf::Texture.loadFromFile problems
« on: August 06, 2012, 03:26:16 pm »
Thanks again Laurent!

How are you able to keep up with all of these support threads AND develop SFML at the same time?!

29
Hi everyone,

I'm using VC++ 2008 with the SFML 2.0 release candidate.

I have just started using the SFML SDK today and I'm slowly familiarizing myself with the smaller components of the graphics library first.

The problem I'm running into is when I try to debug my program (source below) it can't seem to locate local files on my hard drive. When I run the .exe created in the debug directory however, it is able to load the texture file perfectly fine.

Example of debugging:


When I run the compiled exe directly:


And my source code:
#include <vector>

#include <SFML/Graphics.hpp>

const sf::Color kvoid_color(40, 40, 40, 255);

int main() {
  sf::RenderWindow window(sf::VideoMode(800, 600), "Profound Seeker");
  window.setVerticalSyncEnabled(true);

  sf::Texture grass_texture;
  grass_texture.loadFromFile("Resources/grass_tile.bmp");
 
  sf::Sprite grass_sprite;
  grass_sprite.setTexture(grass_texture);
  grass_sprite.setTextureRect(sf::IntRect(0, 0, 40, 40));
  grass_sprite.move(100, 100);
  //grass_sprite.rotate(23.f);

  while (window.isOpen()) {
    sf::Event event;
    while (window.pollEvent(event)) {
      if (event.type == sf::Event::Closed)
        window.close();
    }; // while window.pollEvent(event)

    window.clear(kvoid_color);
    window.draw(grass_sprite);
    window.display();
  }; // while while window.isOpen()

  return 0;
}; // int main

Thanks to all who can help!

30
General / Re: Linker problems setting up SFML2 rc with VC++ 2008
« on: August 06, 2012, 08:57:33 am »
So the conclusion is that ";" should not be used as a separator (I think you must use spaces -- use the "..." button to edit the list if you're not sure)

That fixed the error! Thanks Laurent. I guess I should have tried to use the [...] button to add them in the first place.


Pages: 1 [2] 3
anything