GLBasic forum

Codesnippets => Code Snippets => Topic started by: Synthetic on 2009-Sep-24

Title: PNG screenshots
Post by: Synthetic on 2009-Sep-24
This creates screenshots in the PNG format. There would be more to say but that's all it does.

=======================
Notes
=======================
When this example starts, it allows you to take only one screen shot with the "=" key. You will find the
screenshot inside the same folder as this example binary named screenshot.png.

Please note there is NO error handling. If something screws up, especially with libpng, you will get
a program crash.

When calling the screenshot_png function, it will automatically determine your screen size. You only
have to supply a file name or a folder/directory along with file name you want to save the screenshot
as.

All required headers are included and should be placed in the same folder where your source is located.
They are:
_mingw.h | stdarg.h | stddef.h | stdint.h | stdio.h | stdlib.h | and the sys folder with types.h

=======================
Usage
=======================
screenshot_png("something/screenshot.png")

=======================
Arguments
=======================
file$ - The name and path/name for the PNG image you would like to create.

=======================
Other
=======================
Feel free to use, chop up or mangle this code for your own usage. It is supplied AS-IS and should be
used at your own risk!

I will probably add more to this such as PNG text info customizing etc and I'm always open to ideas.

[attachment deleted by admin]
Title: Re: PNG screenshots
Post by: D2O on 2009-Sep-25
Hmm, ohne Deine Arbeit zu schm?lern, aber das kann doch das 'SAVEBMP "myfolder/myscreen.png"' doch auch.

Oder habe ich das Falsch verstanden?
Title: Re: PNG screenshots
Post by: Synthetic on 2009-Sep-26
As far as I know, it and savesprite only saves BMP files which is why I made it but maybe there was an update I didn't notice. I needed something smaller for screenshots.
Title: Re: PNG screenshots
Post by: Moru on 2009-Sep-26
Is it possible to save an alpha channel into the PNG with this code?
Title: Re: PNG screenshots
Post by: Synthetic on 2009-Sep-26
Sure is but with some modifications. In the glReadPixels call, you will need to change GL_RGB to GL_RGBA and un-comment out the GL_RGBA define. Also, the PNG_COLOR_TYPE define needs to be changed from 2 to 2 | 4.
Title: Re: PNG screenshots
Post by: Synthetic on 2009-Sep-26
I take that back, don't bother with the OpenGL stuff. My brain is not functioning right this morning. XD  There is a function to set the alpha value, I just don't remember it off hand atm. I'll post back when I find it.
Title: Re: PNG screenshots
Post by: Hemlos on 2009-Sep-27
ALPHAMODE 1  // [-1.000..1.000]
Title: Re: PNG screenshots
Post by: Moru on 2009-Sep-27
Quote from: Hemlos on 2009-Sep-27
ALPHAMODE 1  // [-1.000..1.000]

This is not about displaying PNG's, Hemlos... read the thread please
Title: Re: PNG screenshots
Post by: Hemlos on 2009-Sep-27
Quote from: Moru on 2009-Sep-27
Quote from: Hemlos on 2009-Sep-27
ALPHAMODE 1  // [-1.000..1.000]

This is not about displaying PNG's, Hemlos... read the thread please

Sorry, need to elaborate;
the alphamode previously set, is sent "mixed" to the file.

Title: Re: PNG screenshots
Post by: Kitty Hello on 2009-Sep-28
Quote from: Synthetic on 2009-Sep-26
As far as I know, it and savesprite only saves BMP files which is why I made it but maybe there was an update I didn't notice. I needed something smaller for screenshots.
Savesprite also saves PNG images (with alpha information). You can resize an image with CREATESCREEN and STRETCHSPRITE.