Lua graphics display on an existing window - lua

I want to display graphics on top of an existing window, is that possible using pure Lua? because i cannot find the stuff i need, i only found how to display graphics in an specific OpenGL window.
I've looked to some code posted on github
https://github.com/ittner/lua-gd/tree/master
https://github.com/stetre/moongl
https://github.com/vrld/G4L
that's all i've found

There is no way to do it in pure Lua, as it doesn't provide any platform-specific drawing/GUI methods. It's possible to use some library (like those you've listed), but I'm not familiar with them. You can probably use wxlua, which is a wrapper around wxwidgets and provides SetTransparent method on its wxFrame object and ways to draw on a surface with transparent background or transparent brush (you can set the degree of transparency). You still need to find the position of the window you are interested in (to cover it with your window) and this is going to be system-dependent. For example, on Windows you can do this by using winapi window functions.

Related

how to manipulate graphics created with Adobe Animate CC?

So I have created some fancy graphics with Adobe Animate (HTML CANVAS)and added some animation as well. Is there a way to manipulate (or simply get) the Javascript code that generated these graphics? Say I want to use these same graphics in another project. How to extract that code? The generated code is not just simple CreateJS code. It is very tight to the Animate framework.
The code is in fact just plain CreateJS (EaselJS) code. In your generated lib file, you can see all the Graphic instructions for each Shape. For Animate, it uses a "compressed" format by default (which you can actually see in the docs). Since 95% of developers don't care what the exported graphics look like, so it uses a custom compression format to reduce the amount of code that is generated, which results in a much smaller filesize.
You can easily pop into the publish settings, and under "Advanced" turn off the "Compact Shapes" option, which will give you typical lineTo().moveTo().drawRect() commands again.
Hope that helps!

How to render simple 2d text in openGL with delphi?

I am trying to find a way to display a simple text on an openGL form in Delphi.
I tried this with Labels, but they were not showing up. I'm guessing that the openGL window was rendered on top of it, so I tried to call Label1.BringToFront; but this didn't work.
I also heard of a library called freetype, but I couldn't find info, how to implement it in Delphi.
What is the simplest way to render out text on an openGL form in Delphi?
The simplest way is to use opengl's wglfontbitmaps
const numberchar =128
allocate:
wglMakeCurrent(FDC, FRC);
FFontBase := glGenLists(numberchar);
SelectObject(FDC, FFont.Handle);
wglUseFontBitmaps(FDC,0,128, FFontBase);
draw(atext:ansistring);
glPushAttrib(GL_LIST_BIT);
glListBase(FFontbase);
glCallLists(Length(aText), GL_UNSIGNED_BYTE, Pansichar(aText)); list
glPopAttrib;
free:
glDeleteLists(FFontBase, numberchar);
The draw code is only partial. Best to look for tutorials for similar code.
Note this will only give you basic unscaled font. For fancy text effects, indeed, freetype is the most common route.
A good place to start with Delphi and opengl is http://www.delphigl.com/ Mostly German, but some English boards too.
An alternative (provided that you have D2010+) is to look in the direction of DirectX. D2010+ comes with a directx context component.

Converting a Canvas prototype to iOS native

I have developed a Canvas prototype of a game (kind of), and even though I have it running at a decent 30 FPS in a desktop browser, the performance on iOS devices is not what I hoped (lots of unavoidable pixel-level manipulation in nested x/y loops, already optimized as far as possible).
So, I'll have to convert it to a mostly native ObjC app.
I have no knowledge of ObjC or Cocoa Touch, but a solid generic C background. Now, I guess I have two options -- can anyone recommend one of them and whether they are at all possible?
1) Put the prototype into a UIWebView, and JUST do the pixel buffer filling loops in C. Can I get a pointer to a Canvas pixel array living in a web view "into C", and would I be allowed to write to it?
2) Make it all native. The caveat here is that I use quite a few 2D drawing functions too (bezierCurveTo etc.), and I wouldn't want to recode those, or find drawing libraries. So, is there a Canvas-compatible drawing API available in iOS that can work outside a web view?
Put the prototype into a UIWebView, and JUST do the pixel buffer filling loops in C
Nah. Then just embed a web view into your app and continue coding in JavaScript. It's already JITted so you don't really have to worry about performance.
Can I get a pointer to a Canvas pixel array living in a web view "into C"
No, not directly. If you are a hardcore assembly hacker and reverse engineer, then you may be able to do it by looking at the memory layout and call stack of a UIWebView drawing to a canvas, but it's just nonsense.
and would I be allowed to write to it?
Once you program your way down to that, I'm sure you would.
Make it all native.
If you wish so...
The caveat here is that I use quite a few 2D drawing functions too (bezierCurveTo etc.), and I wouldn't want to recode those, or find drawing libraries.
You wouldn't have to do either of those, instead you could just read the documentation of the uber awsum graphix libz called CoreGraphics. It comes by default with iOS (as well as OS X, for the record).
So, is there a Canvas-compatible drawing API available in iOS that can work outside a web view?
No, I don't know of one.
Translating your objective c code to html5 sounds like a daunting task, How about a 3rd option where you don't have to change your JavaScript code ?
http://impactjs.com/ejecta
Ejecta is like a Browser without the Browser. It's specially crafted
for Games and Animations. It has no DIVs, no Tables, no Forms – only
Canvas and Audio elements. This focus makes it fast.
Yes, it's open source
https://github.com/phoboslab/Ejecta

How I can detect the background of an image programmatically?

I need to develop a software that selects a face from a photo where the background is a plain color (green, like in the movies).
Then we want to compose that selection with another background image, this part is easy with many libraries. But I don't know how can I do the selection? Can you give some links or libraries to investigate? I can do this project with any language of my choose, so examples or links in any language are welcome.
Ok, what you are trying to do is called chroma key. Like you say, it used a lot in the movies with a blue/green screen. On windows its actually pretty easy to do because its built into windows as part of GDI+ (or on C#, I think its just called the Graphics class).
I dont have any sample code handy, but the process is pretty straight forward:
With GDI+, you create a bitmap object of your foreground image (the one with the green background). Then create an ImageAttributes object. Use ImageAttribute's object's SetColorKey() method to specify a color or range of colors to use as the background color. Lastly, draw that bitmap object over the target bitmap, and GDI+ will draw it as if the background color is transparent.
There's more to it in that in code, but concept-wise thats all there is to it.
This is probably an area where it is easier to work in some other space than RGB - such as HSV.
I would also look at the OpenCV library.

Where can I find an image watermark control for Delphi?

Is there a good image watermark control for Delphi? It would be nice if it could receive both text and images to insert in a base photo.
I would also prefer it was free.
I couldn't find any pre-packaged controls. But watermarking is not very hard at all. All you simply need to do is draw an image on top of another image with the use of alpha blending. This site has a whole section on alpha blending in Delphi. They provide links to graphics libraries which have implemented it.
However if you're using Delphi.NET, and can access the relevant classes in the framework, there is an easier way using only framework methods.
Take a look at Graphics32 together with GraphicEX.
Or see if PascalMagick does the trick.

Resources