home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Computer Panoráma
/
computer_panorama_1997-12-hibas.iso
/
SHARE
/
GRAPH
/
PTC051.ZIP
/
EXAMPLES
/
RAND16.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1997-09-23
|
1KB
|
66 lines
/////////////////////////////
// random putpixel example //
/////////////////////////////
#include "ptc.h"
#include <conio.h>
#include <iostream.h>
#include <stdlib.h>
int main(int argc,char *argv[])
{
// try to init ptc from command line (ie. "rand16 640 480 RGB565")
PTC ptc(argc,argv);
if (!ptc.ok())
{
// command line init failed - fall back to 320x200 fuzzy 16bit modeset
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 16bit RGB565 surface
Surface surface(ptc,xres,yres,RGB565);
// main loop
while (!ptc.kbhit())
{
// lock surface
ushort* buffer=(ushort*)surface.Lock();
if (!buffer)
{
ptc.Close();
cout << "null surface lock!\n";
return 1;
}
// plot 100 random pixels
for (int i=0; i<100; i++)
{
int x=random(xres);
int y=random(yres);
buffer[xres*y+x]=RGB16(random(255),random(255),random(255));
}
// unlock surface
surface.Unlock();
// update to display
surface.Update();
}
return 0;
}