Need to use opengl in combination with View - android

I am new in android. I need to use opengl in combination with View Class to draw something. How to do this. plz give me any hints or suggestions...

You also have the option to combine "normal" android views (Button, ImageView, etc) in a layout with a GlSurfaceView. (i.e. FrameLayout)
By doing so you can combine normal android UI with openGL, you can also make a composite view where the openGL view is just part of the layout.
This is the way ads are usually displayed overlaying 3D aplications.
Be aware that this technique can produce quite weird results in low end devices when dealing with tranasparency.

You probably wanta GlSurfaceView. It's a View that allows you to use Opengl to draw to it.
Put it in a layout file for your app
<GLSurfaceView id="#+id/myView" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
Then in your code
((GLSurfaceView)findViewById(R.id.myView)).setRenderer(new GlSurfaceView.Renderer() {
public void onSurfaceCreated(...)...
public void onSurfaceChanged(...)...
public void onDraw(GL10 gl)...
});
((GLSurfaceView)findViewById(R.id.myView)).setRenderMode(RENDERMODE_CONTINUOUSLY);
And then you draw in your onDraw with your gl calls.
This is the super-quick start answer to your question, if you drop the surfaceview in framelayout and know what your drawing it's pretty quick to get a basic setup running.

Related

Is it possible to use android.graphics.Camera on ViewGroup?

My purpose: I have a RelativeLayout acting like a button (clickable) and it has multiple views inside of it: TextView, Image. I want to transform this RelativeLayout alltogether (as if it is like a single object) in 3D coordinates.
What I know: I know that by using Camera and modifiying Matrix, i can really transform an Image view in 3d.
However, i can't do this on a ViewGroup like a RelativeLayout as i can't modify it's matrix.
Question: Is it possible and if yes, how?
Well android isn't built to work that way, each view in android is responsible for drawing it self, so you can't just put a certain render logic in a parent view and expect the child views to cope with it.
Easiest thing I can think of is to create your own big view and draw your child views manually inside it, then I believe you can achieve the desired effect by using the camera object with your canvas.
Or you can go openGL but that would only make sense if you have performance issue in the above approach

Android - How to overlay images in a WebView?

I'm trying to overlay several images[to form a building plan with possible zoom].
The point is to choose which images to averlay each time depending on selected filters[staff, equipements ...].
After doing researches, I implemented the zoom using a WebView but I didn't find a way to make this webview take different images at once [which is possible with ImageView using LayerDrawable].
Is there any way to achieve this ? or should I just stick the ImageViews and find a way to implement Zoom in it ?? I hope my question is clear and not too stupid since I'm just a beginner :).
Thanks for your help!!
While you can stack several ImageViews on top of each other, if you want to make this efficient and feature rich (pinch zoon, panning) you need to create your own component, either based on View or based on SurfaceView.
Personally I think SurfaceView is an overkill here, subclassing simple view should be sufficient. You need to manually draw your layers from bitmaps on canvas on onDraw() method of the view.
Then you can use GestureDetector or ScaleGestureDetector to add zoom by scaling your canvas via affine transformations.
Use a RelativeLayout for starters.
You could use the ViewGroup.addView(View child, int index, ViewGroup.LayoutParams params) or a variant along with ViewGroup.removeView(View view) or ViewGroup.removeViewAt(int index).
This would obviously require you to inflate the views manually using LayoutInflater but you could keep a global reference to each after inflating and just flip between the two

3D animation between layouts like the lock screen in jelly bean

So basically I'm trying to replicate this. It will be used like a view flipper. I haven't had much experience in doing this sort of stuff in android yet so any help would be appreciated!
I'm not exactly sure, what are you going to achieve, but I would start with such lecture: Android flip 3D animation. It's quite easy to replace views in the middle of such animation. You may consider writing your own container, if the ViewFlipper is not enough.
If the view is too complex for Android to handle, or your animation is intended to be more interesting than simple flip/scale/move, then you may consider using OpenGL and shaders. Simply draw your views to bitmaps, pass it to OpenGL and do whatever you want to do with them.

Gestures and OpenGL

I'm using OpenGL ES on android 2.3.3 at the minute to render a simple 3D game. I'd like to extend it using the built in gestures library, but I can't find a way to recognise the gestures from a GLSurfaceView as opposed to an android view(I don't have an XML layout is what I'm saying)
Is there any way to either implement an XML layout on top of what I have already, or preferably to implement the gestures library on top of the GLSurfaceview instead.
Thanks.
You can attach a normal onTouchListener to GLSurfaceView, so long as you have an instance of GLSurfaceView (which it sounds like is what you have). This is only really useful if you just want to know the raw x,y coordinates on screen where the user has pressed (e.g to rotate around the y if the user moves their finger left/right across the screen)
For gesture library, which I haven't used myself, you should be able to just place your GLSurfaceView inside a frame layout and then place another view (e.g. linear layout set to match_parent) in the same frame layout so that it completely covers the GLSurfaceView and is on top of it. Attach the gesture library to this view (and obviously make sure it is transparent so people can still see the GLSurfaceView below).
The gesture library has a way of 'stealing' events from the view. See here for details.
Here, here, and here are some examples that should make it clearer.

display transparent view over existing views

In Android 2.2, I want to display a few sprites and clickable animations over an existing view. I just discovered that SurfaceView cannot be transparent
I tried overriding dispatchDraw() of a LinearLayout but that doesn't seem to be callable via a Runnable Thread.
I also tried to extend Canvas directly, but that quickly turned into a mess when trying to place it in my XML layout.
Do I have to use GLSurfaceView to have a drawing view whose background is transparent?
Optimally, I'd like to just have a Canvas on which I can draw Bitmap at various coordinates, instead of dealing with the details of GL (unless GL is the only way I can do transparency).
Silly Rabbit. Just use Views and move them around wherever you want within a FrameLayout. SurfaceView is not designed for what you're trying to do.
I'm going to try Switching from Canvas to OpenGL and toss in parts of TranslucentGLSurfaceView.
I'm still open to selecting an answer that doesn't require OpenGL, just for the sake of it solving my original question.

Categories

Resources