Al desplazar la rueda del ratón cambia el color de fondo de la ventana

parent 2443606f
Showing with 23 additions and 0 deletions
...@@ -45,10 +45,33 @@ void mouse_button_callback(GLFWwindow *window, int button, int action, int mods) ...@@ -45,10 +45,33 @@ void mouse_button_callback(GLFWwindow *window, int button, int action, int mods)
} }
} }
const double gradient_step = 0.05;
const double gradient_colors[][3] = {{0.6, 0.6, 0.6}, {1, 0.65, 0}};
void scroll_callback(GLFWwindow *window, double xoffset, double yoffset) { void scroll_callback(GLFWwindow *window, double xoffset, double yoffset) {
static double position_in_gradient = 0;
std::cout << "Movida la rueda del raton " std::cout << "Movida la rueda del raton "
<< xoffset << " unidades en horizontal y " << xoffset << " unidades en horizontal y "
<< yoffset << " unidades en vertical" << std::endl; << yoffset << " unidades en vertical" << std::endl;
position_in_gradient += yoffset * gradient_step;
if (position_in_gradient > 1) {
position_in_gradient = 1;
} else if (position_in_gradient < 0) {
position_in_gradient = 0;
}
double a = (1 - position_in_gradient);
double b = position_in_gradient;
glClearColor(
gradient_colors[0][0] * a + gradient_colors[1][0] * b,
gradient_colors[0][1] * a + gradient_colors[1][1] * b,
gradient_colors[0][2] * a + gradient_colors[1][2] * b,
1.0
);
} }
int main() { int main() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment