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

Author Topic: Maximum size of an texture  (Read 3288 times)

0 Members and 1 Guest are viewing this topic.

Carlos Augusto Br Cpp

  • Newbie
  • *
  • Posts: 40
  • Programming is life
    • View Profile
    • Email
Maximum size of an texture
« on: September 07, 2016, 01:53:51 am »
Hey guys..I have a problem... I am studying SFML and trying to mix some things and I have picked an image for my background that his size is 2048x2048...I declare all things...a chainsaw sprite that will rotate while the window is open and the background sprite....everything seems to be fine..but when I try to execute only the chainsaw appears rotating...and in console show a message like this: Failed to create texture, its internal size too high (2048x2048, maximum is 1024x1024)

and here is my code:

/*****************************************************
* HEADERS
******************************************************/

#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>

// Main function of C++ programs
int main(int argc,char* argv[])
{
    /***********************************************************
    * WINDOW
    ************************************************************/


    // Set up the main window and enable framerate limit to 60
    sf::RenderWindow window(sf::VideoMode(800,600), "SFML Test");
    window.setFramerateLimit(60);

    // Set an view and his properties
    sf::View view;
    view.reset(sf::FloatRect(50, 50, 1024, 768));

    /***********************************************************
    * GRAPHICS
    ************************************************************/

    // Texture for the background
    sf::Texture main_BG;
    main_BG.loadFromFile("Resources/BG01.png");

    // Texture for the chainsaw sprite
    sf::Texture chainsaw_texture;
    chainsaw_texture.loadFromFile("Resources/Chainsaw.png");

    // Properties of the BackGround (sprite)
    sf::Sprite background;
    background.setTexture(main_BG);
    background.setPosition(0,0);
    background.setColor(sf::Color::Blue);

    // Properties of the chainsaw sprite
    sf::Sprite chainsaw;
    chainsaw.setTexture(chainsaw_texture);
    chainsaw.setPosition(400,300);
    chainsaw.setOrigin(117,115);

    /*************************************************************
    * Main Loop
    **************************************************************/

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

        /**********************************************************
        * KEYBOARD OR JOYSTICK INPUT
        ***********************************************************/

        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
        {
            view.move(-5,0);
        }

        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
        {
            view.move(5,0);
        }

        // Set what view we'll use
        window.setView(view);

        // Clear the window
        window.clear(sf::Color::White);

        // Do the draw call's
        window.draw(background);
        window.draw(chainsaw);

        // Rotate the chainsaw sprite while the window is open
        chainsaw.rotate(5);

        // Update the screen
        window.display();

    }
}

 

So...the really question is...Have I an option to solve this or the only option is to use a background texture at internal size of 1024x1024??

DarkRoku12

  • Full Member
  • ***
  • Posts: 203
  • Lua coder.
    • View Profile
    • Email
Re: Maximum size of an texture
« Reply #1 on: September 07, 2016, 02:36:36 am »
You can split up the texture in several sprites by:
Loading the texture in a sf::Image and split up in several textures and then draw the sprites in the desire positions taking into account the offset.

If you are using (or plan to use) Thor you can take a look at: thor::BigTexture

If you don't want to include thor you can take a look at its source and build your own class.

« Last Edit: September 07, 2016, 02:42:47 am by DarkRoku »
I would like a spanish/latin community...
Problems building for Android? Look here

Carlos Augusto Br Cpp

  • Newbie
  • *
  • Posts: 40
  • Programming is life
    • View Profile
    • Email
Re: Maximum size of an texture
« Reply #2 on: September 07, 2016, 04:31:23 am »
Thanks master...helps a lot...maybe I'll take a look in Thor...maybe  :D