How to use OpenGL without displaying it? - android

For an application i want to render things in background even when the app is not currently displayed. The official docs write to open a GLcontext via a GLSurfaceView. For not displaying graphics and rendering into another target there seems not to be a real solution.
So the Question is how to create a GL-context without GLSurfaceView in Android?
Use case: Record a video and add current time as text directly into video. For that CPU-based image-manipulation is simply to slow to be performed live. At least if the video should be also displayed while recording. OpenGL could render everything simply into a Framebuffer/Renderbuffer.

You don't have to use GLSurfaceView to do OpenGL rendering. If you look at the source code, you can see that it's only using only publicly available APIs. It is merely a convenience class that makes the most common uses of OpenGL under Android (using OpenGL to draw the content of a view) very easy. If your use case is different then you just... don't use it.
The API you use for creating contexts and rendering surfaces more directly is EGL. There are two versions of it available in the Android Java frameworks: EGL10 and EGL14. EGL10 is very old, and I would strongly recommend using EGL14.
The EGL calls are not really documented in the Android SDK documentation, but you can use the man pages on www.khronos.org to see the calls explained.
Using EGL directly, you can create a context and an off-screen rendering surface that will allow you to use OpenGL without any kind of view.
I posted complete code showing how to create a context with an off-screen rendering surface in a previous answer here: GLES10.glGetIntegerv returns 0 in Lollipop only.

Already answered here and here
I think the most simple is what is described in second link when they say :
set it's view size 1pixel&1pixel, put it visible(user cannot see it) and in OnDraw bind FBO to the main texture and render it
So you would still create a GLSurfaceView (just to get a context) but you would make it 1x1 and invisible.
Or you could use a translucent GLSurfaceView as suggested in my comment (I am not sure this will work on any device, this seems to be a bit tricky to setup).

Related

3D Model with use of textures [Android]

I am trying to find approaches on stamping multiple textures on an object (3D .obj) Android. But, I am unable to do so, I have tried min3d but not sure if it is the right way to do it?
Is there anything available around which is similar to this? Or How Should I approach this UI? Below is the UI of model and how I want to stamp an "image"/texture on it, in addition I want to change the color of the model / add text on it.
In addition, I am planning to give touches on it, by stamping username/label/textview at the back of the model by using rotation through touches.
Please guide, which SDK should I use on Android, what is the best approach to do it.
What you want is basically just rendering textures on a given 3D mesh, as far as I can see. You could take multiple approaches for this: The simplest being just texturing the actual object, but a more complicated approach could involve rendering the object and "stamp"&text textures separately, giving the illusion of being overlayed (Not preferable though, as this will be difficult to manage correctly).
For texturing, you can either attempt rendering different textures after each other (First the background, then the stamp, then the text), or combining the different elements into one texture (pre-processing) before rendering.
I recommend having a look at the following posts and articles:
OpenGL ES (which can do everything you want to do, but has a decently steep learning curve)
Switch to a different 3D rendering engine if you find it too difficult to use your current one (Many options, although most are fullblown game engines)
Loading 3D objects and textures for OpenGL ES rendering
Check out the following git snippets and articles on texturing in min3d: this, this article, this article on object loading
You did not provide any code displaying your current attempts, so it is difficult to say what exactly your problem is, and how to solve it. If you edit your question you might receive more concrete solutions besides just links to potentially helpful resources.
Perhaps working with the OpenGL ES 2.0 api might be an option. Take a look this repo here called the Android 3D Model Viewer which makes use of it, it might help you out.

Android ARCore use TextureView in a ViewRenderable

So I have a custom view that uses a TextureView in order to render it's content through OpenGL and JNI, which works as intented.
Now, looking at the ARCore demos (and documentation) it is posible to render Android Views using the
ViewRenderable class. But doing a quick test using my custom view, it appears that it won't work, since it wasn't made thinking in this kind of behavior...
So I have two questions here:
It is possible to use a TextureView as a custom renderable in ARCore?
If not, is there a way to have a delimited area (anchored in a given point) where I can freely make my JNI/OpenGL calls?
If someone could point me out where in the documentation (or demos) can I look out will be highly appreciated

OpenGL ES Startup

