Page 1 of 1

Drawing Images

Posted: 17 Jun 2011, 04:46
by Von66341
Hello!

I understand that lua can open and write to a .txt file
With a code something like this:

Code: Select all

local file = assert (io.open("path","w"))
file:write(v) 
print(v) 
file:close() 
I was wondering if it is possible for lua to open an image and make drawing changes to it? If yes, how should I go above doing it?

Thanks.

Re: Drawing Images

Posted: 17 Jun 2011, 05:37
by knorke
i am having a deju vu!
what kind of image?
either open/write the file in binary mode (for .bmp) or use a text based image format like .svg.

Re: Drawing Images

Posted: 17 Jun 2011, 05:40
by Von66341
for format like .jpg or .gif or anyother format

U were saying .bmp, but the writing of files won't be in openGL coding correct?

Or is there a way to open any formation of image file, make new drawning (openGL or other methods) and then save the image file?

Re: Drawing Images

Posted: 17 Jun 2011, 06:01
by knorke
It does not seem like Lua or Spring have build in functions to write images so you have to make something yourself.
The writing of files would work like writing text just instead of letters you write bytes. to do so, you have to open the file in binary mode.
The "w" in io.open() is the mode, for binary write probally "wb"

The .bmp format is probally less complex then the .jpg format because there is no compression.
Wiki has details on how a data is stored in a bitmap file: http://en.wikipedia.org/wiki/BMP_file_format

Google also has many results on "bitmap loader tutorial", must stuff for other languages but the principle is the - oh wait, just found this:

http://springrts.com/wiki/Lua_OpenGL_Api#PixelReadback
gl.SaveImage
gl.ReadPixels

Re: Drawing Images

Posted: 17 Jun 2011, 10:08
by TheFatController
http://springrts.com/phpbb/viewtopic.php?f=23&t=14117 (if you can find the widget) has some image writing functions

Re: Drawing Images

Posted: 17 Jun 2011, 16:42
by knorke

Re: Drawing Images

Posted: 20 Jun 2011, 03:27
by Von66341
Hey! I downloaded the widget and tried. It doesn't output any images/heightmap. Anyone know if it is a working copy?

Re: Drawing Images

Posted: 29 Jun 2011, 19:23
by zwzsg
I tried it many moons ago, and couldn't get it to work. Dunno if the problem came from me or from the code, or if I used a wrong version, or what.