Overview |
Description |
Main loop
The program loops around until the user presses
a key. Each loop around it locks the surface to access the memory, then
draws 100 random pixels at a time to this surface before unlocking it and
updating to the display. The RGB32 function is used to pack the three red,
green, blue bytes into a 32 bit ARGB8888 pixel.
Clean up
The PTC object is cleaned up automatically
when the main procedure exits, there is no need to explicitly shut down
PTC. At times during the program uses the function "PTC::Error" to shutdown
PTC and report an error message.
Source code |
int main(int
argc,char *argv[])
{
// initialize ptc from
command line (eg: "rand32 640 480 ARGB8888")
PTC ptc(argc,argv);
if (!ptc.ok())
{
//
fallback to virtual 32bit
if
(!ptc.Init(320,200))
{
// failure
ptc.Error("could not initialize ptc");
return 1;
}
}
// get display resolution
int xres=ptc.GetXResolution();
int yres=ptc.GetYResolution();
// create fullscreen surface
Surface surface(ptc,xres,yres,ARGB8888);
// 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);
uint *pixel=(uint*)(buffer+pitch*y+x*4);
*pixel=RGB32(random(255),random(255),random(255));
}
//
unlock surface
surface.Unlock();
//
update to display
surface.Update();
}
return 0;
}