<commit_before>#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <assert.h>
#include <unistd.h>

#include <bcm_host.h>

#include <GLES/gl.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>

#include "model_board/model_board.h"

/* OpenGL rotation matrix that converts ground coordinates
 * (x=easy, y=north, z=up) into board coordinates.  It is
 * column-major so do matrix[COL][ROW]. */
float matrix[4][4];

// Acceleration vector in units of g (9.8 m/s^2).
float acceleration[3];

// Magnetic field vector where each component is approximately between -1 and 1.
float magnetic_field[3];

// 0 = Screen faces south, 90 = West, 180 = North, 270 = East
// TODO: read screen_orientation from environment
float screen_orientation = 0;

uint32_t screen_width, screen_height;
EGLDisplay display;
EGLSurface surface;
EGLContext context;

// Sets the display, OpenGL|ES context and screen stuff
static void init_opengl(void)
{
    EGLBoolean result;
    EGLint num_config;

    static EGL_DISPMANX_WINDOW_T nativewindow;

    DISPMANX_ELEMENT_HANDLE_T dispman_element;
    DISPMANX_DISPLAY_HANDLE_T dispman_display;
    DISPMANX_UPDATE_HANDLE_T dispman_update;

    static const EGLint attribute_list[] =
        {
            EGL_RED_SIZE, 8,
            EGL_GREEN_SIZE, 8,
            EGL_BLUE_SIZE, 8,
            EGL_ALPHA_SIZE, 8,
            EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
            EGL_NONE
        };
   
    EGLConfig config;

    // get an EGL display connection
    display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    assert(display!=EGL_NO_DISPLAY);

    // initialize the EGL display connection
    result = eglInitialize(display, NULL, NULL);
    assert(EGL_FALSE != result);

    // get an appropriate EGL frame buffer configuration
    result = eglChooseConfig(display, attribute_list, &config, 1, &num_config);
    assert(EGL_FALSE != result);

    // create an EGL rendering context
    context = eglCreateContext(display, config, EGL_NO_CONTEXT, NULL);
    assert(context!=EGL_NO_CONTEXT);

    // create an EGL window surface
    int32_t success = graphics_get_display_size(0 /* LCD */, &screen_width, &screen_height);
    assert( success >= 0 );

    VC_RECT_T dst_rect = {.x = 0, .y = 0, .width = screen_width, .height = screen_height};
    VC_RECT_T src_rect = {.x = 0, .y = 0, .width = screen_width<<16, .height = screen_height<<16};

    dispman_display = vc_dispmanx_display_open(0 /* LCD */);
    dispman_update = vc_dispmanx_update_start(0);

    dispman_element = vc_dispmanx_element_add (dispman_update, dispman_display,
                                               0/*layer*/, &dst_rect, 0/*src*/,
                                               &src_rect, DISPMANX_PROTECTION_NONE, 0 /*alpha*/, 0/*clamp*/, 0/*transform*/);

    nativewindow.element = dispman_element;
    nativewindow.width = screen_width;
    nativewindow.height = screen_height;
    vc_dispmanx_update_submit_sync(dispman_update);

    surface = eglCreateWindowSurface(display, config, &nativewindow, NULL);
    if(surface == EGL_NO_SURFACE)
    {
        fprintf(stderr, "eglCreateWindowSurface returned ELG_NO_SURFACE.  "
                "Try closing other OpenGL programs.\n");
        exit(1);
    }

    // connect the context to the surface
    result = eglMakeCurrent(display, surface, surface, context);
    assert(EGL_FALSE != result);

    glClearColor(0, 0, 0, 0.5);   // set background colors
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear buffers
    glShadeModel(GL_FLAT);

    // Enable back face culling.
    glEnable(GL_CULL_FACE);
}

// Description: Sets the OpenGL|ES model to default values
static void init_projection()
{
    float nearp = 1, farp = 500.0f, hht, hwd;

    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

    glViewport(0, 0, (GLsizei)screen_width, (GLsizei)screen_height);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    hht = nearp * tan(45.0 / 2.0 / 180.0 * M_PI);
    hwd = hht * screen_width / screen_height;

    glFrustumf(-hwd, hwd, -hht, hht, nearp, farp);
}

static void init_textures(void)
{
    glEnable(GL_TEXTURE_2D);
    model_board_init();
}

