nits.kk
nits.kk

Reputation: 5316

How to call onDraw() of a class extending GLSurfaceView?

How do I call onDraw() on my class extending GLSurfaceView. I need the canvas for drawing the gestures of the user. (FingerPaint.java logic). Mean while I need the onDrawFrame() of the renderer to be called for other effects. I can manage the calls to both the methods by maintaing a flag. I am calling invalidate() but that too is not able to call the onDraw(). GLSurfaceView extends View so I thought I can override onDraw() and can call it by calling invalidate(). Please Throw some light. Thanks in Advance Krishna :)

Upvotes: 1

Views: 2613

Answers (2)

NikoDiYana
NikoDiYana

Reputation: 31

Just call invalidate() and onDraw() will be called, just like normal View. The canvas is drawn on top of the GLES viewport.

So far I couldn't implement invalidate(Rect dirty). The whole view is redrawn always.

It is needed to put setWillNotDraw(false) before drawing.

Upvotes: 1

Erik
Erik

Reputation: 812

Try calling requestRender () from your GLSurfaceView. Obviously this works best when setting rendermode to "RENDERMODE_WHEN_DIRTY". And that means you won't be rendering continuously, so that may interfere with the "constant" rendering required for your effects.

I think the best solution would be to split the rendering up between 2 overlaying surfaces and 2 renderers. Request the bottom surface (fingerpaint surface) to render a frame whenever the user interacts, and on the top one (gfx surface) you render continuously. Or swap this around... whatever works best.

Upvotes: 2

Related Questions