voxels renderer rebuilt, WorldFiles fix
This commit is contained in:
@@ -13,60 +13,15 @@ float Events::y = 0.0f;
|
||||
bool Events::_cursor_locked = false;
|
||||
bool Events::_cursor_started = false;
|
||||
|
||||
#define _MOUSE_BUTTONS 1024
|
||||
|
||||
void cursor_position_callback(GLFWwindow*, double xpos, double ypos){
|
||||
if (Events::_cursor_started){
|
||||
Events::deltaX += xpos-Events::x;
|
||||
Events::deltaY += ypos-Events::y;
|
||||
}
|
||||
else {
|
||||
Events::_cursor_started = true;
|
||||
}
|
||||
Events::x = xpos;
|
||||
Events::y = ypos;
|
||||
}
|
||||
|
||||
void mouse_button_callback(GLFWwindow*, int button, int action, int){
|
||||
if (action == GLFW_PRESS){
|
||||
Events::_keys[_MOUSE_BUTTONS+button] = true;
|
||||
Events::_frames[_MOUSE_BUTTONS+button] = Events::_current;
|
||||
}
|
||||
else if (action == GLFW_RELEASE){
|
||||
Events::_keys[_MOUSE_BUTTONS+button] = false;
|
||||
Events::_frames[_MOUSE_BUTTONS+button] = Events::_current;
|
||||
}
|
||||
}
|
||||
|
||||
void key_callback(GLFWwindow*, int key, int /*scancode*/, int action, int /*mode*/) {
|
||||
if (action == GLFW_PRESS){
|
||||
Events::_keys[key] = true;
|
||||
Events::_frames[key] = Events::_current;
|
||||
}
|
||||
else if (action == GLFW_RELEASE){
|
||||
Events::_keys[key] = false;
|
||||
Events::_frames[key] = Events::_current;
|
||||
}
|
||||
}
|
||||
|
||||
void window_size_callback(GLFWwindow*, int width, int height){
|
||||
glViewport(0,0, width, height);
|
||||
Window::width = width;
|
||||
Window::height = height;
|
||||
}
|
||||
|
||||
int Events::initialize(){
|
||||
GLFWwindow* window = Window::window;
|
||||
_keys = new bool[1032];
|
||||
_frames = new uint[1032];
|
||||
|
||||
memset(_keys, false, 1032*sizeof(bool));
|
||||
memset(_frames, 0, 1032*sizeof(uint));
|
||||
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
glfwSetMouseButtonCallback(window, mouse_button_callback);
|
||||
glfwSetCursorPosCallback(window, cursor_position_callback);
|
||||
glfwSetWindowSizeCallback(window, window_size_callback);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,4 +30,6 @@ public:
|
||||
static void toggleCursor();
|
||||
};
|
||||
|
||||
#define _MOUSE_BUTTONS 1024
|
||||
|
||||
#endif /* WINDOW_EVENTS_H_ */
|
||||
|
||||
+49
-3
@@ -1,5 +1,6 @@
|
||||
#include <iostream>
|
||||
#include "Window.h"
|
||||
#include "Events.h"
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
@@ -7,13 +8,53 @@ GLFWwindow* Window::window = nullptr;
|
||||
uint Window::width = 0;
|
||||
uint Window::height = 0;
|
||||
|
||||
int Window::initialize(uint width, uint height, const char* title){
|
||||
void cursor_position_callback(GLFWwindow*, double xpos, double ypos) {
|
||||
if (Events::_cursor_started) {
|
||||
Events::deltaX += xpos - Events::x;
|
||||
Events::deltaY += ypos - Events::y;
|
||||
}
|
||||
else {
|
||||
Events::_cursor_started = true;
|
||||
}
|
||||
Events::x = xpos;
|
||||
Events::y = ypos;
|
||||
}
|
||||
|
||||
void mouse_button_callback(GLFWwindow*, int button, int action, int) {
|
||||
if (action == GLFW_PRESS) {
|
||||
Events::_keys[_MOUSE_BUTTONS + button] = true;
|
||||
Events::_frames[_MOUSE_BUTTONS + button] = Events::_current;
|
||||
}
|
||||
else if (action == GLFW_RELEASE) {
|
||||
Events::_keys[_MOUSE_BUTTONS + button] = false;
|
||||
Events::_frames[_MOUSE_BUTTONS + button] = Events::_current;
|
||||
}
|
||||
}
|
||||
|
||||
void key_callback(GLFWwindow*, int key, int /*scancode*/, int action, int /*mode*/) {
|
||||
if (action == GLFW_PRESS) {
|
||||
Events::_keys[key] = true;
|
||||
Events::_frames[key] = Events::_current;
|
||||
}
|
||||
else if (action == GLFW_RELEASE) {
|
||||
Events::_keys[key] = false;
|
||||
Events::_frames[key] = Events::_current;
|
||||
}
|
||||
}
|
||||
|
||||
void window_size_callback(GLFWwindow*, int width, int height) {
|
||||
glViewport(0, 0, width, height);
|
||||
Window::width = width;
|
||||
Window::height = height;
|
||||
}
|
||||
|
||||
int Window::initialize(uint width, uint height, const char* title, int samples){
|
||||
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, 16);
|
||||
glfwWindowHint(GLFW_SAMPLES, samples);
|
||||
|
||||
window = glfwCreateWindow(width, height, title, nullptr, nullptr);
|
||||
if (window == nullptr){
|
||||
@@ -35,11 +76,16 @@ int Window::initialize(uint width, uint height, const char* title){
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_BLEND);
|
||||
glEnable(GL_MULTISAMPLE);
|
||||
// glDisable(GL_MULTISAMPLE);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
Window::width = width;
|
||||
Window::height = height;
|
||||
|
||||
Events::initialize();
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
glfwSetMouseButtonCallback(window, mouse_button_callback);
|
||||
glfwSetCursorPosCallback(window, cursor_position_callback);
|
||||
glfwSetWindowSizeCallback(window, window_size_callback);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -6,11 +6,11 @@
|
||||
class GLFWwindow;
|
||||
|
||||
class Window {
|
||||
static GLFWwindow* window;
|
||||
public:
|
||||
static uint width;
|
||||
static uint height;
|
||||
static GLFWwindow* window; // не лучшее решение делать window публичным
|
||||
static int initialize(uint width, uint height, const char* title);
|
||||
static int initialize(uint width, uint height, const char* title, int samples);
|
||||
static void terminate();
|
||||
|
||||
static void viewport(int x, int y, int width, int height);
|
||||
|
||||
Reference in New Issue
Block a user