I have an android application. I want to use OpenGL to render my images and add effects. also I want a separate view where user can scribble on. I want the background color of the view to be transparent. I also want to zoom in and out as I zoom in or out the image. I am thinking I shall control the zoom in and out using glScalef()
. But I shall also need to increase the pen width as I zoom (scale up) the view. I want to write this view in openGL. I am new to android and openGL. please guide me with your ideas.
1 Answers
I have tried a different approach to implement my functionality of scribbling over a glSurfaceView and simultaneously be able to zoom in and zoom out. I have done all the scribbling over normal android provided canvas. In the background I have a GLSurfaceView. On top of it i have a scribbble view (http://www.java2s.com/Code/Android/2D-Graphics/Classforthescribblememopad.htm). I have set the background of ScribbleView as TRANSPARENT. When I am done Scribbling I put scribbling off using onClickListener of a Button (when scribbling is off user can zoom in and zoom out). I can zoom in or out using ScaleGestureDetector.SimpleOnScaleGestureListener. In its onScale()
I am using mScaleFactor=(mScaleFactor * detector.getScaleFactor());
Where mScaleFactor is initlised to 1f and mScaleFactor is used to track the current ScalingFactor. For scaling of glSurface I use glScalef(mScaleFactor,mScaleFactor)
and for canvas scaling I use canvas.scale(mScaleFactor,mScaleFactor,getWidth()/2,getHeight()/2)
. I have set the pivot point to middle of the view as the coordinates of the canvas is such that its origin is at top left.
After I scale up or scale down the canvas Then for correct scribbling I have in onTouchEvent(Event event) of Scribble view I have done the below mapping for the
event.getX() and event.getY(). <br>
x=(event.getX()- getWidth() / 2) / getmScaleFactor() + getWidth() / 2;<br>
y=(event.getX()- getWidth() / 2) / getmScaleFactor() + getWidth() / 2;<br>
<br>
Now when I do scribbling on the zoomed in or out canvas I can scribble at the point where I touch the screen correctly.
I hope I have been able to give you all some insight of my approach.
Thanks Krishna.