I use GLSurfaceView to show the camera's dataļ¼but if I put camera static for a few minutes and then move it, the GLSurfaceView will not preview any more and stuck,but onDrawFrame() still has response.However if I change the program that GLES20 used, GLSurfaceView work well soon.I don't know where the problem is.Thank for help!
Related
I'm trying to build a camera view as background.
I want to load my camera inside GLSurfaceView.Renderer class.
My class:
public class ModelRenderer implements GLSurfaceView.Renderer {
...
My question is, is it possible to load camera preview as background in GLSurfaceView.Renderer?
I'm using Android studio.
Well It isn't really adding the preview as a "background" but you certainly can draw the camera preview to the GLSurfaceView and attach a renderer to the surface to do the drawing. There are numerous examples of doing so. I would search around for them but I believe Grafika has what you are looking for.
I got a problem with drawing a mapView from the here-api into a glSurfaceView (it should be a glSurfaceView as some external devices requeres it to ensure good performance).
The map draws into a normal SurfaceView just perfectly.
I do the following steps to create the map-view in the GLSurfaceView:
Extend my view from GLSurfaceView:
public class MapView extends GLSurfaceView
Setting the Renderer uppon initialisation in the ctors:
setRenderer(...)
Start rendering after the map has been initialized:
Renderer renderer = new MapOffScreenRenderer(getContext());
renderer.setMap(map); //mapView, not null
updateRendererSize(); //update the render size to the screen size
renderer.start(getHolder(), surfaceUpdatedListener); // HERE COMES THE CRASH
It seems like the MapOffscreenRenderer crashes if i try to tell him to draw the map into the glSurfaceView.
The crash is a generic error: "12291 EGL_BAD_ALLOC during rendering".
If i try to call the renderer.start() func (without the holder param), then everything is fine (the only bad thing is that the map is not being drawn).
The GlSurceView initialisation itself is fine as i am able to draw my own geometries into it.
Thank you very much for you help.
MapOffScreenRenderer internally uses a PBuffer backed surface and its own rendering thread and EGL context. It is not intended to be used to push into another GLSurfaceView surface. If you really want to do this then maybe create an independent OpenGL surface and share it between the GLSurfaceView and the MapOffScreenRenderer.
What use case are you try to accomplish using this type of design?
I am following a tutorial on http://obviam.net/index.php/a-very-basic-the-game-loop-for-android/ to make an Android game loop. It works really well, except that my SurfaceView is only 526x320 while my phone is 1920x1080 resolution. Can anyone help me fix this issue?
First, that tutorial overrides onDraw() when rendering onto a SurfaceView Surface, which is a recipe for trouble. Don't do that. Don't extend SurfaceView unless you really want to draw on the View as well as the Surface. (Its render thread may also continue to run while the app isn't in the foreground... maybe you should find a tutorial by someone who understands SurfaceView better.)
Second, the SurfaceView's Surface is allowed to be a different size. You can set it to any (reasonable) size you want with the setFixedSize() method.
The default size of the SurfaceView should match the size of the View. If you have a full-screen View, the Surface will be the size of the screen.
iam currently using camera and surfaceview in my app to use Torch etc ... , im using these in an Activity ,
How to use Camera and SurfaceView in Background , ex . : I want to keep Torch/Led Flash On , i saw many Widget that work fine in Background , how they do it ?
Thanks .
Take a look here:
http://developer.android.com/guide/topics/media/camera.html
There is all the code you need to make an activity which shows the camera preview.
As the Camera API:
http://developer.android.com/reference/android/hardware/Camera.html#setPreviewDisplay%28android.view.SurfaceHolder%29
specifies...you need to use a SurfaceHolder for your preview. Thus you can only use a SurfaceView or a derived class for your automatic preview. Otherwise you can use for example a TextureView or an ImageView to draw your preview by yourself. You'll need though to implement the onFramePreview method to grab the frames from the preview and handle them by yourself. By using OpenGL or the ANI API you can also add effects to your frame. This is the only way, I know about, to also add effects directly on your preview, unless these effects can be achieved by overlaying a semi-transparent colored surface above your preview image.
On some devices, onPreviewFrame is not called if no SurfaceView was set to display the camera preview.
However, I handle the camera in a service, so I can't set a SurfaceView but I don't want to have visible preview anyway.
How can this be done? Can I programmatically create a SurfaceView and set it with Camera::setPreviewDisplay?
This must be possible or not?
It works on almost every phone without a SurfaceView but not on HTC One X and Google Nexus One...
According to this question, creating a SurfaceView in code works fine. Though I don't think you can create it through a service.
Another approach is to create a 1px-1px SurfaceView inside a RelativeLayout and hiding it with some other view on top of it. (visibility should still be VISIBLE). We use this trick for Path camera UI where we render preview buffers through OpenGL and it works fine.
According to documentation readily configured, visible and displayed surface view is necessary to activate camera preview. It may be overlayued though
From API 11 on, you can use a SurfaceTexture instead of a SurfaceView to get frames from the camera. Then, instead of using Camera.setPreviewDisplay, simply use Camera.setPreviewTexture.
This answer as well as this one discuss this point.