Render to bitmap using arsd nanovega - image

I want to render some graphics, texts and shapes to a bitmap using a canvas-like API like nanovega in D on my server.
I know how to create an arsd window with OpenGL context and render to it, (as per documentation) but is it also possible rendering to a headless context or even directly to draw to some memory buffer? (Because I don't think my server has OpenGL available and would probably need to use some software renderer)
Mainly I wanted to use gradients, texts, shapes, rounded corners, images and masks and render all of that to an image. I know that nanovega implements all of the rendering parts of that, so I would like to keep using it.

Related

The best approach to use only ThreeJS for building interactive UI without HTML DOM overlays

May I have a 2D layer for UI, Text, Buttons, etc over the 3D scene in ThreeJS?
Ideally something like engine from PixiJS inside ThreeJS? I've seen PixiJS offers some 3D features so why not combine both libraries in something super-powerful? I just do not want to place any HTML Dom elements over WebGL canvas as this will probably slow down performance on Mobile devices.
One way to solve this issue is to implement the UI as screen space sprites like demonstrated in the following official example (check out how the red sprites are rendered):
https://threejs.org/examples/webgl_sprites
The idea is to render them with a separate orthographic camera and an additional call of WebGLRenderer.render(). Besides, instances of THREE.Sprite do support raycasting which is of course useful when implementing interaction.
Building up on Mugen87's answer, you can also use THREE.Shape to make visual containers adapted to the user screen size :
https://threejs.org/docs/#api/en/extras/core/Shape
You can use THREE.Shape to make mesh-based text, is illustrated in this example :
https://threejs.org/examples/?q=text#webgl_geometry_text_shapes
You should also have a look at three-mesh-ui, an add-on for building mesh-based user interface with three.js :
https://github.com/felixmariotto/three-mesh-ui

Direct2D: smooth image movement?

Im using direct2d to draw a bitmap to the window, and thats working fine, but when I move the image (continually, with joystick, key input, or just by itself), it doesn't move smoothly. It look's like the image pixels are not spread to surrounded pixels, It looks like the most dominant colors remain, and the others are discarded. I create the bitmap using WIC (windows imaging component).
I didn't want to post code cause it's just the most basic stuff, window creation, direct2d initialization, bitmap creation and drawing, all taken from msdn, most of it is just copy-paste. If you think you need any code to help me, ask, then I'll post it.
What I want:
Smooth image movement on picture.
What I've tried:
-void SetAntialiasMode(D2D1_ANTIALIAS_MODE antialiasMode); (tried all options)
-setting D2D1_BITMAP_INTERPOLATION_MODE in draw bitmap method to different modes.
Thanks in advance!

Text/object manipulation using 3js or other platforms

I was wondering if there’s any way to use 3js or a similar javascript-based framework to create a 3D object in virtual space (within the browser window) and have text interact with it — ideally projected onto it, or possibly just hidden or distorted by it in some way.
I’m thinking a virtual version of this type of work by Jenny Holzer, where she projects text onto buildings. The text becomes distorted by the contour of the building and disappears around its contours.
this is the image I'm referenceing

Xcode GLKit printing Text on GLKView without using UIImages

I have an app, its a small game using opengles with GLKit.
No im wondering how it works when i want to draw text on
my screen (if it is possible).
How can i do it?
i draw all of my game objects using images (wrapped in some kind
of sprite). its possible to scale, to move, and to rotate.
everything works fine.
but finding out how it works to print text on that glkview
gets me deep inside of problems ^^
I dont want to use uiimages cause i also dont know how
to present uiimages on a glkview.
There are a number of ways to do what you want:
1) Have an image with all the text glyphs you need in it. For example, if your application is in English, you'd have the 26 uppercase and 26 lowercase letters in the image. Upload that texture to the GPU and use the proper texture coordinates or glSubTexImage2d() to pull out the glyphs you need. (It's not clear to me if this is what you meant by not wanting a UIImage. It doesn't have to be a UIImage, though that's probably easiest.)
2) Every time you need to display text, draw it on the CPU on the fly, and upload the entire word, phrase, or sentence as a texture. You could create a CGBitmapContext and use Core Graphics to draw text to it. Then upload it using glTexImage2D().
3) Get the individual glyphs out of the fonts and draw directly using the bezier curves that make up the glyphs. This allows for 3D extrusion, too. However, this option is the most time consuming to code and probably least performant. It also involves dealing with the many small problems that fonts have (like degenerate segments, and incorrect winding orders). IF you want to go down this path, I think maybe Core Text can help.
There are at least two clean ways to do this, depending on your requirements.
While documentation advises against compositing over a CAEAGLLayer (GLKView), it works quite well, at least in recent iOS versions, when transparent content is layered on top of the CAEAGLLayer. For example, try dropping a UITextView, with opaque set to false and a clear background color, on top of a GLKView in your Storyboard in Interface Builder in the Apple GLKit template or your app. In my test on an iPhone 5, frame rendering time remained around 1ms, even while scrolling in the text view. If your text needs are static, or you don't want the user to interact with the text, use CATextLayer as a child layer of your EAGLLayer instead of a view.
The second approach is to render the text into a texture. You can then composite the text onto your view by disabling the depth buffer and rendering the texture on a full screen rectangle. Look at UIGraphicsBeginImageContextWithOptions to see how to render to an offscreen image with Quartz. UIGraphicsGetImageFromCurrentImageContext allows you to retrieve the UIImage to use as a texture.

Placing objects on scrolling background in XNA

How do I place objects that appear only if the background scrolls to a certain point?
Example- I have this long image that keeps scrolling using the technique above. However, after scrolling to part of the image, I want to add a platform there. How would I do that?
In general, you will probably need to save the locations of your objects in a file and then load that file at the beginning of the level (assuming you are making some kind of platformer game). You can do this by creating a class or a struct containing all the relevant information for the platform (position, size, texture, etc) and then using XML serialization to write an array of those classes/structs to a file.
Your level loader would then load and deserialize the level data, which would end up being a list of all the objects in your level (such as platforms). Now that you have the locations of your platforms in memory you have a couple different options on how to get them to the screen.
Draw all the objects (platforms) all the time, whether or not they are in the view of the camera. If your levels don't contain a lot of objects, this would be simple to implement.
Draw only those in the camera's view. Without knowing how you implemented the horizontal scroller, it's kind of hard to make suggestions for this part. Whatever mechanism you currently have to identify the boundaries of what part of the background to show could be used to determine which objects to draw as well.
I'm working on a game that scrolls vertically right now, and I needed a way to do something similar: place objects in a level and have them appear when the background scrolled to them. I used TorqueX 2D (free engine binaries if you've payed to develop for XNA) and its 2D scene editor to set this up pretty easily. I have my camera scrolling up, the background stays in place. When it gets to an object position defined in the XML level file it spawns the object in the level.

Resources