/*
          __
         / /_______________  ____  ___
        / __/ ___/ ___/ __ \/ __ \/ _ \
       / /_(__  ) /__/ /_/ / /_/ /  __/
       \__/____/\___/\____/ .___/\___/
                         /_/

    dbuff2.c
    using the double buffer to speed up drawing
*/

#include <tscope.h>

void put_some_pixels()
{
    int i, x, y;
    for (i = 0; i < (SXMAX * SYMAX); i++) {
        x = ts_rint(SXMAX);
        y = ts_rint(SYMAX);
        ts_putpixel(x, y);
    }
}


int main()
{
    // set up the screen, double buffer is on
    ts_scrsize(SIZE1);
    ts_doublebuff(ON);
    ts_init();
    ts_coordinates(STANDARD);

    // do some drawing directly to the screen
    ts_printf_centre(SXMAX / 2, SYMAX - 20,
                     "press next to draw %d pixels on the screen",
                     SXMAX * SYMAX);
    ts_button(SXMAX - 20, SYMAX - 20);
    put_some_pixels();

    ts_fgcolor(BLACK);
    ts_fill(ON);
    ts_rect(0, SYMAX - 50, SXMAX, SYMAX);
    ts_fgcolor(WHITE);
    ts_printf_centre(SXMAX / 2, SYMAX - 40, "quite slow, isn't it?");
    ts_printf_centre(SXMAX / 2, SYMAX - 20,
                     "press next to clear the screen");
    ts_button(SXMAX - 20, SYMAX - 20);


    // do some drawing on the buffer
    ts_clrscr();
    ts_printf_centre(SXMAX / 2, SYMAX - 40,
                     "press next to draw %d pixels on the double buffer",
                     SXMAX * SYMAX);
    ts_button(SXMAX - 20, SYMAX - 20);
    ts_tobuff();
    put_some_pixels();
    ts_toscr();

    // blit the buffer
    ts_printf_centre(SXMAX / 2, SYMAX - 20,
                     "done, press next to blit the buffer");
    ts_button(SXMAX - 20, SYMAX - 20);

    // exit
    ts_blitbuff();
    ts_fgcolor(BLACK);
    ts_rect(0, SYMAX - 50, SXMAX, SYMAX);
    ts_fgcolor(WHITE);
    ts_printf_centre(SXMAX / 2, SYMAX - 40, "press next to exit");

    ts_button(SXMAX - 20, SYMAX - 20);
    return 0;
}

END_OF_MAIN();


top
Persoonlijke pagina Universiteit GentTscope
Allegro | Cygwin | Gcc
© See license.html for copyright information