-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
167 lines (134 loc) · 3.87 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
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
#include "Main.h"
using namespace sf;
RenderWindow MainWindow;
WindowHandle MainWindowHandle;
bool fullscreen = false;
bool debuginput = false;
bool paused = false;
//bool g_exit = false;
//void GameLoop(float dt);
void HandleEvent(const Event &event)
{
switch (event.type)
{
case Event::MouseButtonPressed:
if (debuginput)
{
cout << event.mouseButton.button + " was pressed" << endl;
cout << "mouse x: " << event.mouseButton.x << endl;
cout << "mouse y: " << event.mouseButton.y << endl;
}
break;
case Event::MouseButtonReleased:
if (debuginput)
{
cout << event.mouseButton.button + " was released" << endl;
cout << "mouse x: " << event.mouseButton.x << endl;
cout << "mouse y: " << event.mouseButton.y << endl;
}
break;
case Event::MouseMoved:
if (debuginput)
{
cout << "new mouse x: " << event.mouseMove.x << endl;
cout << "new mouse y: " << event.mouseMove.y << endl;
}
break;
case Event::KeyPressed:
if (debuginput)
{
cout << event.key.code + " was pressed" << endl;
cout << "control:" << event.key.control << endl;
cout << "alt:" << event.key.alt << endl;
cout << "shift:" << event.key.shift << endl;
cout << "system:" << event.key.system << endl;
}
break;
case Event::TextEntered:
if (debuginput && event.text.unicode < 128)
cout << "ASCII character typed: " << static_cast<char>(event.text.unicode) << endl;
break;
case Event::KeyReleased:
if (debuginput)
{
cout << "control:" << event.key.control << endl;
cout << "alt:" << event.key.alt << endl;
cout << "shift:" << event.key.shift << endl;
cout << "system:" << event.key.system << endl;
}
switch (event.key.code)
{
case Keyboard::Key::Escape:
break;
case Keyboard::Key::LSystem:
case Keyboard::Key::RSystem:
break;
}
break;
case Event::Closed:
//Save and prompt for confirmation of close
MainWindow.close();
break;
case Event::Resized:
// adjust the viewport when the window is resized
//glViewport(0, 0, event.size.width, event.size.height);
break;
case Event::LostFocus:
paused = true;
//autosave
break;
case Event::GainedFocus:
paused = false;
//load autosave
break;
}
}
void renderingThread(sf::Window* window)
{
// activate the window's context
window->setActive(true);
// the rendering loop
while (window->isOpen())
{
// draw...
// end the current frame -- this is a rendering function (it requires the context to be active)
window->display();
}
}
int main()
{//Switch to fullscreen for release
if (fullscreen)
{
MainWindow.create(VideoMode::getDesktopMode(), "Title Text", Style::Fullscreen);
}
else
{
MainWindow.create(VideoMode(800, 600), "Title Text");
}
ContextSettings settings = MainWindow.getSettings();
cout << "depth bits:" << settings.depthBits << endl;
cout << "stencil bits:" << settings.stencilBits << endl;
cout << "antialiasing level:" << settings.antialiasingLevel << endl;
cout << "version:" << settings.majorVersion << "." << settings.minorVersion << endl;
//glEnable(GL_TEXTURE_2D);
MainWindowHandle = MainWindow.getSystemHandle();
CircleShape shape(100.f);
shape.setFillColor(Color::Green);
Clock clock;
while (MainWindow.isOpen())
{
Time elapsed = clock.restart();
//updateGame(elapsed);
Event event;
while (MainWindow.pollEvent(event))
{
HandleEvent(event);
}
//clear the buffers
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
MainWindow.clear();
//MainWindow.draw(shape);
MainWindow.display();
}
return 0;
}