Drawing Images

Drawing Images

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
Von66341
Posts: 111
Joined: 10 Feb 2011, 03:00

Drawing Images

Post 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.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Drawing Images

Post 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.
Von66341
Posts: 111
Joined: 10 Feb 2011, 03:00

Re: Drawing Images

Post 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?
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Drawing Images

Post 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
User avatar
TheFatController
Balanced Annihilation Developer
Posts: 1177
Joined: 10 Dec 2006, 18:46

Re: Drawing Images

Post by TheFatController »

http://springrts.com/phpbb/viewtopic.php?f=23&t=14117 (if you can find the widget) has some image writing functions
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Drawing Images

Post by knorke »

Von66341
Posts: 111
Joined: 10 Feb 2011, 03:00

Re: Drawing Images

Post by Von66341 »

Hey! I downloaded the widget and tried. It doesn't output any images/heightmap. Anyone know if it is a working copy?
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: Drawing Images

Post 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.
Post Reply

Return to “Lua Scripts”