improved keymapping
This commit is contained in:
31
src/main.c
31
src/main.c
@@ -3,14 +3,31 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "pltf/pltf.h"
|
||||
#include "pltf/gl_funcs.h"
|
||||
#include "pltf/pltf.h"
|
||||
#include "shader.h"
|
||||
|
||||
void counter_cb(void* user_data) {
|
||||
int* counter = (int*) user_data;
|
||||
printf("Counter: %d\n", *counter);
|
||||
(*counter)++;
|
||||
typedef struct {
|
||||
const char* up_msg;
|
||||
const char* down_msg;
|
||||
int up_count;
|
||||
int down_count;
|
||||
} MsgState;
|
||||
|
||||
void msg_cb(const PltfKeyAction action, void* user_data) {
|
||||
MsgState* state = (MsgState*) user_data;
|
||||
switch (action) {
|
||||
case PLTF_KEY_DOWN:
|
||||
printf("Key: %s Count: %d\n", state->down_msg, state->down_count);
|
||||
state->down_count++;
|
||||
break;
|
||||
case PLTF_KEY_UP:
|
||||
printf("Key: %s Count: %d\n", state->up_msg, state->up_count);
|
||||
state->up_count++;
|
||||
break;
|
||||
default:
|
||||
printf("INVALID PltfKeyAction. Was %d\n", action);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
@@ -22,8 +39,8 @@ int main() {
|
||||
pltf_gl_ctx_info_print();
|
||||
|
||||
pltf_key_callback_set(PLTF_KEY_ESC, pltf_window_close, NULL);
|
||||
int counter = 0;
|
||||
pltf_key_callback_set(PLTF_KEY_Q, counter_cb, &counter);
|
||||
MsgState msg_state = { .up_msg = "UP", .down_msg = "DOWN", .up_count = 0, .down_count = 0 };
|
||||
pltf_key_callback_set(PLTF_KEY_Q, msg_cb, &msg_state);
|
||||
|
||||
// clang-format off
|
||||
const float triangle_verts[] = {
|
||||
|
||||
Reference in New Issue
Block a user