Post subject: Text on Transparent Background using Lua?
Joined: 4/6/2013
Posts: 7
Not entirely sure how to do this, but is there a way to display text without any background? I was trying various functions with the lua-gd, but so far I have not had any luck. Ideally I would like to do it through lua-gd since I want the ability to specify a sexy font. Has anyone done this? Thanks. ------------ UPDATE Believe I figured out how transparency and drawing with gd works a little better. But I still have not figured out how to draw only one object, and have everything else transparent. Next thing I am going to try is a png with transparency already in it just to see if I can even do it, but I do not want to save everything as an image to use that. Any ideas? Here are some funny gi joe pics.
-- fceux gui.opacity sets the transparency on whole image, but colorallocatealpha sets objects in image transaparency

require "gd"
while (true) do


im = assert(gd.createTrueColor(80, 80))
black = im:colorAllocateAlpha(0, 0, 0,126)
white = im:colorAllocateAlpha(255, 255, 255,60)
im:openPolygon( { { 50, 50 }, { 50, 60 }, { 60, 60 }, { 60, 50 } }, white)


gui.gdoverlay(0,
		      0,
			  im:gdStr());
gui.opacity(0.5);

    FCEU.frameadvance();
end;
----------------
--see how the colorAllocateAlpha sets the transparency of images in image relative to each other?
--order of drawing is important as well.
require "gd"
while (true) do

im = assert(gd.createTrueColor(200, 100))
green = im:colorAllocateAlpha(0, 200, 0,0)
red = im:colorAllocateAlpha(200,0, 0,50)
white = im:colorAllocateAlpha(255, 255, 255,40)
blue= im:colorAllocateAlpha(0, 0, 200,10)

 gd.useFontConfig(true)
 im:stringFT(blue, "Arial", 20, 0, 10, 30, "Standard Arial")

im:filledRectangle(0, 0, 100, 50, green )
im:filledRectangle(25, 25, 125, 75, red )
im:filledRectangle(35, 35, 150, 150, white )

gui.gdoverlay(0,
		      0,
			  im:gdStr());
--~ gui.opacity(0.5);

    FCEU.frameadvance();

end;
------------- UPDATE - Got Solution - 5/31 This is what happens when you do not read the documentation carefully enough, and just assume things.
gd.createTrueColor(x, y) Used to create truecolor images, with an essentially unlimited number of colors. Invoke gd.createTrueColor with the x and y dimensions of the desired image to return the new image or nil on error. Truecolor images are always filled with black at creation time. There is no concept of a "background" color index.
require "gd"

	while (true) do
		 im = gd.create(200, 50);--works with transparency
		 white = im:colorAllocateAlpha(255, 255, 255,127);--background
		 black = im:colorAllocate(0, 0, 0, 20);
		 im:string(gd.FONT_GIANT, 1, 1, "transparent background", black);
		 gui.gdoverlay(0,
					   50,
					   im:gdStr());

		 im = assert(gd.createTrueColor(50, 50)) --does not seem to allow transparency...
		 white = im:colorAllocateAlpha(255, 255, 255,127);--background
		 black = im:colorAllocate(0, 0, 0, 20);
		 im:string(gd.FONT_LARGE, 1, 1, "no transparency", black);

		 gui.gdoverlay(0,
					   0,
					   im:gdStr());

		 FCEU.frameadvance()
	end

Post subject: Re: Text on Transparent Background using Lua?
Emulator Coder, Skilled player (1113)
Joined: 5/1/2010
Posts: 1217
MetalStorm wrote:
Not entirely sure how to do this, but is there a way to display text without any background?
You mean with the game showing underneath? As for doing that with lua-gd, does specifying the background color using image:colorAllocateAlpha() to be fully transparent work?
Joined: 4/6/2013
Posts: 7
Tried that, posted update in first post.
Post subject: Re: Text on Transparent Background using Lua?
Joined: 4/6/2013
Posts: 7
Ilari wrote:
MetalStorm wrote:
Not entirely sure how to do this, but is there a way to display text without any background?
You mean with the game showing underneath? As for doing that with lua-gd, does specifying the background color using image:colorAllocateAlpha() to be fully transparent work?
Looks you you were right, I was just calling the wrong image creation method...