I done a 1:1 copy of the iOS App "MohrenJass" to Android.
-> Austria Cardgame.. Good training example :)
Good introduction to Activity, Views, Canvas, Preference, APIs, and more
Now i done the OpenGL ES Sample from the Developer page.
I read about OpenGL but i have a Question about it.
There are realy some points in it who give me some hard times.
Matrix, vertex, shader, fragment, projection, camera,...
Its not that i not understand it, but only to know "do this when that"
is not enough for searching errors in code...
I think about trying the ReplicaIsland code next,
but should i start with OpenGL first?
I found this fro OpenGL -> Prefer it because its german
http://wiki.delphigl.com/index.php/Hauptseite
(Dont know if its possible with my stand of knowledge)
Also found this
http://www.learnopengles.com/android-lesson-one-getting-started/
Or skip this and go into ReplicaIsland?
Learning by doing was always a good way,
but sometimes its a punch in my face...
I wont to try next a simple 2D Application.
A Square to go left/ right, jump above a other Square or somthing.
Only for learning to reach someday my target of realy create a App :)
I also read something about Unity, but i think its not the way i should start that.
Possible if i know what i am doing it will get with it easy...
Well.. I hope you have any tipps for me!
As for libraries such as Unity or Cocos 2D and such you will be able to start with your application quicker but they usually limit your capabilities as a developer at one point or another. If this is for a purpose of creating a simple game then you should go for it. If the goal is to get as much knowledge as possible I suggest you try the openGL. It is not easy and it does not get easier over time but it is worth it. And if you later turn to some library everything will be as clear as day.
So about the tutorials and examples there is a fact that they are in most cases misleading. They will explain to you how something is done but the code structure will be completely unmaintainable. If you want a good code that will help you over time you should begin with creating a simple "debug" scene to which you can then add components you later expect to need. For instance you should create a class that can contain an openGL context which should later be extended to include caches such as textures, shaders... Then you should have a class containing the view you draw to, the frame buffer and the render buffers you use on it. It should contain all the necessary tools to initialize with view, enable depth buffers, stencil buffers, presenting the content... All of these and more can be more or less pasted from examples and tutorials, all you need to do is restructure them. This would be your base construct as you will be able to create all components to draw and present but can not draw with it. To test it all you can do is try to clear the buffer to some value and see if you get the expected result.
After this the fun part begins: Creating the classes to handle and compile shaders, classes to create textures from images, matrix stacks, VBOs... Again all of these can be pasted from web but need restructuring.
So when you have all this necessary tools you can actually start working on the game itself. At this point most people take the wrong turn. Try to create objects that contain all the data you need to present a certain element in your game. For instance you have a character which is defined with a location, speed and an image (texture). This object can then have a draw method and a move method. The draw method will use the location to translate the matrix, will generate or reuse some vertex data, bind the appropriate texture and simply draw itself. The move in this case will only use the speed to change the location. As you go deeper more components are usually added and the situation can get complicated. But imagine only having what I wrote above you can create 3 images: character, enemy, bullet; then create as many objects as you need at any time with this images, move them around as you please, create crash detecting (which is very simple with this data) and you have a simple game which can become very advanced very quickly only by adding a few tricks.

Do I need to use layouts when developing games on Android?

I'm new in Android development and I have been making a tutorial for a game example which tells that using a layout file is not necessary because of the flexibility need on game development. However I've seen on Android docs that using a layout file is always the best way for Android development.
I'm sorry if my doubt looks obvious or kind of weird, but I'm really newbie and I'd really appreciate if you guys give me some help.
Most Android Games will use a Surface, Canvas, or GL Surface view to render all content to the screen. This element is likely to be fullscreen as well.
And so all drawing of UI and buttons and game elements are drawn directy to the surface, bypassing the use of Android's many UI views.
There is no reason you game cannot use android UI views in addition to using a surface for drawing the game action itself.
And of course you will likely use layouts as well when integrating things such as Admob ads or user dialogs within you game. So in practice you will use both.
But a standard utility application built in android will use layouts almost exclusively.
As a final aside, it is not necessary to use layouts. Every view type can be created either through XML layouts and inflating the views, or by instantiating a view in java code. the main reason for using layout files is because they are fast to build easy to use for a large category of interface design. But he choice to use them or not is your own.
A layout is used for arranging views. If you're not using any views (i.e. you do all the drawing yourself), then there's no point in using a layout.
For game development you are better off not using a layout file. The tutorial you are following is right. You will probably want to draw directly to a GL Surface View.
Personally, I forgo a lot of the features of the Android framework when doing game development. I use one Activity to bootstrap the game and get it running, and I draw to one GLSurfaceView. A lot of Android game dev tutorials follow this approach, and so are probably going to be a lot more useful to you than tutorials for more traditional Android apps.

Adding effect to an Android Camera preview

I am looking to get Live camera feed and add effects to it and display it. Which is the right technology to go forward with. Any open source
You can configure camera class to provide you the preview buffer (but copies). This is provided throuh PreviewBuffer Callback interface. You have implement the interface and set it on the camera. During preview you will get the preview buffers.
http://developer.android.com/reference/android/hardware/Camera.PreviewCallback.html
Then you can apply custom processing algorithm on the buffer and use either Surface or opengl surface to draw the same.
Shash316
Check out OpenCV... it will require you to do some work in C/C++, JNI and the Android NDK but it is a really nice library and should do what you need pretty easily.
Kieran is right, OpenCV would be a good and easy way with a lot of capabilities.
See http://opencv.willowgarage.com/wiki/AndroidTrunk for details of the android implementation.
And checkout the sample application: https://code.ros.org/svn/opencv/trunk/opencv/android/apps/OpenCV_SAMPLE/
This should get you a good starter as it is an example using processors for the live image.

Categories

Resources