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 - yuxuwu

Pages: [1]
1
Graphics / Re: Texture stops updating midway through
« on: August 22, 2017, 07:06:45 pm »
Thank you! The fix seemed to do the trick. Can't believe that flew over my head.

2
Graphics / Texture stops updating midway through
« on: August 22, 2017, 05:43:19 pm »
Hello,

I'm new to SFML so I've been stuck on this for a little while now, but it seems like the texture for my sprite only loads midway through. I want to display a 2D array of pixels to a window, so I wanted to see if I could fill up an entire window with a solid color as a test.
Here's a snippet of my code:
 
    sf::RenderWindow window(sf::VideoMode(WINSIZE_X, WINSIZE_Y), "My Window");
    sf::Sprite sprite;
    sf::Texture texture;
    sf::Uint8 *pixels = new sf::Uint8[WINSIZE_X * WINSIZE_Y * 4];

    if (!texture.create(WINSIZE_X, WINSIZE_Y)) {
        std::cout << "Error: texture could not be created" << std::endl;
    }

    while(window.isOpen()) {
        //Update texture
        for(int y = 0; y < WINSIZE_Y; y++) {
          for(int x = 0; x < WINSIZE_X; x++) {
            pixels[(y*WINSIZE_X)+(4*x)]       = 255; // R
            pixels[(y*WINSIZE_X)+(4*x)+1]     = 255; // G
            pixels[(y*WINSIZE_X)+(4*x)+2]     = 0; // B
            pixels[(y*WINSIZE_X)+(4*x)+3]     = 200; // A
          }
        }
        texture.update(pixels);

        //Update sprite with texture
        sprite.setTexture(texture);

        //Clear window
        window.clear(sf::Color::Black);

        //Draw everything
        window.draw(sprite);
        window.display();
    }
 

WINSIZE_X and WINSIZE_Y are defined as 800 and 600 respectively.

Sorry if this is a stupid question, but thanks in advanced for any assistance!

Pages: [1]