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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:02:47+00:00 2026-06-04T11:02:47+00:00

I have problems with smooth scrolling in OpenGL (testing on SGS2 and ACE) I

  • 0

I have problems with smooth scrolling in OpenGL (testing on SGS2 and ACE)
I created simple applications – only fixed speed horizontal scrolling of images, or only one image (player) moving by accelerator,
but it’s movement is not smooth 🙁
I tried many various of code but no satisfaction…

first I tried work with GLSurfaceView.RENDERMODE_CONTINUOUSLY and I put all code to onDrawFrame:

    public void onDrawFrame(GL10 gl) 
    {
      updateGame(gl, 0.017f);
      drawGame(gl); 
    }

this is the simplest and absolute smooth!! – but it’s dependent on hardware speed (= useless)

    public void onDrawFrame(GL10 gl) 
    { 
      frameTime = SystemClock.elapsedRealtime();        
      elapsedTime = (frameTime - lastTime) / 1000; 
      updateGame(gl, elapsedTime);
      drawGame(gl); 
      lastTime = frameTime; 
    }

this is the best of all but it’s not as smooth as the previous, sometimes flick

second I tried GLSurfaceView.RENDERMODE_WHEN_DIRTY, in onDrawFrame i have only drawing objects and this code in separate Thread:

   while (true) 
   {
     updateGame(renderer, 0.017f);
     mGLSurfaceView.requestRender();
     next_game_tick += SKIP_TICKS;
     sleep_time = next_game_tick - System.currentTimeMillis();
     if (sleep_time >= 0) 
     {
       try 
       {
          Thread.sleep(sleep_time);
       } 
       catch (Exception e) {}
       }
       else 
       {
         Log.d("running behind: ", String.valueOf(sleep_time));
       }
     } 

this is not smooth and it’s not problem with “running behind”

My objective is smooth image movement like in first code example above.

Possible error is somewhere else then I looking. Please, Can somebody help me with this?

Is better use RENDERMODE_WHEN_DIRTY or RENDERMODE_CONTINUOUSLY?

