Ejemplo n.º 1
0
/******************************************************************************\
 Pre-renders the extra rotations of the tile mask and the terrain tile sheets.
 This function will generate tile textures 1-3.
\******************************************************************************/
static void prerender_tiles(void)
{
        r_texture_t *blend_mask, *rotated_mask, *masked_terrain;
        int i, x, y;

        blend_mask = R_texture_load("models/globe/blend_mask.png", FALSE);
        if (!blend_mask || !r_terrain_tex)
                C_error("Failed to load essential prerendering assets");

        /* Render the blend mask to tile size */
        R_texture_select(blend_mask);
        setup_tile_uv_mask();
        render_tile(0, 0);
        R_texture_free(blend_mask);
        blend_mask = save_buffer((int)tile.x, (int)tile.y);
        R_texture_upload(blend_mask);
        finish_buffer();

        rotated_mask = NULL;
        for (i = 0; i < 3; i++) {

                /* Render the blend mask at tile size and orientation */
                R_texture_select(blend_mask);
                setup_tile_uv(i, -1, -1, -1);
                for (y = 0; y < R_TILE_SHEET_H; y++)
                        for (x = 0; x < R_TILE_SHEET_W; x++)
                                render_tile(x, y);
                rotated_mask = save_buffer((int)sheet.x, (int)sheet.y);
                R_texture_upload(rotated_mask);
                finish_buffer();

                /* Render the tiles at this orientation */
                R_texture_select(r_terrain_tex);
                for (y = 0; y < R_TILE_SHEET_H; y++)
                        for (x = 0; x < R_TILE_SHEET_W; x++) {
                                setup_tile_uv(0, i, x, y);
                                render_tile(x, y);
                        }

                /* Read the terrain back in and mask it */
                masked_terrain = save_buffer((int)sheet.x, (int)sheet.y);
                R_surface_mask(masked_terrain->surface, rotated_mask->surface);
                R_texture_free(rotated_mask);
                finish_buffer();

                /* Render the masked terrain on top of the terrain texture
                   and read it back in to replace the old terrain texture */
                R_texture_render(r_terrain_tex, 0, 0);
                R_texture_upload(masked_terrain);
                R_texture_render(masked_terrain, 0, 0);
                if (r_test_prerender.value.n)
                        R_texture_render(masked_terrain, (int)sheet.x, 0);
                R_texture_free(masked_terrain);
                R_texture_free(r_terrain_tex);
                r_terrain_tex = save_buffer((int)sheet.x, (int)sheet.y);
                R_texture_upload(r_terrain_tex);
                finish_buffer();
        }
        R_texture_free(blend_mask);
}
Ejemplo n.º 2
0
/** return length of buffer used */
int PROCto_buffer( Procedure e, char * buffer, int length ) {
    if( prep_buffer( buffer, length ) ) {
        return -1;
    }
    PROC_out( e, 0 );
    return( finish_buffer() );
}
Ejemplo n.º 3
0
void Projector::_show_buffer (char* output)
{   //effects using accumulation buffer
    //reverse colors
    if (reverse_colors) {
        glAccum(GL_MULT,    -1.0f);
        glAccum(GL_ADD,     1.0f);
    }

    //increase contrast & invert colors
    if (high_contrast) {
        glAccum(GL_ADD,     -0.25f);
        glAccum(GL_RETURN,  2.0f);
        glAccum(GL_ADD,     0.25f);
    } else {
        glAccum(GL_RETURN,  1.0f);
    }

    //draw image as soon as possible
#ifdef CAPTURE
    if (output) _capture_little(output);
#endif
    finish_buffer();

    //restore colors
    if (reverse_colors) {
        glAccum(GL_MULT,    -1.0f);
        glAccum(GL_ADD,     1.0f);
    }
}
Ejemplo n.º 4
0
/** return length of buffer used */
int RULEto_buffer( Rule e, char * buffer, int length ) {
    if( prep_buffer( buffer, length ) ) {
        return -1;
    }
    RULE_out( e, 0 );
    return( finish_buffer() );
}
Ejemplo n.º 5
0
/* return length of buffer used */
int STMTto_buffer( Statement s, char * buffer, int length ) {
    if( prep_buffer( buffer, length ) ) {
        return -1;
    }
    STMT_out( s, 0 );
    return( finish_buffer() );
}
Ejemplo n.º 6
0
void KineticLogger_LogPrintf(int log_level, const char* format, ...)
{
    if (KineticLoggerHandle == NULL) {
        return;
    }
    if (format == NULL || !is_level_enabled(log_level)) {
        return;
    }

    char* buffer = NULL;
    buffer = get_buffer();

    /* Add timestamp prefix */
    struct timeval tv;
    if (0 == gettimeofday(&tv, NULL)) {
        fprintf(KineticLoggerHandle, "%08lld.%06lld  ",
            (long long)tv.tv_sec, (long long)tv.tv_usec);
    }
    
    va_list arg_ptr;
    va_start(arg_ptr, format);
    int len = vsnprintf(buffer, BUFFER_MAX_STRLEN, format, arg_ptr);
    va_end(arg_ptr);

    if (len > BUFFER_MAX_STRLEN) {
        Buffer[BUFFER_MAX_STRLEN] = '\0';
    }
    strcat(Buffer, "\n");
    
    finish_buffer();
}
Ejemplo n.º 7
0
void CaptureMenu::_call (int N)
{
    logger.debug() << "selected choice "  << N |0;

    switch (N) {
        case 0: projector->toggle_quality();    return;
        case 1: projector->set_color(false);    return;
        case 2: projector->set_color(true);     return;
        case 3: return;
        default: break;
    }

    //draw waiting dialog
    const char* message = projector->get_quality()
        ? "saving high-quality image"
        : "saving low-quality image";
    Menu* dialog = new Menu(message, Helv18, 0.5, 0.5, false);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    finish_buffer();

    switch (N) {
        case 4: capture(1,1);           break;
        case 5: capture(2,2);           break;
        case 6: capture(3,3);           break;
        case 7: capture(4,4);           break;
#if (CAPTURE > 4)
        case 8: capture(6,6);           break;
        case 9: capture(8,8);          break;
        case 10: capture(12,12);        break;
        case 11: capture(16,16);        break;
        case 12: capture(24,24);        break;
#endif
    }
    dialog->close();
}
Ejemplo n.º 8
0
/** return length of buffer used */
int SCHEMAref_to_buffer( Schema s, char * buffer, int length ) {
    if( prep_buffer( buffer, length ) ) {
        return -1;
    }
    REFout( s->u.schema->usedict, s->u.schema->use_schemas, "USE", 0 );
    REFout( s->u.schema->refdict, s->u.schema->ref_schemas, "REFERENCE", 0 );
    return( finish_buffer() );
}
Ejemplo n.º 9
0
void ModelMenu::_call (int N)
{
    if (0 <= N and N < m_size) {
        //open waiting dialog
        Menu* dialog = new Menu("building model...", Helv18, 0.5, 0.5, false);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        finish_buffer();

        //build model
        int edges = m_edges ? m_edges[N] : 1111;
        int faces = m_faces ? m_faces[N] : 111111;
        int weights = m_weights ? m_weights[N] : 1111;
        Polytope::select(m_nums[N], edges, faces, weights);
        update_title();

        //close dialog
        dialog->close();
    }
}
Ejemplo n.º 10
0
void Projector::display (char* output)
{
    if (_update_needed) _update();

    if (not (paused and motion_blur)) {
        if (motion_blur)    _set_rand_tilt();
        else                _set_tilt(0,0);
        _draw();

        bool effects = motion_blur or reverse_colors or high_contrast;
        if (effects) { //slower, using accum buffer
            _draw_buffer();
            _show_buffer(output);
        } else { //faster, no accum buffer
#ifdef CAPTURE
            if (output) _capture_little(output);
#endif
            finish_buffer();
        }
    } else { //draw a long-exposure image

        //LATER this ignores color inversion, contrast, etc.
        const int N = NUM_STILL_FRAMES / (high_quality ? 1 : 4);
        const float part = 1.0f / N;
        glClear(GL_ACCUM_BUFFER_BIT);
        for (int n=0; n<N; ++n) {
            _set_unif_tilt(n,N);
            _draw();
            glAccum(GL_ACCUM, part);

            //watch image develop
            //logger.debug() << "  frame " << n+1 << " / " << N |0;
            glAccum(GL_RETURN, 1.0f);
            if (n == N-1) _show_buffer(output);
            else          _show_buffer();
        }
    }
}
Ejemplo n.º 11
0
/******************************************************************************\
 Pre-renders tiles for transition between base tile types.
\******************************************************************************/
static void prerender_transitions(void)
{
        r_texture_t *trans_mask, *inverted_mask, *large_mask, *masked_terrain;
        int x, y, tiles_a[] = {0, 1, 1, 2}, tiles_b[] = {1, 0, 2, 1};

        trans_mask = R_texture_load("models/globe/trans_mask.png", FALSE);
        if (!trans_mask || !r_terrain_tex)
                C_error("Failed to load essential prerendering assets");

        /* Render an inverted version of the mask */
        inverted_mask = R_texture_clone(trans_mask);
        R_surface_flip_v(inverted_mask->surface);
        R_surface_invert(inverted_mask->surface, TRUE, FALSE);
        R_texture_upload(inverted_mask);
        R_texture_select(inverted_mask);
        setup_tile_uv_mask();
        render_tile(0, 0);
        R_texture_free(inverted_mask);
        inverted_mask = save_buffer((int)tile.x, (int)tile.y);
        R_texture_upload(inverted_mask);
        finish_buffer();

        /* Render the transition mask to tile size */
        R_texture_select(trans_mask);
        setup_tile_uv_mask();
        render_tile(0, 0);
        R_texture_free(trans_mask);
        trans_mask = save_buffer((int)tile.x, (int)tile.y);
        R_texture_upload(trans_mask);
        finish_buffer();

        /* Render the transition mask tile sheet */
        for (y = 0; y < R_T_BASES - 1; y++) {
                R_texture_select(trans_mask);
                for (x = 0; x < 3; x++) {
                        setup_tile_uv(x, -1, -1, -1);
                        render_tile(x, y + 1);
                }
                R_texture_select(inverted_mask);
                for (x = 3; x < 6; x++) {
                        setup_tile_uv(x - 3, -1, -1, -1);
                        render_tile(x, y + 1);
                }
        }
        large_mask = save_buffer((int)sheet.x, (int)sheet.y);
        R_texture_free(trans_mask);
        R_texture_free(inverted_mask);
        finish_buffer();

        /* Render the masked layer of the terrain and read it back in */
        R_texture_select(r_terrain_tex);
        for (y = 0; y < R_T_BASES - 1; y++)
                for (x = 0; x < 3; x++) {
                        setup_tile_uv(0, -1, tiles_b[2 * y], 0);
                        render_tile(x, y + 1);
                        setup_tile_uv(0, -1, tiles_b[2 * y + 1], 0);
                        render_tile(x + 3, y + 1);
                }
        masked_terrain = save_buffer((int)sheet.x, (int)sheet.y);
        R_surface_mask(masked_terrain->surface, large_mask->surface);
        R_texture_free(large_mask);
        R_texture_upload(masked_terrain);
        finish_buffer();
        if (r_test_prerender.value.n)
                R_texture_render(masked_terrain, (int)sheet.x, 0);

        /* Render the base layer of the terrain */
        R_texture_render(r_terrain_tex, 0, 0);
        R_texture_select(r_terrain_tex);
        for (y = 0; y < R_T_BASES - 1; y++)
                for (x = 0; x < 3; x++) {
                        setup_tile_uv(0, -1, tiles_a[2 * y], 0);
                        render_tile(x, y + 1);
                        setup_tile_uv(0, -1, tiles_a[2 * y + 1], 0);
                        render_tile(x + 3, y + 1);
                }

        /* Render the masked terrain over the tile sheet and read it back in */
        R_texture_render(masked_terrain, 0, 0);
        R_texture_free(masked_terrain);
        R_texture_free(r_terrain_tex);
        r_terrain_tex = save_buffer((int)sheet.x, (int)sheet.y);
        r_terrain_tex->mipmaps = TRUE;
        R_texture_upload(r_terrain_tex);
        finish_buffer();
}