<commit_before>#include <par.h>
#include <parwin.h>
#include <assert.h>

#define TOKEN_TABLE(F)          \
    F(P_SIMPLE, "p_simple")     \
    F(A_POSITION, "a_position") \
    F(A_TEXCOORD, "a_texcoord") \
    F(U_MVP, "u_mvp")

TOKEN_TABLE(PAR_TOKEN_DECLARE);

Matrix4 projection;
Matrix4 model;
Matrix4 view;
par_mesh* rectmesh;
par_texture* palmstexture;

void init(float winwidth, float winheight, float pixratio)
{
    float gray = 0.8;
    par_state_clearcolor((Vector4){gray, gray, gray, 1});
    par_state_depthtest(0);
    par_state_cullfaces(0);
    par_shader_load_from_asset("zooming.glsl");

    const float fovy = 16 * PAR_TWOPI / 180;
    const float aspect = (float) winwidth / winheight;
    const float znear = 0.1;
    const float zfar = 300;
    projection = M4MakePerspective(fovy, aspect, znear, zfar);
    Point3 eye = {0, 0, 4};
    Point3 target = {0, 0, 0};
    Vector3 up = {0, 1, 0};
    view = M4MakeLookAt(eye, target, up);
    model = M4MakeIdentity();

    palmstexture = par_texture_from_asset("arecaceae.png");
    int w, h;
    par_texture_info(palmstexture, &w, &h);
    rectmesh = par_mesh_create_rectangle(2, 2.0 * h / w);
}

int draw()
{
    Matrix4 modelview = M4Mul(view, model);
    Matrix4 mvp = M4Mul(projection, modelview);
    par_draw_clear();
    par_shader_bind(P_SIMPLE);
    par_texture_bind(palmstexture, 0);
    par_uniform_matrix4f(U_MVP, &mvp);
    par_varray_enable(par_mesh_coord(rectmesh), A_POSITION, 2, PAR_FLOAT, 0, 0);
    par_varray_enable(par_mesh_uv(rectmesh), A_TEXCOORD, 2, PAR_FLOAT, 0, 0);
    par_draw_one_quad();
    return 1;
}

void tick(float winwidth, float winheight, float pixratio, float seconds)
{
    const float RADIANS_PER_SECOND = 1.57;
    float theta = seconds * RADIANS_PER_SECOND;
    model = M4MakeRotationY(theta);
}

void dispose()
{
    par_shader_free(P_SIMPLE);
    par_mesh_free(rectmesh);
    par_texture_free(palmstexture);
}

int main(int argc, char* argv[])
{<commit_msg>Fit camera to window.<commit_after>#include <par.h>
#include <parwin.h>
#include <assert.h>

#define TOKEN_TABLE(F)          \
    F(P_SIMPLE, "p_simple")     \
    F(A_POSITION, "a_position") \
    F(A_TEXCOORD, "a_texcoord") \
    F(U_MVP, "u_mvp")

TOKEN_TABLE(PAR_TOKEN_DECLARE);

Matrix4 projection;
Point3 camerapos;
par_mesh* rectmesh;
par_texture* palmstexture;

const float gray = 0.8;
const float fovy = 16 * PAR_TWOPI / 180;
const float worldwidth = 6000;

void init(float winwidth, float winheight, float pixratio)
{
    par_state_clearcolor((Vector4){gray, gray, gray, 1});
    par_state_depthtest(0);
    par_state_cullfaces(0);
    par_shader_load_from_asset("zooming.glsl");
    palmstexture = par_texture_from_asset("arecaceae.png");
    int imgwidth, imgheight;
    par_texture_info(palmstexture, &imgwidth, &imgheight);
    float worldheight = worldwidth * imgheight / imgwidth;
    rectmesh = par_mesh_create_rectangle(worldwidth, worldheight);
    const float aspect = (float) winwidth / winheight;
    float cameraheight = 0.5 * worldheight / tan(fovy * 0.5);
    camerapos = (Point3){0, 0, cameraheight};
    const float znear = 1.0;
    const float zfar = cameraheight * 1.1;
    projection = M4MakePerspective(fovy, aspect, znear, zfar);
}

int draw()
{
    Point3 target = {camerapos.x, camerapos.y, 0};
    Vector3 up = {0, 1, 0};
    Matrix4 view = M4MakeLookAt(camerapos, target, up);
    Matrix4 model = M4MakeIdentity();
    Matrix4 modelview = M4Mul(view, model);
    Matrix4 mvp = M4Mul(projection, modelview);
    par_draw_clear();
    par_shader_bind(P_SIMPLE);
    par_texture_bind(palmstexture, 0);
    par_uniform_matrix4f(U_MVP, &mvp);
    par_varray_enable(par_mesh_coord(rectmesh), A_POSITION, 2, PAR_FLOAT, 0, 0);
    par_varray_enable(par_mesh_uv(rectmesh), A_TEXCOORD, 2, PAR_FLOAT, 0, 0);
    par_draw_one_quad();
    return 1;
}

void tick(float winwidth, float winheight, float pixratio, float seconds) {}

void dispose()
{
    par_shader_free(P_SIMPLE);
    par_mesh_free(rectmesh);
    par_texture_free(palmstexture);
}

int main(int argc, char* argv[])
{
{'fraction_non_alphanumeric': 0.12266928361138371, 'fraction_numerical': 0.026005888125613347, 'mean_word_length': 4.160759493670886, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2796612', 'n_tokens_mistral': 1646, 'n_tokens_neox': 1580, 'n_words': 333}