Combining Cocos2d and GLKView to render the same data - ios

I use cocos2d engine to render some animation to CCGLView which is placed on app main window next to regular UIViews. My application uses external screen and I would like to render on that screen exactly the same content as in CCGLView but without any other views. And I need to perform this operation in an efficient manner so taking screenshots of CCGLView is not an option.
As I understand there is no such option using cocos2d as It supports presenting only one scene at time (CCDirector updates only one CCGLView at time).
So my question is:
Is it possible to achieve this goal using GLKView? I have access to frame buffer object from CCGLView and I can read pixels from the buffer. I think that the best option would be to use cocos2d runloop and perform this operation next to regular cocos2d rendering. Unfortunately I don't know too much about openGLES and I don't know how I can achieve this. cocos2d uses openGLES 2.0.
Edit:
For now the only suggestion came from #s1ddok (thanks) and the idea is to use CCRenderTexture to draw into CCGLView placed on main window and use CCRenderTexture's data to render to the external window. But I still don't understand how I can render the texture for the second time - this time to another view. Using another CCGLView would require configuring this view as a target for CCDirector, how can I do that? Moreover second CCGLView will share EAGLContext with the first one... So how to force cocos2d to render to the second CCGLView? Any help is appreciated!

I guess the best way you can go is CCRenderTexture. Render the whole scene onto it and then display the data on external screen.
It is a common practice for multiple purposes, for example, if you need to apply shader to a whole scene or something.
This actually will allow you to render scene only once every frame, and then use the same data for UIKit and external screen.

Related

Who calls Present() (if anyone) when using Steam's OpenVR?

I'm new with both directx and openvr, and trying to wrap my head around how the OpenVR compositor API works. The docs call for rendering each eye and handing each one to the compositor via Submit(). But I'm a bit confused about how Present() factors in to this flow. I expected to need to call Present() to render each eye, but from examining some existing VR games, this doesn't happen. Present is called to render any view on the main (non-VR) monitor, but is not called at all for the stuff drawn by the compositor.
Does somebody else call Present() or something lower-level?
Present is to display in a traditional swap chain in a window on your screen. Because with VR, you use an alternative mechanisum and API to present the image to the HMD, you do not need a Present at all.
You only need one if you want to display a copy or anything else on the monitor along side the hmd.

Is there a way to overlay frames in SpriteKit?

As the title states, is there a way to stop the canvas / SKScene from clearing the contents of the current frame, and just draw over the current frame? Now the contents of the scene/frame are cleared every update cycle, i would like to just draw over the previous frame.
I have worked with OpenFrameworks and other visual programming frameworks, and the way it worked there was; you draw stuff on the update call, on the next update call you set a background again to 'clear' the previous frame.
I have looked through the whole documentation of SpriteKit and couldn't find anything. I also tried to emulate the effect by pushing more nodes onto the scene, having them follow one step behind the 'new' nodes. This was, as i expected, way to heavy on CPU / RAM.
No code, i know, i'm sorry, but the stuff i use is pretty basic. Any one of you have any thoughts on this?
Hope to hear from you, thanks.
You should be able to do this by setting the clearsContextBeforeDrawing property on your SKView to NO.
clearsContextBeforeDrawing is a property of UIView, which SKView is a subclass of.
I wouldn't consider this to technically be Sprite Kit providing the behavior, but I believe it's what you're looking for.
Note: I didn't actually test this, so it's possibly that this won't actually work. It would theoretically work perfectly for UIKit.

Is it posible to insert a UITextView (or other UIKit view) into an augmented reality SCNScene?

Weird crazy question I know. My current setup is a SCNScene with a camera controlled by the device's gyroscope. I'm able to add and light normal nodes, however I would like to add 2D UIView objects into the scene like UITextViews or maybe some buttons. The views would need to be inside the scene and thus become no longer visible if the camera moves away from them.
Firstly, is this even possible? Or would this be way more difficult to implement than rebuilding an editable textview as a node? Could this be achieved by categories or...?
I just talked to the scenekit people here at WWDC. He said that as of now it is completly impossible to do it in a nice, functional way. The only options he offered as a possible solution is to create the UIView element somewhere off screen or behind the scene and continuously take screenshots of the object and apply those images as a texture to a SCNNode. He also pointed out the performance will be very poor with this because taking screenshots is heavy and you can't get going very quick with it. So I guess this is a no-go until UIView adds support because, according to the engineer, it's impossible to implement this because of a UIView limitation and not a SceneKit one.

Animating a "character" within iOS app that's not SpriteKit

I am in talks with a client to do an app, but in it, they are wanting it to revolve around a little character that follows you throughout the app (think Clippy, from the old days of Microsoft Word :)).
One thought I had was, can I use an SKSprite/Node inside an iOS app not using the SpriteKit framework?
Or is this a matter of animating through an array of UIImages?
Those were my first thoughts - does anyone know the best direction to go in for something like this? I need basic animations for a character throughout the whole app.
Depending on the detail of animation needed, you could do it with just CoreAnimation and possibly selectively choosing the image to display in an UIImageView. For example, see the answers to this question: rotate a UIView around its center but several times
Simple answer is, No, out of the box you can't use a class from a framework and choose to not use the framework. Though I'm not exactly sure what that question means. An SKSpriteNode renders via an SKScene node, and an SKScene node renders via an SKView, which is rendered by a View Controller.
You could do something fancy like dedicate the SKView as only part of the screen, and have a standard UIKit view as the other part, or only have the SKView appear on the screen when you needed it I guess.

iOS app: OpenGL Views within Storyboard-based Application

I have been working on an iOS, OpenGL-based app for the past few months. During this time, I have created both the main UIWindow and a single UIView in code, as opposed to using a storyboard. An important item to note is that I create an instance of EAGLView (used in many Apple examples), which inherits from UIView.
The code base I am working with is quite extensive, and among other things, it uses a separate rendering thread. I'll come back to this point near the end of this post.
With this in mind, I am now at the point that I want to add native UI support. To do this, I am using a storyboard (for the first time). My current setup consists of a main/root view with two buttons. Each button uses a modal segue to place a new view on the screen.
To reuse as much code as possible, I have specified that the views I segue to are of type EAGLView (as opposed to UIView). The only change I've had to make is that instead of initializing with "initWithFrame", I now initialize with "initWithCoder".
Other than moving to a storyboard, nothing else in the code base has changed. However, when I segue to an EAGLView, nothing renders -- all I see is white. I am hesitant to use GLKit because it duplicates much of the functionality I have already written (I had everything rendering just fine prior to using a storyboard). In addition, GLKit provides a callback for rendering, whereas, I have a separate render thread.
My scenario sounds a lot like this post:
OpenGL iOS view does not paint
I have GL error checks for every call (or for every group of calls), and no errors are being reported. What's even stranger is that when I capture an OpenGL ES frame for debugging (in Xcode), the debugger actually shows the content I expect to see.
Any ideas here? I am stumped.
Please try the following:
Verify that you stop rendering in the view that you're segueing from (stopping times etc.) - this view is still alive since you only pushed a new EAGLView on top of it.
Use XCode's OpenGL ES Frame capture to debug your OpenGL state in the new view. Verify that you're not missing binding to textures or other objects.
If the above doesn't work - write the simplest rendering possible (simple quad, for example) and debug that code.

Resources