update_camera();
}
-void set_window_size(int width, int height)
+void camera_on_resize(int width, int height)
{
mat4x4_perspective(camera.projection, 86.1f / 180.0f * M_PI, (float) width / (float) height, 0.01f, 1000.0f);
}
void init_camera(GLFWwindow *window, ShaderProgram *prog);
void set_camera_position(v3f pos);
void set_camera_angle(f32 yaw, f32 pitch);
-void set_window_size(int width, int height);
+void camera_on_resize(int width, int height);
void camera_enable();
extern struct movement_dirs
static void framebuffer_size_callback(__attribute__((unused)) GLFWwindow* window, int width, int height)
{
glViewport(0, 0, width, height);
- set_window_size(width, height);
- hud_rescale(width, height);
+
+ camera_on_resize(width, height);
+ hud_on_resize(width, height);
+ input_on_resize(width, height);
+}
+
+static void cursor_pos_callback(__attribute__((unused)) GLFWwindow* window, double current_x, double current_y)
+{
+ input_on_cursor_pos(current_x, current_y);
+}
+
+static void window_pos_callback(__attribute__((unused)) GLFWwindow* window, int x, int y)
+{
+ input_on_window_pos(x, y);
}
static void client_loop()
set_camera_position((v3f) {0.0f, 0.0f, 0.0f});
set_camera_angle(0.0f, 0.0f);
- set_window_size(width, height);
+ camera_on_resize(width, height);
hud_init(prog);
- hud_rescale(width, height);
+ hud_on_resize(width, height);
hud_add(RESSOURCEPATH "textures/crosshair.png", (v3f) {0.0f, 0.0f, 0.0f}, (v2f) {1.0f, 1.0f}, HUD_SCALE_TEXTURE);
init_input(&client, window);
+ input_on_resize(width, height);
clientplayer_add_to_scene(&client.player);
glfwSetFramebufferSizeCallback(window, &framebuffer_size_callback);
+ glfwSetCursorPosCallback(window, &cursor_pos_callback);
+ glfwSetWindowPosCallback(window, &window_pos_callback);
struct timespec ts, ts_old;
clock_gettime(CLOCK_REALTIME, &ts_old);
#pragma GCC diagnostic pop
}
-void hud_rescale(int width, int height)
+void hud_on_resize(int width, int height)
{
hud.width = width;
hud.height = height;
void hud_init(ShaderProgram *prog);
void hud_deinit();
-void hud_rescale(int width, int height);
+void hud_on_resize(int width, int height);
void hud_render();
HUDElement *hud_add(char *texture, v3f pos, v2f scale, HUDScaleType scale_type);
Client *client;
HUDElement *pause_menu_hud;
bool paused;
+ bool fullscreen;
KeyListener pause_listener;
+ KeyListener fullscreen_listener;
+ int small_x, small_y, small_width, small_height;
} input;
-static void cursor_pos_callback(__attribute__((unused)) GLFWwindow* window, double current_x, double current_y)
+void input_on_cursor_pos(double current_x, double current_y)
{
if (input.paused)
return;
set_camera_angle(input.client->player.yaw, input.client->player.pitch);
}
+void input_on_resize(int width, int height)
+{
+ if (! input.fullscreen) {
+ input.small_width = width;
+ input.small_height = height;
+ }
+}
+
+void input_on_window_pos(int x, int y)
+{
+ if (! input.fullscreen) {
+ input.small_x = x;
+ input.small_y = y;
+ }
+}
+
static bool move(int forward, int backward, vec3 dir)
{
f32 sign;
void process_input()
{
do_key_listener(&input.pause_listener);
+ do_key_listener(&input.fullscreen_listener);
if (input.pause_listener.fired) {
input.paused = ! input.paused;
}
}
+ if (input.fullscreen_listener.fired) {
+ input.fullscreen = ! input.fullscreen;
+
+ if (input.fullscreen) {
+ GLFWmonitor *monitor = glfwGetPrimaryMonitor();
+ const GLFWvidmode *vidmode = glfwGetVideoMode(monitor);
+ glfwSetWindowMonitor(input.window, monitor, 0, 0, vidmode->width, vidmode->height, 0);
+ } else {
+ glfwSetWindowMonitor(input.window, NULL, input.small_x, input.small_y, input.small_width, input.small_height, 0);
+ }
+ }
+
input.client->player.velocity.x = 0.0f;
input.client->player.velocity.z = 0.0f;
input.paused = false;
input.pause_listener = create_key_listener(GLFW_KEY_ESCAPE);
+ input.fullscreen_listener = create_key_listener(GLFW_KEY_F11);
- glfwSetCursorPosCallback(input.window, &cursor_pos_callback);
input.pause_menu_hud = hud_add(RESSOURCEPATH "textures/pause_layer.png", (v3f) {-1.0f, -1.0f, 0.5f}, (v2f) {1.0f, 1.0f}, HUD_SCALE_SCREEN);
enter_game();
void process_input();
void init_input(Client *client, GLFWwindow *window);
+void input_on_cursor_pos(double current_x, double current_y);
+void input_on_resize(int width, int height);
+void input_on_window_pos(int x, int y);
#endif