-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackGround.cpp
More file actions
54 lines (43 loc) · 1.83 KB
/
Copy pathBackGround.cpp
File metadata and controls
54 lines (43 loc) · 1.83 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once
#include <Windows.h>
#include <gl/GL.h>
#include "BackGround.h"
BG::BG(const std::vector<std::array<float, 4>>& colors, const int& width, const int& height) : colors(colors), width(width), height(height) {}
void BG::fillGradient() const {
glBegin(GL_QUADS);
for (size_t i = 0; i < this->colors.size() - 1; ++i) {
// Extract start and end colors
auto& [r1, g1, b1, a1] = this->colors[i];
auto& [r2, g2, b2, a2] = this->colors[i + 1];
// Calculate start and end Y positions
float yStart = static_cast<float>(i) / (this->colors.size() - 1) * this->height;
float yEnd = static_cast<float>(i + 1) / (this->colors.size() - 1) * this->height;
// Set the gradient colors and vertices
glColor4f(r1, g1, b1, a1);
glVertex2f(0.0f, yStart);
glVertex2f(static_cast<float>(this->width), yStart);
glColor4f(r2, g2, b2, a2);
glVertex2f(static_cast<float>(this->width), yEnd);
glVertex2f(0.0f, yEnd);
}
glEnd();
}
void BG::fillGradient(const std::vector<std::array<float, 4>>& 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();
}