(first of all, sorry for my bad english, its not my native language)
Hi!
I'm using SFML v2.3, Mingw32 v4.7.1 (Code::Blocks default) and Windows 10.
I'm trying to make an application to test the sf::Image class and render single pixels, but everytime i try to do a simple loop using sf::Image::setPixel it crashes...
#include <SFML/Graphics.hpp>
#include <iostream>
int loopCount = 0;
const int Largura = 800;
const int Altura = 600;
int main()
{
//Setup Window
sf::RenderWindow window(sf::VideoMode(Largura, Altura), "yay");
window.setVerticalSyncEnabled(true);
// create an empty 800x600 texture
sf::Texture texture;
if (!texture.create(800, 600))
{
std::cout << "Fail to create the texture";
}
// create an black image
sf::Image image;
image.create(800, 600, sf::Color::Black);
// Set the texture to be the image and create the Sprite to render
texture.update(image);
sf::Sprite sprite;
sprite.setTexture(texture);
//the loop that is crashing the program
//it should create a diagonal line of white pixels
for(int i=0; i<=600; i++){
image.setPixel(i, i, sf::Color::White);
}
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
//The actual Rendering
window.clear();
texture.update(image);
window.draw(sprite);
window.display();
}
return 0;
}
What am i doing wrong? I am not suposed to manipulate pixels like that?