-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackGround.cpp
More file actions
29 lines (23 loc) · 941 Bytes
/
BackGround.cpp
File metadata and controls
29 lines (23 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#pragma once
#include <Windows.h>
#include <gl/GL.h>
#include "BackGround.h"
void BG::fillGradient(const std::vector<std::tuple<GLfloat, GLfloat, GLfloat, GLfloat>>& colors, const int& width, const int& height) {
glBegin(GL_QUADS);
for (size_t i = 0; i < colors.size() - 1; ++i) {
// Extract start and end colors
auto [r1, g1, b1, a1] = colors[i];
auto [r2, g2, b2, a2] = colors[i + 1];
// Calculate start and end Y positions
float yStart = static_cast<float>(i) / (colors.size() - 1) * height;
float yEnd = static_cast<float>(i + 1) / (colors.size() - 1) * height;
// Set the gradient colors and vertices
glColor4f(r1, g1, b1, a1);
glVertex2f(0.0f, yStart);
glVertex2f(static_cast<float>(width), yStart);
glColor4f(r2, g2, b2, a2);
glVertex2f(static_cast<float>(width), yEnd);
glVertex2f(0.0f, yEnd);
}
glEnd();
}