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 7682611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:36:28+00:00 2026-05-31T18:36:28+00:00

I have a helper method drawRect(p1, p2) that draws a rectangle (in orthographic projection).

  • 0

I have a helper method drawRect(p1, p2) that draws a rectangle (in orthographic projection). The code works fine if I do this:

function webGLStart() {
    // initialization code

    gl.clear(gl.COLOR_BUFFER_BIT);
    gl.uniformMatrix4fv(shaderProgram.pMatrixLoc, false, pMatrix);

    drawRect(new Point(10, 10), new Point(50, 50));
}

Now suppose I want to render a new rectangle after every mouse click. So I cleared the canvas, set up the projection matrix and moved the drawRect call in mouse down handler. And it is not working.

function webGLStart() {
    // initialization code

    gl.clear(gl.COLOR_BUFFER_BIT);
    gl.uniformMatrix4fv(shaderProgram.pMatrixLoc, false, pMatrix);

    canvas.onmousedown = handleMouseDown;
}

function handleMouseDown(event) {
    // x, y depends on click coordinate
    drawRect(new Point(x, y), new Point(x + 20, y + 20));
}

The whole canvas is getting vanished after mouse click. However, if I store the information of all rectangles in an array and in mouse handler I clear the canvas and then draw all rectangles from the array then there is no problem. In other words if I re-render the complete scene then there is no problem.

So my question is: is it not possible to draw one after another without clearing the whole canvas and refreshing everything?

  • 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-05-31T18:36:29+00:00Added an answer on May 31, 2026 at 6:36 pm

    If you want to “preserve” the background then you must use the preserveDrawingBuffer flag:

    gl = canvas.getContext("experimental-webgl", {preserveDrawingBuffer:true} );
    

    See these recent answers:

    When WebGL decide to update the display?

    Webgl update region using viewport+scissor

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

Sidebar

Related Questions

I have a helper method that serialises an object, which works until you try
I have this helper method that I can't seem to clean up with content_tag
I have an object obj that is passed into a helper method. public static
In my rails project I have a presenter method that has a helper view
I have a helper method that retrieves a string that I need to get
In my Rails app I have a helper method location that gets the coordinates
I have a helper method that creates navigation links for some controllers. def gen_associations(controllers)
So I have a helper method that looks something like the following: private D
I have a helper method that calls two other helper methods, the problem is
I have a helper method for my Rails app that returns a string with

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.