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
|
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>
int main()
{
/// create the window
sf::Window window(sf::VideoMode(800, 600), "OpenGL", sf::Style::Default, sf::ContextSettings(32));
window.setVerticalSyncEnabled(true);
/// load resources, initialize the OpenGL states, ...
glLoadIdentity();
glTranslatef(15.0f, 0.0f, -6.0f);
/// 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
glViewport(0, 0, event.size.width, event.size.height);
}
}
/// clear the buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/// draw...
glBegin(GL_TRIANGLES);
glVertex3f(0.f, 0.f, 0.f);
glVertex3f(-1.f, -1.f, 0.f);
glVertex3f(1.f, -1.f, 0.f);
glEnd();
/// end the current frame (internally swaps the front and back buffers)
window.display();
}
/// release resources...
return 0;
}
|