// on crée une texture de taille 2x2 pixels
sf::Texture texture;
texture.create(2, 2);
// on déclare un tableau de pixels bruts de 2x2
sf::Uint8 pixels[2 * 2 * 4];
// on bidouille autant qu'on veut dans le tableau de pixels...
// là par exemple on remplit tout de pixels verts semi-transparents
for (int x = 0; x < 2; ++x)
for (int y = 0; y < 2; ++y)
{
pixels[(x + y * 2) * 4 + 0] = 0; // composante rouge
pixels[(x + y * 2) * 4 + 1] = 255; // composante verte
pixels[(x + y * 2) * 4 + 2] = 0; // composante rouge
pixels[(x + y * 2) * 4 + 3] = 128; // composante alpha
}
// le tableau de pixels est prêt : on met à jour la texture
texture.update(pixels);
// plus tard, on affiche par exemple cette texture via un sprite
window.draw(sf::Sprite(texture));
Salut l'ami,
J'ai réussi à faire ce que je voulais faire ! Récupérer les pixels un par un selon l'orientation d'un rayon qui parcourt un scanline ! :-D
https://gyazo.com/792b4c053fe375425900b7316cb9fbab
Le GIF est de mauvaise qualité mais je te laisse voir le résultat sur le screenshot ici, on voit bien mieux :
https://image.noelshack.com/fichiers/2017/43/5/1509108663-yes.png
En gros je récupère pixel par pixel le long du parcours du rayon :
///RECUPERATION DU TRAIT DE PIXELS AU FUR ET A MESURE///
if (line[1].position.x >= 0 && line[1].position.x <= texture.getSize().x &&
line[1].position.y >= 0 && line[1].position.y <= texture.getSize().y)
{
redLine[1].position = {line[1].position.x, line[1].position.y};
sf::Color c = sf ::Color(img.getPixel((int)line[1].position.x, (int)line[1].position.y).r,
img.getPixel((int)line[1].position.x, (int)line[1].position.y).g,
img.getPixel((int)line[1].position.x, (int)line[1].position.y).b);
vecColors.push_back(c);
}
Et ensuite ma fonction d'assignation des pixels :
texStripe.create(1, vecColors.size());
sf::Uint8 pixels[vecColors.size()*4];
stripe[0].texCoords = {0,0};
stripe[1].texCoords = {0, vecColors.size()};
stripe[1].position = {stripe[0].position.x, vecColors.size()};
for (unsigned int i = 0 ; i < vecColors.size() ; i++)
{
pixels[(i)*4+0] = vecColors[i].r;
pixels[(i)*4+1] = vecColors[i].g;
pixels[(i)*4+2] = vecColors[i].b;
pixels[(i)*4+3] = vecColors[i].a;
}
texStripe.update(pixels);
Merci infiniment à toi !!
sf::Color c = sf ::Color(img.getPixel((int)line[1].position.x, (int)line[1].position.y).r,
img.getPixel((int)line[1].position.x, (int)line[1].position.y).g,
img.getPixel((int)line[1].position.x, (int)line[1].position.y).b);
Pourquoi pas juste
sf::Color c = img.getPixel((int)line[1].position.x, (int)line[1].position.y);
??