home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Computer Panoráma
/
computer_panorama_1997-12-hibas.iso
/
SHARE
/
GRAPH
/
PTC051.ZIP
/
EXAMPLES
/
RAND32.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1997-09-23
|
2KB
|
71 lines
////////////////////////////////////
// random 32bit ARGB8888 putpixel //
////////////////////////////////////
#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. "rand32 640 480 ARGB8888")
PTC ptc(argc,argv);
if (!ptc.ok())
{
// command line init failed - fall back to 320x200 fuzzy 32bit modeset (FUZZY32 is implied)
if (!ptc.Init(320,200))
{
ptc.Close();
cout << "could not initialize ptc\n";
return 1;
}
}
// get display resolution
int xres=ptc.GetXResolution();
int yres=ptc.GetYResolution();
// create fullscreen 32bit ARGB8888 surface
Surface surface(ptc,xres,yres,ARGB8888);
// main loop
while (!ptc.kbhit())
{
// lock surface
uint* buffer=(uint*)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]=RGB32(random(255),random(255),random(255));
}
// unlock surface
surface.Unlock();
// update to display
if (!surface.Update())
{
ptc.Close();
cout << "update failed\n";
return 1;
}
}
return 0;
}