select screen
This commit is contained in:
@@ -55,6 +55,7 @@ Fusion Of Real-time Generative Effects.
|
|||||||
options:
|
options:
|
||||||
--help show this help message and exit
|
--help show this help message and exit
|
||||||
-v, --version print version
|
-v, --version print version
|
||||||
|
-s, --screen output screen number (default: primary)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Release guide
|
## Release guide
|
||||||
@@ -89,8 +90,8 @@ make -f Makefile.dev release-arch
|
|||||||
- [ ] Handle compilation errors
|
- [ ] Handle compilation errors
|
||||||
- [ ] Minimal working fragment sample
|
- [ ] Minimal working fragment sample
|
||||||
- [ ] Hot-reload fragment shader
|
- [ ] Hot-reload fragment shader
|
||||||
- [ ] Force fullscreen
|
- [x] Force fullscreen
|
||||||
- [ ] Select screen as argument
|
- [ ] Select screen as argument / config
|
||||||
- [ ] Midi
|
- [ ] Midi
|
||||||
- [ ] Read Midi events
|
- [ ] Read Midi events
|
||||||
- [ ] Read midi mapping config file
|
- [ ] Read midi mapping config file
|
||||||
|
|||||||
+44
-5
@@ -6,21 +6,29 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
void print_help(int status_code) {
|
void print_help(int status_code) {
|
||||||
puts(PACKAGE " " VERSION "\n\n"
|
puts(PACKAGE
|
||||||
|
" " VERSION "\n\n"
|
||||||
"usage: " PACKAGE " "
|
"usage: " PACKAGE " "
|
||||||
"[--help] "
|
"[--help] "
|
||||||
"[-v] "
|
"[-v] "
|
||||||
|
"[-s=SCREEN] "
|
||||||
"\n\n"
|
"\n\n"
|
||||||
"Fusion Of Real-time Generative Effects.\n\n"
|
"Fusion Of Real-time Generative Effects.\n\n"
|
||||||
"options:\n"
|
"options:\n"
|
||||||
" --help show this help message and exit\n"
|
" --help show this help message and exit\n"
|
||||||
" -v, --version print version\n");
|
" -v, --version print version\n"
|
||||||
|
" -s, --screen output screen number (default: primary)\n");
|
||||||
exit(status_code);
|
exit(status_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
void invalid_arg(char *arg) {
|
void invalid_arg(char *arg) {
|
||||||
fprintf(stderr, "invalid argument: '%s'\n\n", arg);
|
fprintf(stderr, "invalid argument: '%s'\n\n", arg);
|
||||||
print_help(EXIT_FAILURE);
|
print_help(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void invalid_value(char *arg, char *value) {
|
||||||
|
fprintf(stderr, "invalid value for argument '%s': '%s'\n\n", arg, value);
|
||||||
|
print_help(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_arg(char *arg, char *ref) { return strcoll(arg, ref) == 0; }
|
bool is_arg(char *arg, char *ref) { return strcoll(arg, ref) == 0; }
|
||||||
@@ -30,8 +38,37 @@ char *split_arg_value(char *arg) {
|
|||||||
return strtok(NULL, "=");
|
return strtok(NULL, "=");
|
||||||
}
|
}
|
||||||
|
|
||||||
parameters parse_args(int argc, char **argv) {
|
bool is_digit(char c) { return c >= '0' && c <= '9'; }
|
||||||
parameters params;
|
|
||||||
|
bool is_number(char *value) {
|
||||||
|
if (value == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
unsigned long value_len = strlen(value);
|
||||||
|
unsigned int i;
|
||||||
|
for (i = 0; i < value_len; i++) {
|
||||||
|
if (!is_digit(value[i])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char parse_uchar(char *arg, char *value) {
|
||||||
|
if (!is_number(value)) {
|
||||||
|
invalid_value(arg, value);
|
||||||
|
}
|
||||||
|
unsigned long long tmp_value = (unsigned long long)atoll(value);
|
||||||
|
if (tmp_value >= 256) {
|
||||||
|
invalid_value(arg, value);
|
||||||
|
}
|
||||||
|
return (unsigned char)tmp_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
Parameters parse_args(int argc, char **argv) {
|
||||||
|
Parameters params;
|
||||||
|
|
||||||
|
params.screen = 0;
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
char *arg;
|
char *arg;
|
||||||
@@ -44,6 +81,8 @@ parameters parse_args(int argc, char **argv) {
|
|||||||
} else if (is_arg(arg, "-v") || is_arg(arg, "--version")) {
|
} else if (is_arg(arg, "-v") || is_arg(arg, "--version")) {
|
||||||
puts(PACKAGE " " VERSION);
|
puts(PACKAGE " " VERSION);
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
|
} else if (is_arg(arg, "-s") || is_arg(arg, "--screen")) {
|
||||||
|
params.screen = parse_uchar(arg, value);
|
||||||
} else {
|
} else {
|
||||||
invalid_arg(arg);
|
invalid_arg(arg);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -3,6 +3,6 @@
|
|||||||
#ifndef ARGS_H
|
#ifndef ARGS_H
|
||||||
#define ARGS_H
|
#define ARGS_H
|
||||||
|
|
||||||
parameters parse_args(int argc, char **argv);
|
Parameters parse_args(int argc, char **argv);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+33
-6
@@ -45,42 +45,69 @@ static const char *fragment_shader_text =
|
|||||||
|
|
||||||
void error_callback(int error, const char *description) {
|
void error_callback(int error, const char *description) {
|
||||||
fprintf(stderr, "Error %d: %s\n", error, description);
|
fprintf(stderr, "Error %d: %s\n", error, description);
|
||||||
|
glfwTerminate();
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void key_callback(GLFWwindow *window, int key, int scancode, int action,
|
static void key_callback(GLFWwindow *window, int key, int scancode, int action,
|
||||||
int mods) {
|
int mods) {
|
||||||
|
// close window on escape key
|
||||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
|
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
|
||||||
glfwSetWindowShouldClose(window, GLFW_TRUE);
|
glfwSetWindowShouldClose(window, GLFW_TRUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void *init_window(GLFWwindow **window) {
|
void *init_window(GLFWwindow **window, Parameters params) {
|
||||||
|
// set errors handler
|
||||||
glfwSetErrorCallback(error_callback);
|
glfwSetErrorCallback(error_callback);
|
||||||
|
|
||||||
|
// print current GLFW version
|
||||||
fprintf(stdout, "[GLFW] %s\n", glfwGetVersionString());
|
fprintf(stdout, "[GLFW] %s\n", glfwGetVersionString());
|
||||||
|
|
||||||
|
// init GLFW
|
||||||
if (!glfwInit()) {
|
if (!glfwInit()) {
|
||||||
fprintf(stderr, "[GLFW] Initialization failed\n");
|
fprintf(stderr, "[GLFW] Initialization failed\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add context to window before creation
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||||
glfwWindowHint(GLFW_DECORATED, NULL);
|
glfwWindowHint(GLFW_DECORATED, 0);
|
||||||
|
|
||||||
(*window) = glfwCreateWindow(640, 480, PACKAGE " " VERSION,
|
// detect monitors
|
||||||
glfwGetPrimaryMonitor(), NULL);
|
int count;
|
||||||
|
GLFWmonitor **monitors = glfwGetMonitors(&count);
|
||||||
|
|
||||||
|
// check selected monitor availability
|
||||||
|
if (params.screen >= count) {
|
||||||
|
fprintf(stderr, "Screen %d is out of range [0-%d]\n", params.screen,
|
||||||
|
count - 1);
|
||||||
|
glfwTerminate();
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// create fullscreen window in selected monitor
|
||||||
|
(*window) = glfwCreateWindow(1, 1, PACKAGE " " VERSION,
|
||||||
|
monitors[params.screen], NULL);
|
||||||
|
|
||||||
|
// handle window creation fail
|
||||||
if (!(*window)) {
|
if (!(*window)) {
|
||||||
fprintf(stderr, "[GLFW] Window or context creation failed\n");
|
fprintf(stderr, "[GLFW] Window or context creation failed\n");
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// use current window
|
||||||
glfwMakeContextCurrent((*window));
|
glfwMakeContextCurrent((*window));
|
||||||
|
// link GLAD and GLFW window
|
||||||
gladLoadGL(glfwGetProcAddress);
|
gladLoadGL(glfwGetProcAddress);
|
||||||
|
// set keyboard handler
|
||||||
glfwSetKeyCallback((*window), key_callback);
|
glfwSetKeyCallback((*window), key_callback);
|
||||||
|
// hide cursor
|
||||||
|
glfwSetInputMode((*window), GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||||
|
// vsync
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
return window;
|
return window;
|
||||||
@@ -144,10 +171,10 @@ void loop(GLFWwindow *window, ShaderProgram program) {
|
|||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
void forge_run(parameters params) {
|
void forge_run(Parameters params) {
|
||||||
GLFWwindow *window;
|
GLFWwindow *window;
|
||||||
|
|
||||||
init_window(&window);
|
init_window(&window, params);
|
||||||
|
|
||||||
ShaderProgram program = init_program();
|
ShaderProgram program = init_program();
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -3,6 +3,6 @@
|
|||||||
#ifndef FORGE_H
|
#ifndef FORGE_H
|
||||||
#define FORGE_H
|
#define FORGE_H
|
||||||
|
|
||||||
void forge_run(parameters params);
|
void forge_run(Parameters params);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
parameters params;
|
Parameters params;
|
||||||
params = parse_args(argc, argv);
|
params = parse_args(argc, argv);
|
||||||
puts(PACKAGE " " VERSION);
|
puts(PACKAGE " " VERSION);
|
||||||
forge_run(params);
|
forge_run(params);
|
||||||
|
|||||||
+3
-5
@@ -4,9 +4,9 @@
|
|||||||
#ifndef TYPES_H
|
#ifndef TYPES_H
|
||||||
#define TYPES_H
|
#define TYPES_H
|
||||||
|
|
||||||
struct Parameters {
|
typedef struct Parameters {
|
||||||
// TODO
|
unsigned char screen;
|
||||||
};
|
} Parameters;
|
||||||
|
|
||||||
typedef struct Vertex {
|
typedef struct Vertex {
|
||||||
vec2 pos;
|
vec2 pos;
|
||||||
@@ -28,6 +28,4 @@ typedef struct ShaderProgram {
|
|||||||
GLuint vertex_array;
|
GLuint vertex_array;
|
||||||
} ShaderProgram;
|
} ShaderProgram;
|
||||||
|
|
||||||
typedef struct Parameters parameters;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user