voxelcore/src/window/Window.cpp
MihailRis 1a00a11917
All changes made for 10th part of tutorial
voxel_engine.cpp - changed structure, added character controls, physics
almost all files are modified (including shaders)
+ new source directory - physics
2021-08-04 01:45:04 +03:00

62 lines
1.4 KiB
C++

#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include "Window.h"
GLFWwindow* Window::window;
int Window::width = 0;
int Window::height = 0;
int Window::initialize(int width, int height, const char* title){
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
//glfwWindowHint(GLFW_SAMPLES, 2);
window = glfwCreateWindow(width, height, title, nullptr, nullptr);
if (window == nullptr){
std::cerr << "Failed to create GLFW Window" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glewExperimental = GL_TRUE;
if (glewInit() != GLEW_OK){
std::cerr << "Failed to initialize GLEW" << std::endl;
return -1;
}
glViewport(0,0, width, height);
glClearColor(0.0f,0.0f,0.0f,1);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Window::width = width;
Window::height = height;
return 0;
}
void Window::setCursorMode(int mode){
glfwSetInputMode(window, GLFW_CURSOR, mode);
}
void Window::terminate(){
glfwTerminate();
}
bool Window::isShouldClose(){
return glfwWindowShouldClose(window);
}
void Window::setShouldClose(bool flag){
glfwSetWindowShouldClose(window, flag);
}
void Window::swapBuffers(){
glfwSwapBuffers(window);
}