-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
94 lines (78 loc) · 2.15 KB
/
main.cpp
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
#include <iostream>
#include <GL/glew.h>
#include <GL/freeglut.h>
#include "Menu/menu.h"
#include "Game/game.h"
#include <windows.h>
#include <mmsystem.h>
using namespace std;
// Create instances of Menu and Game classes
int windowChoice = 0;
Menu menu;
Game game;
// Display function
void displayFunc() {
if(windowChoice == 0)
menu.draw();
else if(windowChoice == 1)
game.draw();
}
// Keyboard function
void keyboardFunc(unsigned char key, int x, int y) {
if(windowChoice == 0)
menu.keyInput(key, x, y);
else if(windowChoice == 1)
game.keyInput(key, x, y);
}
// Special function
void specialFunc(int key, int x, int y) {
if(windowChoice == 0)
menu.specialKeyInput(key, x, y);
else if(windowChoice == 1)
game.specialKeyInput(key, x, y);
}
// OpenGL window reshape routine.
void resize(int w, int h)
{
if(windowChoice == 0)
menu.resize(w, h);
else if(windowChoice == 1)
game.resize(w, h);
}
void setWindowIcon() {
// Load icon file
auto hIcon = (HICON)LoadImage(nullptr, "..//Images//icon.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);
if (hIcon == nullptr) {
// Error loading icon
std::cerr << "Failed to load icon!" << std::endl;
return;
}
// Set window icon
HWND hWnd = FindWindow(NULL, "Space War"); // Replace "Space War" with your window title
SendMessage(hWnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
}
void loadBackGroundSound() {
// PlaySound("..//Sounds//game.wav", nullptr, SND_ASYNC);
}
// Main routine.
int main(int argc, char **argv)
{
loadBackGroundSound();
glutInit(&argc, argv);
glutInitContextVersion(4, 3);
glutInitContextProfile(GLUT_COMPATIBILITY_PROFILE);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(1000, 1000);
glutCreateWindow("Space War");
setWindowIcon();
// glutFullScreen();
glewExperimental = GL_TRUE;
glewInit();
menu.setup();
glutDisplayFunc(displayFunc);
glutKeyboardFunc(keyboardFunc);
glutReshapeFunc(resize);
glutSpecialFunc(specialFunc);
glutMainLoop();
}