Exemplo n.º 1
0
void init(float winwidth, float winheight, float pixratio)
{
    const Vector4 bgcolor = {0.937, 0.937, 0.93, 1.00};
    parg_state_clearcolor(bgcolor);
    parg_state_cullfaces(1);
    parg_state_depthtest(1);
    parg_shader_load_from_asset(SHADER_SIMPLE);

    int* rawdata;
    colorbuf = parg_buffer_slurp_asset(TEXTURE_COLOR, (void*) &rawdata);
    int width = *rawdata++;
    int height = *rawdata++;
    int ncomps = *rawdata++;
    parg_buffer_unlock(colorbuf);

    colortex =
        parg_texture_from_u8(colorbuf, width, height, ncomps, 3 * sizeof(int));
    graybuf = parg_buffer_from_asset(BIN_ISLAND);
    graytex = parg_texture_from_fp32(graybuf, IMGWIDTH, IMGHEIGHT, 1, 0);
    const float h = 1.5f;
    const float w = h * winwidth / winheight;
    const float znear = 10;
    const float zfar = 90;
    projection = M4MakeFrustum(-w, w, -h, h, znear, zfar);
    Point3 eye = {0, -50, 50};
    Point3 target = {0, 0, 0};
    Vector3 up = {0, 1, 0};
    view = M4MakeLookAt(eye, target, up);
    rectmesh = parg_mesh_rectangle(20, 20);
}
Exemplo n.º 2
0
void init(float winwidth, float winheight, float pixratio)
{
    parg_state_clearcolor((Vector4){gray, gray, gray, 1});
    parg_state_depthtest(0);
    parg_state_cullfaces(0);
    parg_shader_load_from_asset(SHADER_SIMPLE);
    float worldheight = worldwidth * sqrt(0.75);
    parg_zcam_init(worldwidth, worldheight, fovy);
    trimesh = parg_mesh_sierpinski(worldwidth, 10);
    printf("%d triangles\n", parg_mesh_ntriangles(trimesh));
}
Exemplo n.º 3
0
void init(float winwidth, float winheight, float pixratio)
{
    parg_state_clearcolor((Vector4){gray, gray, gray, 1});
    parg_state_depthtest(0);
    parg_state_cullfaces(0);
    parg_shader_load_from_asset(SHADER_ZOOMING);
    palmstexture = parg_texture_from_asset(TEXTURE_PALMS);
    int imgwidth, imgheight;
    parg_texture_info(palmstexture, &imgwidth, &imgheight);
    float worldheight = worldwidth * imgheight / imgwidth;
    parg_zcam_init(worldwidth, worldheight, fovy);
    rectmesh = parg_mesh_rectangle(worldwidth, worldheight);
}
Exemplo n.º 4
0
void init(float winwidth, float winheight, float pixratio)
{
    resolution = pixratio * winwidth;
    par_shapes_mesh* shape;
    shape = par_shapes_create_cylinder(30, 3);
    float axis[3] = {1, 0, 0};
    par_shapes_rotate(shape, PARG_PI * 0.5, axis);
    cylinder = parg_mesh_from_shape(shape);
    par_shapes_free_mesh(shape);

    shape = par_shapes_create_plane(3, 3);
    par_shapes_scale(shape, 4, 4, 1);
    par_shapes_translate(shape, -2, -2, -1);
    backdrop = parg_mesh_from_shape(shape);
    par_shapes_free_mesh(shape);

    kleingeo = parg_mesh_from_asset(M_KLEIN);
    parg_mesh_send_to_gpu(kleingeo);

    kleintex = parg_texture_from_asset_linear(T_KLEIN);
    abstract = parg_texture_from_asset(T_ABSTRACT);
    logo = parg_texture_from_asset(T_LOGO);
    rust = parg_texture_from_asset(T_RUST);
    billboard = parg_mesh_rectangle(1, 1);
    reflection = parg_framebuffer_create_empty(
        512, 512, PARG_FBO_LINEAR | PARG_FBO_ALPHA | PARG_FBO_DEPTH);

    const Vector4 transparent = {0, 0, 0, 0};
    parg_state_clearcolor(transparent);

    parg_state_depthtest(1);
    parg_state_cullfaces(1);
    parg_shader_load_from_asset(S_SIMPLE);
    const float h = 1.0f;
    const float w = h * winwidth / winheight;
    const float znear = 4;
    const float zfar = 20;
    projection = M4MakeFrustum(-w, w, -h, h, znear, zfar);
    Point3 eye = {0, 1.8, 5};
    Point3 target = {0, 0.7, 0};
    Vector3 up = {0, 1, 0};
    view = M4MakeLookAt(eye, target, up);
    model = M4MakeIdentity();
}
Exemplo n.º 5
0
Arquivo: ztex.c Projeto: prideout/parg
void init(float winwidth, float winheight, float pixratio)
{
    printf(
        "Spacebar to toggle texture modes.\n"
        "D to toggle auto-zooming demo mode.\n"
        "G to toggle the slippy map grid.\n");
    parg_state_clearcolor((Vector4){0.43, 0.61, 0.8, 1});
    parg_state_cullfaces(1);
    parg_state_depthtest(0);
    parg_shader_load_from_asset(SHADER_DEFAULT);
    parg_zcam_init(1, 1, fovy);
    parg_zcam_set_position(0, 0, STARTZ);
    ocean_texture = parg_texture_from_asset(TEXTURE_OCEAN);
    paper_texture = parg_texture_from_asset(TEXTURE_PAPER);

    // Decode the europe image.
    int* rawdata;
    parg_buffer* colorbuf =
        parg_buffer_slurp_asset(TEXTURE_EUROPE, (void*) &rawdata);
    int width = *rawdata++;
    int height = *rawdata++;
    int ncomps = *rawdata++;
    parg_texture_fliprows(rawdata, width * ncomps, height);

    // Sample the ocean color from one corner of the image.
    int ocean_color = rawdata[0];

    // Perform marching squares and generate a mesh.
    par_msquares_meshlist* mlist =
        par_msquares_color((parg_byte*) rawdata, width, height, 16, ocean_color,
            4, PAR_MSQUARES_SWIZZLE | PAR_MSQUARES_DUAL | PAR_MSQUARES_HEIGHTS |
            PAR_MSQUARES_SIMPLIFY);
    par_msquares_mesh const* mesh;
    mesh = par_msquares_get_mesh(mlist, 0);
    landmass_mesh = parg_mesh_create(
        mesh->points, mesh->npoints, mesh->triangles, mesh->ntriangles);
    mesh = par_msquares_get_mesh(mlist, 1);
    ocean_mesh = parg_mesh_create(
        mesh->points, mesh->npoints, mesh->triangles, mesh->ntriangles);
    parg_buffer_unlock(colorbuf);
    par_msquares_free(mlist);
}
Exemplo n.º 6
0
void draw()
{
    Matrix4 modelview = view;
    Matrix4 mvp = M4Mul(projection, view);

    // Draw the background.
    parg_draw_clear();
    parg_shader_bind(P_TEXTURE);
    parg_texture_bind(abstract, 0);
    parg_uniform_matrix4f(U_MVP, &mvp);
    parg_varray_enable(
        parg_mesh_coord(backdrop), A_POSITION, 3, PARG_FLOAT, 0, 0);
    parg_varray_enable(parg_mesh_uv(backdrop), A_TEXCOORD, 2, PARG_FLOAT, 0, 0);
    parg_varray_bind(parg_mesh_index(backdrop));
    parg_draw_triangles_u16(0, parg_mesh_ntriangles(backdrop));
    parg_varray_disable(A_TEXCOORD);

    // Prep for the scene.
    modelview = M4Mul(view, model);
    mvp = M4Mul(projection, modelview);
    parg_texture_bind(kleintex, 0);
    parg_uniform_matrix4f(U_MVP, &mvp);
    parg_varray_enable(
        parg_mesh_coord(kleingeo), A_POSITION, 3, PARG_FLOAT, 0, 0);
    parg_varray_enable(parg_mesh_uv(kleingeo), A_TEXCOORD, 2, PARG_FLOAT, 0, 0);
    parg_varray_bind(parg_mesh_index(kleingeo));

    // Draw each chart of the Klein bottle, skipping the podium disk.
    int start = 0;
    for (int i = 0; i < NCHARTS; i++) {
        if (i != PODIUM_CHART) {
            parg_draw_triangles_u16(start, CHARTS[i]);
        }
        start += CHARTS[i];
    }

    // Draw it again for the reflection.
    parg_framebuffer_pushfbo(reflection, 0);
    parg_draw_clear();
    Matrix4 invert = M4MakeScale((Vector3){1, -1, 1});
    parg_state_cullfaces(0);
    Matrix4 flipped = M4Mul(model, invert);
    mvp = M4Mul(projection, M4Mul(view, flipped));
    parg_uniform_matrix4f(U_MVP, &mvp);
    start = 0;
    for (int i = 0; i < NCHARTS; i++) {
        if (i != PODIUM_CHART) {
            parg_draw_triangles_u16(start, CHARTS[i]);
        }
        start += CHARTS[i];
    }
    mvp = M4Mul(projection, modelview);
    parg_state_cullfaces(1);
    parg_framebuffer_popfbo();

    // Draw the podium.
    parg_shader_bind(P_PODIUM);
    parg_texture_bind(rust, 1);
    parg_framebuffer_bindtex(reflection, 2);
    parg_uniform1i(U_RUST, 1);
    parg_uniform1i(U_REFLECTION, 2);
    parg_uniform2f(U_RESOLUTION, resolution, resolution);
    parg_uniform_matrix4f(U_MVP, &mvp);
    start = 0;
    for (int i = 0; i < NCHARTS; i++) {
        if (i == PODIUM_CHART) {
            parg_draw_triangles_u16(start, CHARTS[i]);
        }
        start += CHARTS[i];
    }
    parg_varray_disable(A_TEXCOORD);

// Draw the walls of the cylinder.
#if CYLINDER
    parg_shader_bind(P_CYLINDER);
    parg_uniform_matrix4f(U_MVP, &mvp);
    parg_varray_enable(
        parg_mesh_coord(cylinder), A_POSITION, 3, PARG_FLOAT, 0, 0);
    parg_varray_bind(parg_mesh_index(cylinder));
    parg_draw_triangles_u16(0, parg_mesh_ntriangles(cylinder));
#endif

    // Draw the logo billboard.
    parg_state_blending(1);
    parg_state_depthtest(0);
    parg_shader_bind(P_LOGO);
    parg_uniform_matrix4f(U_MVP, &mvp);
    parg_texture_bind(logo, 0);
    parg_varray_enable(
        parg_mesh_coord(billboard), A_POSITION, 2, PARG_FLOAT, 0, 0);
    parg_varray_enable(
        parg_mesh_coord(billboard), A_TEXCOORD, 2, PARG_FLOAT, 0, 0);
    parg_draw_one_quad();
    parg_varray_disable(A_TEXCOORD);
    parg_state_blending(0);
    parg_state_depthtest(1);
}