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

Author Topic: texture size limitation  (Read 1595 times)

0 Members and 1 Guest are viewing this topic.

zionsholder

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
texture size limitation
« on: May 13, 2012, 09:26:42 am »
Code: [Select]

#include <SFML\Window.hpp>
#include <SFML\Graphics.hpp>

int main()
{
//initialize window
sf::RenderWindow window(sf::VideoMode(800, 600), "Project: Searching Blind",sf::Style::Titlebar);
srand(time(NULL));

//create drawing tools
sf::Image image;
sf::Texture texture;
sf::Sprite sprite;

//create program varriables
int width = 4096,height = 600;
int r,g,b;
int offsetx=0,offsety=0;

//initialize drawing tools
image.create(width,height);
texture.create(width,height);

//draw a map of random colored pixles
for (int x = 0;x<width;x++)
{
for(int y = 0;y<height;y++)
{
r =rand()%255;
g =rand()%255;
b =rand()%255;
image.setPixel(x,y,sf::Color(r,g,b));
}
}

//load the drawn image to the texture
texture.loadFromImage(image);
//loat the texture to the sprite
sprite.setTexture(texture);
//set the sprite at postion 0,0
sprite.setPosition(0,0);


//main game loop
    while (window.isOpen())
    {
//test events
sf::Event Event;
        while (window.pollEvent(Event))
{
            if (Event.type == sf::Event::Closed)
window.close();
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
window.close();
}
//test for keyboard input
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
offsetx--;
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
offsetx++;
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
offsety--;
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
offsety++;

//set the sprite texture rect based on the keyboard input
sprite.setTextureRect(sf::IntRect(offsetx,offsety,window.getSize().x,window.getSize().y));

//clear window, draw sprite, and display it
window.clear();
window.draw(sprite);
window.display();
       }
}

this is a sample of code that displays a problem for me. I am writing a side-scroller and i need a map that is 500 pixels tall by at least 10,000 wide, and potentially wider. the problem I have is that the width of the sf::texture object is limited by my graphics driver, which only allows the textures to be 4096 by 4096. the code I have supplied works fine, until I change the width variable to 4097, and then I just get a white square. also on my friends computer, it doesn't even work in this current state because he has an older graphics driver. I assume that the solution has something to do with using sf::RenderTexture but I can not think of a perfect fix. I need to build a large sf::Image on the fly in RAM, and then change it to where I can use it in a sprite for a side-scroller. any suggestions?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: texture size limitation
« Reply #1 on: May 13, 2012, 09:51:42 am »
You must split the big image into several smaller textures.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: texture size limitation
« Reply #2 on: May 13, 2012, 09:57:58 am »
I have written thor::BigSprite to cope with this issue. However, a setTextureRect() method is not yet implemented, but planned for Thor 2.1...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

zionsholder

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: texture size limitation
« Reply #3 on: May 13, 2012, 11:21:23 am »
Ok, so use the getMaximumSize member function on startup, and use that to determine the size of the texture array needed to hold all of the data? would that method work?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: texture size limitation
« Reply #4 on: May 13, 2012, 01:57:17 pm »
Yes, that's how I do it. You can also look at my source code or even expand it, if you want.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything