Skip to content

Commit d0f482c

Browse files
committed
Improve pause behaviour of opengl_underlay example for C++
Ported #9360 from Rust to C++
1 parent 7e66df5 commit d0f482c

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

examples/opengl_underlay/main.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,19 @@ class OpenGLUnderlay
166166
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
167167
std::chrono::steady_clock::now() - start_time);
168168
glUniform1f(effect_time_location, elapsed.count());
169+
170+
// Handle the rotation and freezing of rotation via the UI toggle.
169171
if (enable_rotation) {
170-
glUniform1f(rotation_time_location, elapsed.count());
171-
} else {
172-
glUniform1f(rotation_time_location, 0.0);
172+
if (!last_rotation_enabled) {
173+
rotation_pause_offset = elapsed.count() - rotation_time;
174+
}
175+
rotation_time = elapsed.count() - rotation_pause_offset;
173176
}
174177

178+
glUniform1f(rotation_time_location, rotation_time);
179+
180+
last_rotation_enabled = enable_rotation;
181+
175182
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
176183
glUseProgram(0);
177184
}
@@ -185,6 +192,9 @@ class OpenGLUnderlay
185192
GLuint rotation_time_location = 0;
186193
std::chrono::time_point<std::chrono::steady_clock> start_time =
187194
std::chrono::steady_clock::now();
195+
double rotation_time = 0.0;
196+
bool last_rotation_enabled = true;
197+
double rotation_pause_offset = 0.0;
188198
};
189199

190200
int main()

0 commit comments

Comments
 (0)