#include <iostream>
#include "initialization.hpp"
class ExampleGradient:public Initialization
{
public:
ExampleGradient(DemoRunner *runner, int argc, char **argv);
~ExampleGradient()
{}
virtual
void
draw_frame(void) override;
virtual
void
handle_event(const SDL_Event &ev) override;
private:
enum gradient_type
{
linear_gradient,
radial_gradient,
sweep_gradient,
number_gradient_types
};
unsigned int m_gradient_type;
};
ExampleGradient::
ExampleGradient(DemoRunner *runner, int argc, char **argv):
Initialization(runner, argc, argv),
m_gradient_type(linear_gradient)
{
std::cout << "Press any key to change gradient\n";
m_color_stops = m_painter_engine_gl->colorstop_atlas().create(seq, 8);
}
void
ExampleGradient::
handle_event(const SDL_Event &ev)
{
switch (ev.type)
{
case SDL_KEYDOWN:
++m_gradient_type;
break;
}
m_gradient_type = m_gradient_type % number_gradient_types;
Initialization::handle_event(ev);
}
void
ExampleGradient::
draw_frame(void)
{
m_surface_gl->viewport(vwp);
brush.
color(1.0f, 1.0f, 1.0f, 1.0f);
uint32_t t;
t = SDL_GetTicks() % 4000u;
if (t >= 2000u)
{
t = 4000u - t;
}
switch (m_gradient_type)
{
case linear_gradient:
{
float c, s, tf, r;
p0 = window_dims * 0.5f;
}
break;
case radial_gradient:
{
float r0, r1;
p0 = p1 = window_dims * 0.5f;
r0 = 0.0f;
r1 = 10.0f +
fastuidraw::t_max(window_dims.x(), window_dims.y()) * static_cast<float>(t) / 4000.0f;
}
break;
case sweep_gradient:
{
float angle, repeat;
p = window_dims * 0.5f;
repeat = 1.0f;
}
break;
}
m_painter->fill_rect(brush,
.min_point(0.0f, 0.0f)
.max_point(window_dims));
m_painter->end();
fastuidraw_glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
fastuidraw_glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
m_surface_gl->blit_surface(GL_NEAREST);
}
int
main(int argc, char **argv)
{
DemoRunner demo_runner;
return demo_runner.main<ExampleGradient>(argc, argv);
}