Page 1 of 2

Image File to gfx.PutPixel Statements Tool

Posted: August 20th, 2016, 1:24 pm
by Tristan
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. :'(

Re: Image File to gfx.PutPixel Statements Tool

Posted: August 20th, 2016, 2:29 pm
by chili
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 :)

Re: Image File to gfx.PutPixel Statements Tool

Posted: August 20th, 2016, 2:31 pm
by Tristan
Haha no worries. Maybe I got a little better at programming by making this ;)

Re: Image File to gfx.PutPixel Statements Tool

Posted: August 20th, 2016, 8:36 pm
by trybane@gmail.com
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

Re: Image File to gfx.PutPixel Statements Tool

Posted: August 21st, 2016, 1:27 am
by Tristan
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. :)

Re: Image File to gfx.PutPixel Statements Tool

Posted: August 21st, 2016, 1:30 am
by trybane@gmail.com
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.

Re: Image File to gfx.PutPixel Statements Tool

Posted: August 21st, 2016, 10:32 am
by Mr Superbad
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

Re: Image File to gfx.PutPixel Statements Tool

Posted: August 21st, 2016, 10:40 am
by trybane@gmail.com
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.

Re: Image File to gfx.PutPixel Statements Tool

Posted: August 21st, 2016, 11:28 am
by chili
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.

Re: Image File to gfx.PutPixel Statements Tool

Posted: August 21st, 2016, 11:34 am
by Tristan
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.