#include "SimpleMotionRenderer.h" #include "GLExtensions.h" #include #include bool SimpleMotionRenderer::InitializeGl(unsigned width, unsigned height) { mWidth = width; mHeight = height; return mWidth > 0 && mHeight > 0; } void SimpleMotionRenderer::RenderFrame(uint64_t frameIndex) { const float t = static_cast(frameIndex) / 60.0f; const float red = 0.1f + 0.4f * (0.5f + 0.5f * std::sin(t)); const float green = 0.1f + 0.4f * (0.5f + 0.5f * std::sin(t * 0.73f + 1.0f)); const float blue = 0.15f + 0.3f * (0.5f + 0.5f * std::sin(t * 0.41f + 2.0f)); glViewport(0, 0, static_cast(mWidth), static_cast(mHeight)); glDisable(GL_SCISSOR_TEST); glClearColor(red, green, blue, 1.0f); glClear(GL_COLOR_BUFFER_BIT); const int boxWidth = (std::max)(1, static_cast(mWidth / 6)); const int boxHeight = (std::max)(1, static_cast(mHeight / 5)); const float phase = 0.5f + 0.5f * std::sin(t * 1.7f); const int x = static_cast(phase * static_cast(mWidth - static_cast(boxWidth))); const int y = static_cast((0.5f + 0.5f * std::sin(t * 1.1f + 0.8f)) * static_cast(mHeight - static_cast(boxHeight))); glEnable(GL_SCISSOR_TEST); glScissor(x, y, boxWidth, boxHeight); glClearColor(1.0f - red, 0.85f, 0.15f + blue, 1.0f); glClear(GL_COLOR_BUFFER_BIT); const int stripeWidth = (std::max)(1, static_cast(mWidth / 80)); const int stripeX = static_cast((frameIndex % 120) * (mWidth - static_cast(stripeWidth)) / 119); glScissor(stripeX, 0, stripeWidth, static_cast(mHeight)); glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); glDisable(GL_SCISSOR_TEST); } void SimpleMotionRenderer::ShutdownGl() { mWidth = 0; mHeight = 0; }