Skip to content

Instantly share code, notes, and snippets.

@kezadias
Created April 16, 2015 08:05
Show Gist options
  • Save kezadias/15f4c0bf600c5c5e0a70 to your computer and use it in GitHub Desktop.
Save kezadias/15f4c0bf600c5c5e0a70 to your computer and use it in GitHub Desktop.
ALL FILES
#include <GLFW/glfw3.h>
#include <iostream>
#include "src/graphics/window.h"
int main()
{
using namespace sparky;
using namespace graphics;
Window window("Sparky!", 800, 600);
while (!window.closed())
{
window.update();
}
std::cin.get();
return 0;
}
#include "window.h"
namespace sparky { namespace graphics {
Window::Window(const char *title, int width, int height)
{
m_Title = title;
m_Width = width;
m_Height = height;
if(!init())
glfwTerminate();
}
Window::~Window()
{
glfwTerminate();
}
bool Window::init()
{
if (!glfwInit())
{
std::cout << "Failed to initialize GLFW!" << std::endl;
return false;
}
m_Window = glfwCreateWindow(m_Width, m_Height, m_Title, NULL, NULL);
if (!m_Window)
{
std::cout << "Failed to create GLFW window!" std::endl;
return false;
}
glfwMakeContextCurrent(m_Window);
return true;
}
bool Window::closed() const
{
return glfwWindowShouldClose(m_Window);
}
void Window::update() const
{
glfwPollEvents();
glfwSwapBuffers(m_Window);
}
} }
#pragma once
#include <iostream>
#include <GLFW/glfw3.h>
namespace sparky { namespace graphics {
class Window
{
private:
const char *m_Title;
int m_Width, m_Height;
GLFWwindow *m_Window;
bool m_Closed;
public:
Window(const char *name, int width, int height);
~Window();
bool closed() const;
void update() const;
private:
bool init();
};
} }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment