removed printf:s, made error printing more consistent

This commit is contained in:
Rakarake 2026-02-22 21:49:04 +01:00
parent 2383faf456
commit 44ba0468d9
2 changed files with 13 additions and 32 deletions

View file

@ -18,8 +18,8 @@ GLuint compile_shader(GLuint type, const char *src) {
glGetShaderiv(id, GL_INFO_LOG_LENGTH, &result);
char *message = alloca(length * sizeof(char));
glGetShaderInfoLog(id, length, &length, message);
printf("failed to compile %s shader\n", type == GL_VERTEX_SHADER ? "vertex" : "fragment");
printf("%s\n", message);
fprintf(stderr, "failed to compile %s shader\n", type == GL_VERTEX_SHADER ? "vertex" : "fragment");
fprintf(stderr, "%s\n", message);
glDeleteShader(id);
return 0;
}
@ -72,7 +72,7 @@ GLuint create_shader(const char *fragment_src) {
GLuint load_shader(const char *path) {
FILE *handle = fopen(path, "r");
if (handle == NULL) {
printf("failed to open shader file: '%s'\n", path);
fprintf(stderr, "failed to open shader file: '%s'\n", path);
exit(1);
}
@ -89,7 +89,7 @@ GLuint load_shader(const char *path) {
strcpy(string, fragment_header_src);
if (!fread(string + header_length, sizeof(char), file_length, handle)) {
printf("failed to read shader file\n");
fprintf(stderr, "failed to read shader file\n");
exit(1);
}
@ -121,8 +121,6 @@ GLuint load_shader(const char *path) {
Renderer new_renderer() {
const char *version_str = (const char *)glGetString(GL_VERSION);
const char *renderer_str = (const char *)glGetString(GL_RENDERER);
printf("GL_VERSION: %s\n", version_str);
printf("GL_RENDERER: %s\n", renderer_str);
glEnable(GL_DEPTH_TEST);
@ -175,7 +173,6 @@ int shader_file_was_modified(Renderer *state) {
void render(Renderer *state, int w, int h, double time, char *shader_path, int reload_shader) {
int m = shader_file_was_modified(state);
if (m || reload_shader || strcmp(state->shader_path, shader_path)) {
printf("reloading!\n");
state->shader = load_shader(shader_path);
state->shader_path = shader_path;
}

View file

@ -89,28 +89,24 @@ static void egl_init(struct client_state *state) {
state->egl_display = eglGetDisplay((EGLNativeDisplayType) state->wl_display);
if (state->egl_display == EGL_NO_DISPLAY) {
fprintf(stderr, "Can't create egl display\n");
fprintf(stderr, "can't create egl display\n");
exit(1);
} else {
fprintf(stderr, "Created egl display\n");
}
EGLint major, minor;
if (eglInitialize(state->egl_display, &major, &minor) != EGL_TRUE) {
fprintf(stderr, "Can't initialise egl display\n");
fprintf(stderr, "can't initialise egl display\n");
exit(1);
}
printf("EGL major: %d, minor %d\n", major, minor);
// Desktop GL?
if (eglBindAPI(EGL_OPENGL_API) == EGL_FALSE) {
printf("eglBindAPI failed\n");
fprintf(stderr, "eglBindAPI failed\n");
exit(1);
}
EGLint count;
eglGetConfigs(state->egl_display, NULL, 0, &count);
printf("EGL has %d configs\n", count);
EGLConfig *configs = calloc(count, sizeof *configs);
@ -122,10 +118,8 @@ static void egl_init(struct client_state *state) {
EGLint size;
eglGetConfigAttrib(state->egl_display,
configs[i], EGL_BUFFER_SIZE, &size);
printf("Buffer size for config %d is %d\n", i, size);
eglGetConfigAttrib(state->egl_display,
configs[i], EGL_RED_SIZE, &size);
printf("Red size for config %d is %d\n", i, size);
// just choose the first one
state->egl_config = configs[i];
break;
@ -136,20 +130,17 @@ static void egl_init(struct client_state *state) {
state->egl_config,
EGL_NO_CONTEXT, context_attribs);
if (state->egl_context == EGL_NO_CONTEXT) {
printf("Failed to create EGL context\n");
fprintf(stderr, "failed to create EGL context\n");
exit(1);
}
}
void egl_init_surface(struct client_state *state, struct surface *surface) {
printf("Creating egl window of size: %dx%d\n", surface->width, surface->height);
surface->egl_window = wl_egl_window_create(surface->wl_surface,
surface->width, surface->height);
if (surface->egl_window == EGL_NO_SURFACE) {
fprintf(stderr, "Can't create egl window\n");
fprintf(stderr, "can't create egl window\n");
exit(1);
} else {
fprintf(stderr, "Created egl window\n");
}
surface->egl_surface =
@ -159,9 +150,8 @@ void egl_init_surface(struct client_state *state, struct surface *surface) {
if (eglMakeCurrent(state->egl_display, surface->egl_surface,
surface->egl_surface, state->egl_context)) {
fprintf(stderr, "Made current\n");
} else {
fprintf(stderr, "Made current failed\n");
fprintf(stderr, "made current failed\n");
}
}
@ -256,7 +246,6 @@ void layer_new(struct client_state *state, struct wl_output *wl_output) {
static void wl_output_name(void *data, struct wl_output *wl_output, const char *name) {
struct client_state *state = data;
printf("output name: %s\n", name);
if (state->output_list != NULL) {
for (int i = 0; i < state->output_list_len; i++) {
if (strcmp(state->output_list[i], name) == 0) {
@ -455,8 +444,8 @@ static void registry_handle_global(
const char *interface,
uint32_t version
) {
printf("interface: '%s', version: %d, name: %d\n",
interface, version, name);
//printf("interface: '%s', version: %d, name: %d\n",
// interface, version, name);
struct client_state *state = data;
@ -519,11 +508,6 @@ static const struct wl_registry_listener wl_registry_listener = {
/// Initializes wayland and creates an opengl context
struct client_state* wayland_init(int output_type, char *output_list[], int output_list_len) {
if (output_list != NULL) {
for (int i = 0; i < output_list_len; i++) {
printf("output name selected: %s\n", output_list[i]);
}
}
struct client_state *state = malloc(sizeof(struct client_state));
state->output_list = output_list;
state->output_list_len = output_list_len;
@ -570,7 +554,7 @@ struct event wait_for_event(struct client_state *state) {
if (eglMakeCurrent(state->egl_display, next->data.egl_surface,
next->data.egl_surface, state->egl_context)) {
} else {
fprintf(stderr, "Made current failed\n");
fprintf(stderr, "made current failed\n");
}
struct event event = {
.type = EVENT_DRAW,