I am in the progress of writing a voxel raycaster in C, using OpenGL.
I want to create a basic shader that runs for each pixel in the screen, and don’t know how to do it correctly.

I tried creating a fragment shader that passed the color red and a “blank” vertex shader, however the fragment shader would not render red at all.

How can I accomplish this? This is how my code currently looks like:

#include "gl.h"
#include <GLFW/glfw3.h>

#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>

#ifdef _WIN32
#define ENDL "rn"
#elif __unix__ || __linux__ || __APPLE__
#define ENDL "n"
#else
#define ENDL "n"
#endif  

/*
 *  I prefer to store the width and height as constant integers instead of
 *  defining them through the preprocessor.
 */
const int g_width = 800, g_height = 600;

/* The game's window handle. */
GLFWwindow *g_window;

/* The shader(s) and their programs that we'll use for raycasting the voxel. */
GLuint g_shader;
GLuint g_program;

void error_callback(int error, const char* description)
{
    fprintf(stderr, "error: Got an error from GLFW (status=%d, descripton="%s")!" ENDL, error, description);
}

int main(int argc, const char *argv[])
{
    /*
     *  Initialize GLFW. After initializing it (if no errors occured), set
     *  the function `glfwTerminate` to be called on the program's exit.
     */
    if(!glfwInit())
    {
        fprintf(stderr, "error: Failed to initialize GLFW!" ENDL);
        exit(EXIT_FAILURE);
    }

    /* Let's make sure GLFW is terminated automatically for us. */
    atexit(glfwTerminate);

    /* Let's set up a callback for errors that happen in GLFW. */
    glfwSetErrorCallback(error_callback);

    /* Create the window using GLFW. */
    g_window = glfwCreateWindow(g_width, g_height, "Pixeria", NULL, NULL);
    if(!g_window)
    {
        fprintf(stderr, "error: Failed to create a window, maybe GLFW is at fault?" ENDL);
        exit(EXIT_FAILURE);
    }

    /* Make the newly created window the current window. */
    glfwMakeContextCurrent(g_window);

    /* Let's load OpenGL context for our newly created window. */
    if(gladLoadGL(glfwGetProcAddress) == 0)
    {
        fprintf(stderr, "error: Failed to load OpenGL! context!" ENDL);
        exit(EXIT_FAILURE);
    }

    /* Render loop runs here as long as the window isn't exited. */
    while(!glfwWindowShouldClose(g_window))
    {
        glfwSwapBuffers(g_window);
        glfwPollEvents();
    }

    exit(EXIT_SUCCESS);
}

1