Im on Windows 8.1 with MinGw32 4.8.1-4 using SFML 2.1. Because all precompiled versions don't work, but it's not the point.
I have
m_pixels = new Colour[width*height];
where Colour have
unsigned char r,g,b,a;
Now I'm trying to rewrite all pixels from
m_pixels to
sf::Uint8 * pixels = new sf::Uint8[img_size.x*img_size.y*4];
using
void RenderTarget::rewritePixelForTexture(d_type::Bubyte* pixels)
{
for (d_type::Bint i=0; i<m_size.x*m_size.y ; i++)
{
d_type::Bint k=i*4;
pixels[k+3]=m_pixels[i].a;
pixels[k+2]=m_pixels[i].r;
pixels[k+1]=m_pixels[i].g;
pixels[k] =m_pixels[i].b;
}
}
Whole main.cpp :
sf::RenderWindow window(sf::VideoMode(img_size.x, img_size.y), "RENDERER!");
sf::Texture texture;
if (!texture.create(img_size.x, img_size.y))
{
std::cout<<"ERROR WITH TEXTURE\n";
}
sf::Sprite sprite(texture);
sf::Uint8 * pixels = new sf::Uint8[img_size.x*img_size.y*4];
sf::Clock FPSClock;
std::stringstream ss;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
file->rewritePixelForTexture(pixels);
texture.update(pixels);
window.clear();
window.draw(sprite);
window.display();
ss<<getFPS(FPSClock.restart());
window.setTitle(ss.str());
ss.str("");
}
And now to the core. This program supose to be softwere renderer, so NOT USING OPENGL\DIRECTX to render objects. I'm using the SFML only for window. And I have class to draw to file, simple TGA
void RenderTarget::drawToFile(std::string m_filename)
{
//Error checking
if (m_size.x <= 0 || m_size.y <= 0)
{
std::cout << "Image size is not set properly\n";
return;
}
std::ofstream o(m_filename.c_str(), std::ios::out | std::ios::binary);
//Write the header
o.put(0);
o.put(0);
o.put(2); /* uncompressed RGB */
o.put(0);
o.put(0);
o.put(0);
o.put(0);
o.put(0);
o.put(0);
o.put(0); /* X origin */
o.put(0);
o.put(0); /* y origin */
o.put((m_size.x & 0x00FF));
o.put((m_size.x & 0xFF00) / 256);
o.put((m_size.y & 0x00FF));
o.put((m_size.y & 0xFF00) / 256);
o.put(32); /* 24 bit bitmap */
o.put(0);
//Write the pixel data
for (d_type::Bint i=0; i<getSizePixels() ; i++)
{
o.put(m_pixels[i].b);
o.put(m_pixels[i].g);
o.put(m_pixels[i].r);
o.put(m_pixels[i].a);
}
//close the file
o.close();
}
And this is the resault. The triangle is in position:
Vector3Bf(0,0,0),Vector3Bf(0.5f,0.5f,0),Vector3Bf(0.5f,0,0)
But the file and the Texture/Sprite are different.
And my question is simple.. WHY?....
https://imgur.com/a/lb8L5