#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?