Hi everyone!
i'm a very newbie with SFML, in trying to learn how to display my pixels array and refreshing window when needed. I've make this very basic program, it works, make me change the intesity of blue (whitch fill the window) based on my input but it works just for 2 or 3 seconds! Then the window doesn't not respond and freeze.
I'm using CodeBlocks
#include <SFML\Graphics.hpp>
#include <SFML\Window.hpp>
#include <conio.h>
int main()
{
const unsigned int width = 640;
const unsigned int height = 480;
//SFML THINGS
sf::RenderWindow window(sf::VideoMode(width, height), "SFML Single Pixel");
window.setFramerateLimit(30);
sf::Texture texture; texture.create(width, height);
sf::Sprite sprite; sprite.setTexture(texture, true);
sf::Uint8* pixels = new sf::Uint8[width * height * 4];
//VARIABLES
short color=100;
//MAIN LOOP
while(true){
//INPUT
input = getch();
switch(input){
case '1': color = 0; break;
case '2': color = 66; break;
case '3': color = 122; break;
case '4': color = 188; break;
}
//UPDATING PIXELS ARRAY
for (int i = 0; i < width*height*4; i+=4)
{
pixels = color;
pixels[i+1] = color;
pixels[i+2] = 255;
pixels[i+3] = 255;
}
//UPDATING WINDOW?
texture.update(pixels);
sprite.setTexture(texture);
window.draw(sprite);
window.display();
}
return 0;
}