Thank you.

  • 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-04T11:02:48+00:00Added an answer on June 4, 2026 at 11:02 am

    I was fighting with the exact same issue for several days. The loop looks smooth without any Android time reference, but as soon it includes any type of “time sync” , external factors out of the android development control introduce serious discontinuities to the final result.

    Basically, these factors are:

    • eglSwapInterval is not implemented in Android, so is difficult to know the moment when the hardware expose the final draw in the screen (hardware screen sync)
    • Thread.sleep is not precise. The Thread may sleep more or less than requested.
    • SystemClock.uptimeMillis()System.nanoTime(), System.currentTimeMillis() and other timing related measurement are not accurate (its precise).

    The issue is independent of the drawing technology (drawing, openGL 1.0/1.1 and 2.0) and the game loop method (fixed time step, interpolation, variable time step).
    Like you, I was trying Thread.sleep, crazy interpolations, timers, etc. Doesn’t matter what you will do, we don’t have control over this factors.

    According with many Q&A on this site, the basic rules to produce smooth continuous animations are:

    • Reduce at the minimum the GC by removing all dynamic memory request.
    • Render frames as fast the hardware can process them (40 to 60fps is ok in most android devices).
    • Use fixed time steps with interpolation or variable time steps.
    • Optimize the update physics and draw routines to be execute in relative constant time without high peaks variance.

    For sure, you made a lot of previous work before post this question by optimizing your updateGame() and drawGame() (without appreciable GC and relative constant execution time) in order to get a smooth animation in your main loop as you mention: “simple and absolute smooth”.

    Your particular case with variable stepTime and no special requirements to be in perfect sync with realTime events (like music), the solution is simple: “smooth the step Time variable”.
    The solution works with other game loop schemes (fixed time step with variable rendering) and is easy to port the concept (smooth the amount of displacement produced by the updateGame and the real time clock across several frames.)

        // avoid GC in your threads. declare nonprimitive variables out of onDraw
        float smoothedDeltaRealTime_ms=17.5f; // initial value, Optionally you can save the new computed value (will change with each hardware) in Preferences to optimize the first drawing frames 
        float movAverageDeltaTime_ms=smoothedDeltaRealTime_ms; // mov Average start with default value
        long lastRealTimeMeasurement_ms; // temporal storage for last time measurement
    
        // smooth constant elements to play with
        static final float movAveragePeriod=40; // #frames involved in average calc (suggested values 5-100)
        static final float smoothFactor=0.1f; // adjusting ratio (suggested values 0.01-0.5)
    
        // sample with opengl. Works with canvas drawing: public void OnDraw(Canvas c)   
        public void onDrawFrame(GL10 gl){       
            updateGame(gl, smoothedDeltaRealTime_ms); // divide 1000 if your UpdateGame routine is waiting seconds instead mili-seconds.
            drawGame(gl);  
    
            // Moving average calc
            long currTimePick_ms=SystemClock.uptimeMillis();
            float realTimeElapsed_ms;
            if (lastRealTimeMeasurement_ms>0){
            realTimeElapsed_ms=(currTimePick_ms - lastRealTimeMeasurement_ms);
            } else {
                     realTimeElapsed_ms=smoothedDeltaRealTime_ms; // just the first time
            }
            movAverageDeltaTime_ms=(realTimeElapsed_ms + movAverageDeltaTime_ms*(movAveragePeriod-1))/movAveragePeriod;
    
             // Calc a better aproximation for smooth stepTime
            smoothedDeltaRealTime_ms=smoothedDeltaRealTime_ms +(movAverageDeltaTime_ms - smoothedDeltaRealTime_ms)* smoothFactor;
    
            lastRealTimeMeasurement_ms=currTimePick_ms;
        }
    
        // Optional: check if the smoothedDeltaRealTIme_ms is too different from original and save it in Permanent preferences for further use.
    

    For a fixed time step scheme, an intermetiate updateGame can be implemented to improve the results:

    float totalVirtualRealTime_ms=0;
    float speedAdjustments_ms=0; // to introduce a virtual Time for the animation (reduce or increase animation speed)
    float totalAnimationTime_ms=0;
    float fixedStepAnimation_ms=20; // 20ms for a 50FPS descriptive animation
    int currVirtualAnimationFrame=0; // useful if the updateGameFixedStep routine ask for a frame number
    
    private void updateGame(){
        totalVirtualRealTime_ms+=smoothedDeltaRealTime_ms + speedAdjustments_ms;
    
        while (totalVirtualRealTime_ms> totalAnimationTime_ms){
            totalAnimationTime_ms+=fixedStepAnimation_ms;
            currVirtualAnimationFrame++;
            // original updateGame with fixed step                
            updateGameFixedStep(currVirtualAnimationFrame);
        }
    
    
        float interpolationRatio=(totalAnimationTime_ms-totalVirtualRealTime_ms)/fixedStepAnimation_ms;
        Interpolation(interpolationRatio);
    }
    

    Tested with canvas and openGlES10 drawing with the following devices: SG SII (57 FPS), SG Note(57 FPS) , SG tab(60 FPS), unbranded Android 2.3 (43 FPS) slow emulator running on Windows XP(8 FPS). The test platform draws around 45 objects + 1 huge background (texture from 70MP source image) moving along a path specified in real physics parameters (km/h and G’s), without spikes or flick between several devices (well, 8 FPS on the emulator doesn’t look good, but its flow at constant speed as expected)

    Check The graphs for how android report the time. Some times Android report a large delta time and just the next loop it’s small than average, meaning an offset on the reading of realTime value.

    enter image description here

    with more detail:
    enter image description here

    How to limit framerate when using Android's GLSurfaceView.RENDERMODE_CONTINUOUSLY?

    System.currentTimeMillis vs System.nanoTime

    Does the method System.currentTimeMillis() really return the current time?

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

Sidebar

Related Questions

I have a problems in OpenGL with blending (in result of antialiasing or textured
i have a one page website with smooth scrolling effect when an a tag
I have problems binding both a telerik RadGrid and a plain vanilla ASP.NET GridView
I have problems with how I should structure my product listing pages, products pages,
I have problems with dealing with widows within a multicols environment, that is, I
I have problems to get rspec running properly to test validates_inclusion_of my migration looks
I have problems getting some of my views aligned in a relative layout that
I have problems with my keyup binding when cloning an element. Here's the scenario:
I have problems with Darwin Streaming server 5.5.5 on Debian. When i'm trying to
I have problems with following code: http://lisper.ru/apps/format/96 The problem is in normalize function, which

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.