colt n00b
Joined: 17 Apr 2018 Posts: 17
|
Posted: Wed Jul 10, 2024 3:00 pm Post subject: Simple tga writer not working |
|
|
Hi. I did write code to write a simple tga file format file.
Unfortunately, it does not seem to work as expected. The resulting image is always black, not matter the color values I write on the file. Here is the code:
Code: | #include <fstream>
using namespace std;
main () {
int a = 1024;
int b = 768;
int c = 24;
ofstream ofs ("x.tga", ios::binary);
ofs.put (0), ofs.put (0), ofs.put (2), ofs.put (0), ofs.put (0), ofs.put (0);
ofs.put (0), ofs.put (0), ofs.put (0), ofs.put (0), ofs.put (0), ofs.put (0);
ofs.put (a), ofs.put (a >> 8), ofs.put (b), ofs.put (b >> 8);
ofs.put (c), ofs.put (0);
for (int i=0; i<a; i++)
for (int j=0; j<b; j++)
ofs.put (1), ofs.put (0), ofs.put (0);
ofs.close ();
} |
|
|