static void redraw_scene()
{
    // Start with a clear screen
    glClear(GL_COLOR_BUFFER_BIT);

    // Move the camera back so we can see the board.
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(0, 0, -30);

    // Convert screen coords (x=right y=up z=out) to ground coords (x=east y=north z=up).
    glRotatef(-90, 1, 0, 0);
    glRotatef(screen_orientation, 0, 0, 1);<commit_msg>Made it so the console text does not get brighter when you view it through a hole in the board.<commit_after>#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <assert.h>
#include <unistd.h>

#include <bcm_host.h>

#include <GLES/gl.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>

#include "model_board/model_board.h"

/* OpenGL rotation matrix that converts ground coordinates
 * (x=easy, y=north, z=up) into board coordinates.  It is
 * column-major so do matrix[COL][ROW]. */
float matrix[4][4];

// Acceleration vector in units of g (9.8 m/s^2).
float acceleration[3];

// Magnetic field vector where each component is approximately between -1 and 1.
float magnetic_field[3];

// 0 = Screen faces south, 90 = West, 180 = North, 270 = East
// TODO: read screen_orientation from environment
float screen_orientation = 0;

uint32_t screen_width, screen_height;
EGLDisplay display;
EGLSurface surface;
EGLContext context;

// Sets the display, OpenGL|ES context and screen stuff
static void init_opengl(void)
{
    EGLBoolean result;
    EGLint num_config;

    static EGL_DISPMANX_WINDOW_T nativewindow;

    DISPMANX_ELEMENT_HANDLE_T dispman_element;
    DISPMANX_DISPLAY_HANDLE_T dispman_display;
    DISPMANX_UPDATE_HANDLE_T dispman_update;

    static const EGLint attribute_list[] =
        {
            EGL_RED_SIZE, 8,
            EGL_GREEN_SIZE, 8,
            EGL_BLUE_SIZE, 8,
            EGL_ALPHA_SIZE, 8,
            EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
            EGL_NONE
        };
   
    EGLConfig config;

    // get an EGL display connection
    display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    assert(display!=EGL_NO_DISPLAY);

    // initialize the EGL display connection
    result = eglInitialize(display, NULL, NULL);
    assert(EGL_FALSE != result);

    // get an appropriate EGL frame buffer configuration
    result = eglChooseConfig(display, attribute_list, &config, 1, &num_config);
    assert(EGL_FALSE != result);

    // create an EGL rendering context
    context = eglCreateContext(display, config, EGL_NO_CONTEXT, NULL);
    assert(context!=EGL_NO_CONTEXT);

    // create an EGL window surface
    int32_t success = graphics_get_display_size(0 /* LCD */, &screen_width, &screen_height);
    assert( success >= 0 );

    VC_RECT_T dst_rect = {.x = 0, .y = 0, .width = screen_width, .height = screen_height};
    VC_RECT_T src_rect = {.x = 0, .y = 0, .width = screen_width<<16, .height = screen_height<<16};

    dispman_display = vc_dispmanx_display_open(0 /* LCD */);
    dispman_update = vc_dispmanx_update_start(0);

    dispman_element = vc_dispmanx_element_add (dispman_update, dispman_display,
                                               0/*layer*/, &dst_rect, 0/*src*/,
                                               &src_rect, DISPMANX_PROTECTION_NONE, 0 /*alpha*/, 0/*clamp*/, 0/*transform*/);

    nativewindow.element = dispman_element;
    nativewindow.width = screen_width;
    nativewindow.height = screen_height;
    vc_dispmanx_update_submit_sync(dispman_update);

    surface = eglCreateWindowSurface(display, config, &nativewindow, NULL);
    if(surface == EGL_NO_SURFACE)
    {
        fprintf(stderr, "eglCreateWindowSurface returned ELG_NO_SURFACE.  "
                "Try closing other OpenGL programs.\n");
        exit(1);
    }

    // connect the context to the surface
    result = eglMakeCurrent(display, surface, surface, context);
    assert(EGL_FALSE != result);

    glClearColor(0, 0, 0, 0.5);   // set background colors
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear buffers
    glShadeModel(GL_FLAT);

    // Enable back face culling.
    glEnable(GL_CULL_FACE);
}

// Description: Sets the OpenGL|ES model to default values
static void init_projection()
{
    float nearp = 1, farp = 500.0f, hht, hwd;

    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

    glViewport(0, 0, (GLsizei)screen_width, (GLsizei)screen_height);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    hht = nearp * tan(45.0 / 2.0 / 180.0 * M_PI);
    hwd = hht * screen_width / screen_height;

    glFrustumf(-hwd, hwd, -hht, hht, nearp, farp);
}

static void init_textures(void)
{
    // Enable alpha blending so what we see through transparent
    // parts of the model is the same as the background.
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    glEnable(GL_TEXTURE_2D);
    model_board_init();
}

static void redraw_scene()
{
    // Start with a clear screen
    glClear(GL_COLOR_BUFFER_BIT);

    // Move the camera back so we can see the board.
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(0, 0, -30);

    // Convert screen coords (x=right y=up z=out) to ground coords (x=east y=north z=up).
    glRotatef(-90, 1, 0, 0);
    glRotatef(screen_orientation, 0, 0, 1);
{'fraction_non_alphanumeric': 0.10663129973474801, 'fraction_numerical': 0.016976127320954906, 'mean_word_length': 3.2516914749661705, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '383907', 'n_tokens_mistral': 3368, 'n_tokens_neox': 3171, 'n_words': 794}