//////////////////////////////////
// random 16bit RGB565 putpixel //
//////////////////////////////////
#include "ptc.h"







int main(int argc,char *argv[])
{
    // initialize ptc from command line (eg: "rand16 640 480 RGB565")
    PTC ptc(argc,argv);
    if (!ptc.ok())
    {
        // command line init failed
        if (!ptc.Init(320,200,FUZZY16))
        {
            ptc.Close();
            cout << "could not initialize ptc\n";
            return 1;
        }
    }

    // get display resolution
    int xres=ptc.GetXResolution();
    int yres=ptc.GetYResolution();

    // create fullscreen surface
    Surface surface(ptc,xres,yres,RGB565);

    // main loop
    while (!ptc.kbhit())
    {
        // lock surface
        char *buffer=(char*)surface.Lock();
        if (!buffer) return 1;

        // plot 100 random pixels
        int pitch=surface.GetPitch();
        for (int i=0; i<100; i++)
        {
            int x=random(xres);
            int y=random(yres);
            ushort *pixel=(ushort*)(buffer+pitch*y+x*2);
            *pixel=RGB16(random(255),random(255),random(255));
        }

        // unlock surface
        surface.Unlock();

        // update to display
        surface.Update();
    }
    return 0;
}
