Greffin28
Greffin28

Reputation: 257

OpenGL stop drawing when moving window lwjgl

So basically i want to draw every time even when the window is moved because i'm using delta time to move animation and stuff. This mean if the opengl stop, the time is still going and sometimes it makes the player go through wall and blink to other place :/ how can this be fixed? i already try to use thread but it's not working (or at least i code it wrong)..

Upvotes: 0

Views: 746

Answers (1)

Stefan Haustein
Stefan Haustein

Reputation: 18803

You could just cap the deltaT if it gets too big. Or, if you have separate calls for rendering and movements (I'd recommend that anyway so you can drop rendering frames without having extremely large movements), and the deltaT gets too big, break it down to several smaller calls.

Capping:

public void update(int deltaMs) {
  if (deltaMs > 100) {
    deltaMs = 100;
  }
  ...

Split off rendering from updates and do small updates:

public void update(int deltaMs) {
   while(deltaMs > 100) {
      updateImpl(100);
      deltaMs -= 100;
   }
   updateImpl(deltaMs);
   render();
 }

You could even combine both approaches:

public void update(int deltaMs) {
   // Cap at one second.
   if (deltaMs > 1000) {
     delatMs = 1000;
   }

   // Handle movements in small steps to avoid going through walls etc.
   while(deltaMs > 100) {
      updateImpl(100);
      deltaMs -= 100;
   }
   updateImpl(deltaMs);

   render();
 }

Upvotes: 1

Related Questions