forked from itsfuad/Computer-Graphics-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwelcome.h
More file actions
221 lines (179 loc) · 6.98 KB
/
Copy pathwelcome.h
File metadata and controls
221 lines (179 loc) · 6.98 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#pragma once
#include <GL/glut.h>
#include <GL/gl.h>
#include <string>
#include <vector>
#include <cmath>
#include <cstdio>
void switchScene(int newScene);
namespace Welcome {
const int WINDOW_WIDTH = 1200;
const int WINDOW_HEIGHT = 800;
const float TITLE_SCALE = 2.0f;
const float BUTTON_WIDTH = 200.0f;
const float BUTTON_HEIGHT = 50.0f;
bool isHoveringStart = false;
float titleY = WINDOW_HEIGHT * 0.7f;
float titleAlpha = 0.0f;
float buttonAlpha = 0.0f;
float instructionsAlpha = 0.0f;
struct Color {
float r, g, b, a;
Color(float r, float g, float b, float a = 1.0f) : r(r), g(g), b(b), a(a) {}
};
const Color TITLE_COLOR(0.2f, 0.4f, 0.8f);
const Color BUTTON_COLOR(0.2f, 0.6f, 0.9f);
const Color BUTTON_HOVER_COLOR(0.3f, 0.7f, 1.0f);
const Color TEXT_COLOR(0.9f, 0.9f, 0.9f);
void drawText(float x, float y, const std::string& text, float scale = 1.0f, const Color& color = TEXT_COLOR) {
glColor4f(color.r, color.g, color.b, color.a);
glRasterPos2f(x, y);
for (char c : text) {
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, c);
}
}
unsigned char* backgroundImage = nullptr;
void loadBackgroundImage(const char* filename) {
FILE* file = fopen(filename, "rb");
if (!file) return;
unsigned char header[54];
fread(header, 1, 54, file); // BMP header
int width = *(int*)&header[18];
int height = *(int*)&header[22];
int imageSize = 3 * width * height;
backgroundImage = new unsigned char[imageSize];
fread(backgroundImage, 1, imageSize, file);
fclose(file);
}
void drawSmallText(float x, float y, const std::string& text, const Color& color = TEXT_COLOR) {
glColor4f(color.r, color.g, color.b, color.a);
glRasterPos2f(x, y);
for (char c : text) {
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, c);
}
}
void drawCenteredText(float y, const std::string& text, float scale = 1.0f, const Color& color = TEXT_COLOR) {
float width = 0;
for (char c : text) {
width += glutBitmapWidth(GLUT_BITMAP_HELVETICA_18, c);
}
float x = (WINDOW_WIDTH - width * scale) / 2.0f;
drawText(x, y, text, scale, color);
}
void drawTitleWithShadow(float y, const std::string& text) {
drawCenteredText(y - 2, text, TITLE_SCALE, Color(0.0f, 0.0f, 0.0f, titleAlpha * 0.5f));
drawCenteredText(y + 2, text, TITLE_SCALE, Color(0.0f, 0.0f, 0.0f, titleAlpha * 0.5f));
drawCenteredText(y, text, TITLE_SCALE, TITLE_COLOR);
}
void drawButton(float x, float y, float width, float height, const std::string& text, bool isHovered) {
static float pulse = 0.0f;
pulse += 0.05f;
float hoverScale = isHovered ? 1.0f + 0.05f * sinf(pulse) : 1.0f;
float effectiveWidth = width * hoverScale;
float effectiveHeight = height * hoverScale;
float centerX = x + width / 2;
float centerY = y - height / 2;
Color buttonColor = isHovered ? BUTTON_HOVER_COLOR : BUTTON_COLOR;
glColor4f(buttonColor.r, buttonColor.g, buttonColor.b, buttonAlpha);
glBegin(GL_QUADS);
glVertex2f(centerX - effectiveWidth / 2, centerY + effectiveHeight / 2);
glVertex2f(centerX + effectiveWidth / 2, centerY + effectiveHeight / 2);
glVertex2f(centerX + effectiveWidth / 2, centerY - effectiveHeight / 2);
glVertex2f(centerX - effectiveWidth / 2, centerY - effectiveHeight / 2);
glEnd();
float textWidth = glutBitmapLength(GLUT_BITMAP_HELVETICA_18, (const unsigned char*)text.c_str());
float textX = centerX - textWidth / 2.0f;
float textY = centerY - 6;
drawText(textX, textY, text, 1.0f, Color(1.0f, 1.0f, 1.0f, buttonAlpha));
}
void drawBackground() {
if (backgroundImage) {
glRasterPos2i(0, 0);
glDrawPixels(WINDOW_WIDTH, WINDOW_HEIGHT, GL_BGR_EXT, GL_UNSIGNED_BYTE, backgroundImage);
} else {
// fallback gradient
glBegin(GL_QUADS);
glColor3f(0.05f, 0.05f, 0.15f);
glVertex2f(0, WINDOW_HEIGHT);
glVertex2f(WINDOW_WIDTH, WINDOW_HEIGHT);
glColor3f(0.1f, 0.1f, 0.2f);
glVertex2f(WINDOW_WIDTH, 0);
glVertex2f(0, 0);
glEnd();
}
}
void initScene() {
titleY = WINDOW_HEIGHT * 0.7f;
titleAlpha = 0.0f;
buttonAlpha = 0.0f;
instructionsAlpha = 0.0f;
}
void cleanupScene() {
// Nothing to clean up yet
}
void updateScene() {
static int frameCount = 0;
frameCount++;
if (titleY > WINDOW_HEIGHT * 0.6f) {
titleY -= 2.0f;
}
if (frameCount > 20 && titleAlpha < 1.0f) {
titleAlpha += 0.02f;
}
if (frameCount > 40 && buttonAlpha < 1.0f) {
buttonAlpha += 0.02f;
}
if (frameCount > 60 && instructionsAlpha < 1.0f) {
instructionsAlpha += 0.02f;
}
glutPostRedisplay();
}
void display() {
glClear(GL_COLOR_BUFFER_BIT);
drawBackground();
drawTitleWithShadow(titleY, "OpenGL City View Project");
float buttonX = (WINDOW_WIDTH - BUTTON_WIDTH) / 2.0f;
float buttonY = WINDOW_HEIGHT * 0.4f;
drawButton(buttonX, buttonY, BUTTON_WIDTH, BUTTON_HEIGHT, "Start", isHoveringStart);
std::vector<std::string> instructions = {
"Instructor: Anim Al Ahsan Rupai",
"Contributors: ",
" - Md. Fuad Hasan",
" - Md. Masud Alam",
" - Md. Mahtab Habib",
" - Abdullah Shoab",
};
float instructionY = WINDOW_HEIGHT * 0.25f;
for (const auto& instruction : instructions) {
float width = 0;
for (char c : instruction) {
width += glutBitmapWidth(GLUT_BITMAP_HELVETICA_12, c);
}
float x = (WINDOW_WIDTH - width) / 2.0f;
drawSmallText(x, instructionY, instruction, Color(0.8f, 0.8f, 0.8f, instructionsAlpha));
instructionY -= 20.0f;
}
}
void mouse(int button, int state, int x, int y) {
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
float buttonX = (WINDOW_WIDTH - BUTTON_WIDTH) / 2.0f;
float buttonY = WINDOW_HEIGHT * 0.4f;
if (x >= buttonX && x <= buttonX + BUTTON_WIDTH &&
y >= buttonY - BUTTON_HEIGHT && y <= buttonY) {
::switchScene(1);
}
}
}
void mouseMotion(int x, int y) {
float buttonX = (WINDOW_WIDTH - BUTTON_WIDTH) / 2.0f;
float buttonY = WINDOW_HEIGHT * 0.4f;
isHoveringStart = (x >= buttonX && x <= buttonX + BUTTON_WIDTH &&
y >= buttonY - BUTTON_HEIGHT && y <= buttonY);
glutPostRedisplay();
}
void keyboard(unsigned char key, int x, int y) {
if (key == 27) { // ESC
exit(0);
}
}
}