abstracted window
This commit is contained in:
parent
2f8e8a0a91
commit
2c51afc3a3
4
Makefile
4
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
|
||||
|
21
src/main.cpp
21
src/main.cpp
@ -1,5 +1,7 @@
|
||||
#include <iostream>
|
||||
#include "window.h"
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <ostream>
|
||||
|
||||
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;
|
||||
}
|
||||
glfwMakeContextCurrent(window);
|
||||
while(!glfwWindowShouldClose(window)){
|
||||
// Game Loop
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
window->updateWindow();
|
||||
}
|
||||
|
||||
glfwDestroyWindow(window);
|
||||
delete window;
|
||||
|
||||
glfwTerminate();
|
||||
return 0;
|
||||
|
31
src/window.cpp
Normal file
31
src/window.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
#include "window.h"
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
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);
|
||||
}
|
18
src/window.h
Normal file
18
src/window.h
Normal file
@ -0,0 +1,18 @@
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <string>
|
||||
|
||||
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);
|
||||
|
||||
};
|
Loading…
Reference in New Issue
Block a user