Image File to gfx.PutPixel Statements Tool

The Partridge Family were neither partridges nor a family. Discuss.
User avatar
Tristan
Posts: 14
Joined: July 7th, 2013, 3:38 am

Image File to gfx.PutPixel Statements Tool

Post by Tristan » August 20th, 2016, 1:24 pm

Are you following Chili's Beginner C++ Game Programming Reboot?
Are you interested in drawing sprites from image files using lots and lots gfx.PutPixel functions?
Are you not bothered to painstakingly write out hundreds of these statements with autistic pixel precision to incorporate fancy sprites in you game?

If you answered 'Yes' to any of these questions, look no further!
I wrote a Python application with a user-friendly GUI that allows you to navigate to your image of choice and convert the pixel information into what I've coined as "ChiliCode". From there, you can copy and paste the code directly into your solution.

You will find attached the .zip file containing this program. Note that transparency is supported through the rgb colour (255, 0, 255). So any background you don't want the game to draw should be that colour.

If it doesn't work, or you experience bugs, please leave a reply and I'll try to fix it. :) If anyone's interested in the source, let me know and I'll include that as soon as I clean it up.

Cheers, Salty Tristan.
PS, the .exe is named image2chilicode.exe and you will find a test image to try out the program in the same directory as the .exe called test_image_with_transparency.png.
:)

EDIT: FUCK I just realised this has been done before by LuX. Well I'm just gonna go cry now. :'(
Attachments
Image2ChiliCode.zip
(4.69 MiB) Downloaded 1723 times

User avatar
chili
Site Admin
Posts: 3946
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Image File to gfx.PutPixel Statements Tool

Post by chili » August 20th, 2016, 2:29 pm

Haha, yeah LuX made one in Visual Basic way back in the day. I also posted my no-frills fukbmp tool on here somewhere. Still, thanks for putting this up man :)
Chili

User avatar
Tristan
Posts: 14
Joined: July 7th, 2013, 3:38 am

Re: Image File to gfx.PutPixel Statements Tool

Post by Tristan » August 20th, 2016, 2:31 pm

Haha no worries. Maybe I got a little better at programming by making this ;)

trybane@gmail.com
Posts: 109
Joined: August 11th, 2016, 11:17 am

Re: Image File to gfx.PutPixel Statements Tool

Post by trybane@gmail.com » August 20th, 2016, 8:36 pm

Yeah, I grabbed lux's before but it didn't work for me... then I grabbed the fukbmp and it worked. But always willing to give new ones I try :P

User avatar
Tristan
Posts: 14
Joined: July 7th, 2013, 3:38 am

Re: Image File to gfx.PutPixel Statements Tool

Post by Tristan » August 21st, 2016, 1:27 am

I haven't tried Chili's fukbmp, but I'm always looking to be as lazy as possible. I've used LuX's tool and had some issues with it, but with my program, I feel like it is the easiest to use because of its speed and copy to clipboard function.
Not that I'm trying to reinvent the wheel here, but no harm in giving people variety. :)

trybane@gmail.com
Posts: 109
Joined: August 11th, 2016, 11:17 am

Re: Image File to gfx.PutPixel Statements Tool

Post by trybane@gmail.com » August 21st, 2016, 1:30 am

Welp, chili doesn't provide instructions on how to use fukbmp. Really all you need to do is peek at the code he used, and change the load file string he used or change the name of your file to match it.

Mr Superbad
Posts: 9
Joined: March 26th, 2013, 11:29 am

Re: Image File to gfx.PutPixel Statements Tool

Post by Mr Superbad » August 21st, 2016, 10:32 am

Thanks dawg. I was starting to think about that...was trying to think what you would do to create game backgrounds e.g. city skyline, chess board, etc.. is this answer? I guess what I mean is are all graphics derived from putpixel function or could you include some kind of picture file into your code and i would display it without putpixel....? A bit like the cartoons - background doesnt change and the characters are placed on top of the scene....listen to Walt Disney here..:-D

trybane@gmail.com
Posts: 109
Joined: August 11th, 2016, 11:17 am

Re: Image File to gfx.PutPixel Statements Tool

Post by trybane@gmail.com » August 21st, 2016, 10:40 am

Oh you can, but he won't go over how for a while. He did somewhere around lesson 20 in the old beginner series. He might get to it sooner this time round. That being said, don't skip ahead! Everything he teaches is derived from what you've already learned so take it one step at a time.

User avatar
chili
Site Admin
Posts: 3946
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Image File to gfx.PutPixel Statements Tool

Post by chili » August 21st, 2016, 11:28 am

Mr Superbad wrote:Thanks dawg. I was starting to think about that...was trying to think what you would do to create game backgrounds e.g. city skyline, chess board, etc.. is this answer? I guess what I mean is are all graphics derived from putpixel function or could you include some kind of picture file into your code and i would display it without putpixel....? A bit like the cartoons - background doesnt change and the characters are placed on top of the scene....listen to Walt Disney here..:-D
Yup, in general what you do is load an image into memory and then copy it to the screen buffer for sprites, backgrounds, etc. Compiled sprites (functions with an ass ton of putpixel calls) were a real technique used in the past, but not these days. I just use them in the beginning because they are simple.
Chili

User avatar
Tristan
Posts: 14
Joined: July 7th, 2013, 3:38 am

Re: Image File to gfx.PutPixel Statements Tool

Post by Tristan » August 21st, 2016, 11:34 am

Agreed. While you can get away with drawing a stuff with a craptonne of PutPixel calls with a tool like this, I would in no way recommend going through the effort to actually make a game like that.

Wait until we learn how to do it the proper way, this tool is aimed for the impatient and people who would like small custom sprites for the first few tutorials.

Post Reply