-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsfml_opengl.cpp
executable file
·54 lines (47 loc) · 1.59 KB
/
sfml_opengl.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
#include <SFML/Window.hpp>
#include <SFML/OpenGL.hpp>
#include <SFML/Graphics.hpp>
int main()
{
// create the window
sf::RenderWindow window(sf::VideoMode(800, 600), "OpenGL", sf::Style::Default, sf::ContextSettings(32));
window.setVerticalSyncEnabled(true);
glClearColor(.2,.2,.2,0);
// activate the window
window.setActive(true);
// load resources, initialize the OpenGL states, ...
// run the main loop
bool running = true;
while (running)
{
// handle events
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
// end the program
running = false;
}
else if (event.type == sf::Event::Resized)
{
// adjust the viewport when the window is resized
window.setView(sf::View(sf::FloatRect(0, 0, event.size.width, event.size.height)));
glViewport(0, 0, event.size.width, event.size.height);
}
else if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
running = false;
}
// clear the buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// draw...
sf::RectangleShape rect(sf::Vector2f(200,200));
rect.setPosition(20,50);
rect.setFillColor(sf::Color(34,56,78));
window.draw(rect);
// end the current frame (internally swaps the front and back buffers)
window.display();
}
// release resources...
return 0;
}