diff --git a/Makefile b/Makefile index 9957b5e..228bdf8 100644 --- a/Makefile +++ b/Makefile @@ -4,13 +4,13 @@ CXXFLAGS := -std=c++11 -c LDFLAGS := -g LDLIBS= -lglfw -srcfiles := $(wildcard */*.cpp) +srcfiles := $(wildcard src/*.cpp) objfiles := $(subst src,obj,$(subst .cpp,.o,$(srcfiles))) all: main.out main.out: $(objfiles) - $(CXX) $(LDFLAGS) -o $@ $< $(LDLIBS) + $(CXX) $(LDFLAGS) -o $@ $(objfiles) $(LDLIBS) obj/%.o: src/%.cpp mkdir -p obj diff --git a/src/main.cpp b/src/main.cpp index cdbf967..17fb33c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,7 @@ #include +#include "window.h" #include +#include int main(){ std::cout << "Testing from work" << std::endl; @@ -7,21 +9,14 @@ int main(){ std::cerr << "Unable to initialize GLFW. Terminating." << std::endl; return 0; } - - GLFWwindow* window = glfwCreateWindow(800, 600, "Test Window", NULL, NULL); - if(!window){ - std::cerr << "Window creation failed. Terminating." << std::endl; - glfwTerminate(); - return 0; + Window* window = new Window(800, 600, "Test Window"); + while(!window->closing()){ + if(window->mouseDown(0)){ + std::cout << "mouse button down" << std::endl; + } + window->updateWindow(); } - glfwMakeContextCurrent(window); - while(!glfwWindowShouldClose(window)){ - // Game Loop - glfwSwapBuffers(window); - glfwPollEvents(); - } - - glfwDestroyWindow(window); + delete window; glfwTerminate(); return 0; diff --git a/src/window.cpp b/src/window.cpp new file mode 100644 index 0000000..fa5d76f --- /dev/null +++ b/src/window.cpp @@ -0,0 +1,31 @@ +#include "window.h" +#include + +Window::Window(int width, int height, std::string title){ + this->width = width; + this->height = height; + this->title = title; + this->window = glfwCreateWindow(width, height, title.c_str(), NULL, NULL); + makeContextCurrent(); +} + +Window::~Window(){ + glfwDestroyWindow(window); +} + +void Window::makeContextCurrent(){ + glfwMakeContextCurrent(window); +} + +void Window::updateWindow(){ + glfwSwapBuffers(window); + glfwPollEvents(); +} + +bool Window::closing(){ + return glfwWindowShouldClose(window); +} + +bool Window::mouseDown(int button){ + return glfwGetMouseButton(window, button); +} diff --git a/src/window.h b/src/window.h new file mode 100644 index 0000000..fdea225 --- /dev/null +++ b/src/window.h @@ -0,0 +1,18 @@ +#include +#include + +class Window{ + +private: + GLFWwindow* window; + std::string title; + int width, height; +public: + Window(int width, int height, std::string title); + ~Window(); + void updateWindow(); + void makeContextCurrent(); + bool closing(); + bool mouseDown(int button); + +};