Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7933873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:27:43+00:00 2026-06-03T21:27:43+00:00

I’m trying to implement finger paint app via GLSurfaceView. But quads are blinking so

  • 0

I’m trying to implement finger paint app via GLSurfaceView.

But quads are blinking so much, that I’m obliged to repaint them several times (see onTouchEvent in PaintGL class). It seems that I’m drawing on different frame buffers, but i dunno how to switch between them or disable them to avoid this nasty blinking.

Here is my Renderer:

public class PaintRenderer implements GLSurfaceView.Renderer 
{

    private FloatBuffer vertexBuffer;
    public ArrayList<HardPoint> l;
    public boolean isPressed = false;

    public PaintRenderer()
    {
        super ();
        l = new ArrayList<HardPoint>();
    }

    public void onDrawFrame(GL10 gl) 
    {

        ArrayList<HardPoint> n;
        int count;

        synchronized (l) 
        {
            n = (ArrayList<HardPoint>) l.clone();
        }

        if (n.size() == 0)
            return;

        n.add(n.get(n.size() - 1));

        for (int i = 1; i < n.size(); i++) {

            HardPoint start = n.get(i-1);
            HardPoint end = n.get(i);

            if (!end.isPressed)
                continue;

            float dx = end.x - start.x;
            float dy = end.y - start.y;

            count = (int) Math.ceil(Math.max(Math.sqrt(dx * dx + dy * dy), 1));

            for (int j = 0; j < count; j++) 
            {
                drawQuad(gl, new PointF(start.x + dx * (float)j/count , start.y + dy * (float)j/count), 40.0f);
            }

        }

    }

    public void onSurfaceChanged(GL10 gl, int width, int height) 
    {
        gl.glViewport(0, 0, width, height);

        gl.glMatrixMode(GL10.GL_PROJECTION);
        gl.glLoadIdentity();
        gl.glOrthof(0.0f, width, 0.0f, height, -1.0f, 1.0f);

        gl.glMatrixMode(GL10.GL_MODELVIEW);

        gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
        gl.glDisable(GL10.GL_DEPTH_TEST);

    }

    public void onSurfaceCreated(GL10 gl, EGLConfig config) 
    {
    }

    public void drawQuad(GL10 gl_main, PointF center, float side)
    {
        int VERTEX_COUNT = 4;
        float vertices[] = 
            {
                // Вершины квадрата
                  center.x - side/2, center.y + side/2,  // 0. левая нижняя
                  center.x + side/2, center.y + side/2,  // 1. правая нижняя
                  center.x - side/2, center.y - side/2,  // 2. левая верхняя
                  center.x + side/2, center.y - side/2,   // 3. правая верхняя
            };

        ByteBuffer vbb = ByteBuffer.allocateDirect(VERTEX_COUNT * 3 * 4);
        vbb.order(ByteOrder.nativeOrder());
        vertexBuffer = vbb.asFloatBuffer();

        vertexBuffer.put(vertices);

        vertexBuffer.position(0);

        gl_main.glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
        gl_main.glVertexPointer(2, GL10.GL_FLOAT, 0, vertexBuffer);

        gl_main.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);

    }

}

And here is my GLSurfaceView class:

public class PaintGL extends GLSurfaceView
{

    private Context mContext;
    private PaintRenderer renderer;
    private PointF prev_loc, cur_loc;

    public PaintGL(Context context) {
        super(context);
        mContext = context;
        renderer = new PaintRenderer();
        setRenderer(renderer);
        setRenderMode(RENDERMODE_WHEN_DIRTY);
    }


    @Override
    public boolean onTouchEvent(MotionEvent event) 
    {
        if (event.getAction() == MotionEvent.ACTION_DOWN)
        {
            synchronized (renderer.l) 
            {
                renderer.l.add(0, new HardPoint(event.getX(), this.getHeight() - event.getY(), true));
            }
        }
        if (event.getAction() == MotionEvent.ACTION_MOVE || event.getAction() == MotionEvent.ACTION_UP)
        {
            //FIXME Мерцание первого quad'a при достаточно большом количестве точек
            int count = 10;
            synchronized (renderer.l) {
                renderer.l.add(0, new HardPoint(event.getX(), this.getHeight() - event.getY(), 
                        event.getAction() == MotionEvent.ACTION_UP ? false : true));
                while (renderer.l.size() > count)
                {
                    renderer.l.remove(count);
                }
            }
            requestRender();
            Log.d("x", renderer.l.size()+" ");
        }

        return true;
    }

}

And HardPoint class:

public class HardPoint extends PointF 
{
    boolean isPressed;

    public HardPoint() 
    {
        isPressed = false;
    }

    public HardPoint (float x, float y, boolean pressed)
    {
        super(x, y);
        isPressed = pressed;
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T21:27:44+00:00Added an answer on June 3, 2026 at 9:27 pm

    Some points:

    • See Designing for Performance:

    There are two basic rules for writing efficient code:

    • Don’t do work that you don’t need to do.
    • Don’t allocate memory if you can avoid it.
    • ArrayList.clone creates a shallow copy. You’d’ve to add code for a deep copy or use a library like cloning.

    • Get rid of the synchronization between the UI- and the Renderthread on the single list. Use a second list where the UI-Thread just adds HardPoint instances (synchronized). At the beginning of onDrawFrame, transfer the HardPoint instances to the “render” list (synchronized). Then, you can limit the size of the list. This eliminates the clone.

    • Instead of creating the quad geometry each time anew, create it once, and translate it to the correct position.

    • To eliminate the creation of the HardPoint instances, you could apply a Pool (here’s the AndEngine one) pre-allocates the instances.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.