Skip to content

Instantly share code, notes, and snippets.

@newvertex
Created September 9, 2021 14:32
Show Gist options
  • Save newvertex/0721b2f82fa2ef8719cfd5bbe6fbe98c to your computer and use it in GitHub Desktop.
Save newvertex/0721b2f82fa2ef8719cfd5bbe6fbe98c to your computer and use it in GitHub Desktop.
basic SFML window with opengl context
#include <SFML/Window.hpp>
#include <SFML/OpenGL.hpp>
#include <iostream>
constexpr float R = 0.2f;
constexpr float G = 0.4f;
constexpr float B = 0.9f;
constexpr float A = 1.0f;
void sfmlContext(int width, int height, const char *title)
{
std::cout << "SFML Window Creation\n";
sf::ContextSettings settings;
settings.depthBits = 24;
settings.stencilBits = 8;
settings.antialiasingLevel = 2;
settings.majorVersion = 3;
settings.minorVersion = 3;
settings.attributeFlags = sf::ContextSettings::Core;
sf::Window window(sf::VideoMode(width, height), title, sf::Style::Close, settings);
bool running = true;
while (running)
{
sf::Event event;
while (window.pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
running = false;
break;
case sf::Event::KeyPressed:
if (event.key.code == sf::Keyboard::Escape)
running = false;
break;
default:
break;
}
}
glClearColor(R, G, B, A);
glClear(GL_COLOR_BUFFER_BIT);
window.display();
}
}
int main(int argc, char *argv[])
{
int width = 640;
int height = 480;
const char *title = "Hello World!";
sfmlContext(width, height, title);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment