<commit_before>#include "raster.h"

rasterPosT rPos = {0, 0, 0};
viewportT viewport = {0, 0, 0, 0};
GLubyte *raster = NULL;

/* raster engine:
    we render pixels to memory somewhere
    until someone else wants to use the framebuffer
    then we throw 'em quickly into a texture, render to the whole screen
    then let the other function do their thing
*/

typedef int (*GLUPROJECTPTR)(GLdouble, GLdouble, GLdouble,
                             const GLdouble *,
                             const GLdouble *,
                             const GLint *,
                             GLdouble *, GLdouble *, GLdouble *);

void glRasterPos3f(GLfloat x, GLfloat y, GLfloat z) {
    static GLUPROJECTPTR gluProject;
    if (gluProject == NULL) {
        void *glu = dlopen("libGLU.so.1", RTLD_LOCAL | RTLD_LAZY);
        gluProject = (GLUPROJECTPTR)dlsym(glu, "gluProject");
    }
    if (gluProject) {
        GLdouble model[16], proj[16], out[3];
        glGetDoublev(GL_MODELVIEW_MATRIX, model);
        glGetDoublev(GL_PROJECTION_MATRIX, proj);
        gluProject(x, y, z,
                   model, proj, (const GLint *)&viewport,
                   out, out+1, out+2);
        rPos.x = out[0];
        rPos.y = out[1];
        rPos.z = out[2];
    } else {
        rPos.x = x;
        rPos.y = y;
        rPos.z = z;
    }
}

void glViewport(GLint x, GLint y, GLsizei width, GLsizei height) {
    LOAD_GLES(void, glViewport, GLint, GLint, GLsizei, GLsizei);
    if (raster) {
        render_raster();
    }
    gles_glViewport(x, y, width, height);
    viewport.x = x;
    viewport.y = y;
    viewport.width = width;
    viewport.height = height;
}

void init_raster() {
    if (!viewport.width || !viewport.height) {
        glGetIntegerv(GL_VIEWPORT, (GLint *)&viewport);
    }
    if (!raster)
        raster = (GLubyte *)malloc(4 * viewport.width * viewport.height * sizeof(GLubyte));
}

void glBitmap(GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig,
              GLfloat xmove, GLfloat ymove, const GLubyte *bitmap) {
    // TODO: shouldn't be drawn if the raster pos is outside the viewport?
    // TODO: negative width/height mirrors bitmap?
    if (!width && !height) {
        rPos.x += xmove;
        rPos.y -= ymove;
        return;
    }<commit_msg>gluProject for raster pos just breaks things<commit_after>#include "raster.h"

rasterPosT rPos = {0, 0, 0};
viewportT viewport = {0, 0, 0, 0};
GLubyte *raster = NULL;

/* raster engine:
    we render pixels to memory somewhere
    until someone else wants to use the framebuffer
    then we throw 'em quickly into a texture, render to the whole screen
    then let the other function do their thing
*/

void glRasterPos3f(GLfloat x, GLfloat y, GLfloat z) {
    rPos.x = x;
    rPos.y = y;
    rPos.z = z;
}

void glViewport(GLint x, GLint y, GLsizei width, GLsizei height) {
    LOAD_GLES(void, glViewport, GLint, GLint, GLsizei, GLsizei);
    if (raster) {
        render_raster();
    }
    gles_glViewport(x, y, width, height);
    viewport.x = x;
    viewport.y = y;
    viewport.width = width;
    viewport.height = height;
}

void init_raster() {
    if (!viewport.width || !viewport.height) {
        glGetIntegerv(GL_VIEWPORT, (GLint *)&viewport);
    }
    if (!raster)
        raster = (GLubyte *)malloc(4 * viewport.width * viewport.height * sizeof(GLubyte));
}

void glBitmap(GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig,
              GLfloat xmove, GLfloat ymove, const GLubyte *bitmap) {
    // TODO: shouldn't be drawn if the raster pos is outside the viewport?
    // TODO: negative width/height mirrors bitmap?
    if (!width && !height) {
        rPos.x += xmove;
        rPos.y -= ymove;
        return;
    }
{'fraction_non_alphanumeric': 0.11391724879097259, 'fraction_numerical': 0.007791509940891994, 'mean_word_length': 2.4472222222222224, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4353462', 'n_tokens_mistral': 1311, 'n_tokens_neox': 1285, 'n_words': 368}