Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Simple tga writer not working
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
colt
n00b
n00b


Joined: 17 Apr 2018
Posts: 17

PostPosted: Wed Jul 10, 2024 3:00 pm    Post subject: Simple tga writer not working Reply with quote

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 ();   
}
Back to top
View user's profile Send private message
Banana
Moderator
Moderator


Joined: 21 May 2004
Posts: 1555
Location: Germany

PostPosted: Wed Jul 10, 2024 6:44 pm    Post subject: Reply with quote

Can you please provide which language you are using?
_________________
Forum Guidelines

PFL - Portage file list - find which package a file or command belongs to.
My delta-labs.org snippets do expire
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 22170

PostPosted: Wed Jul 10, 2024 7:16 pm    Post subject: Reply with quote

That is C++ code. It doesn't seem to be using anything recent, so any supported C++ dialect can probably parse it.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum