#include <Imagine/Graphics.h>
using namespace std;
const bool stepByStep=true;
void aWindow()
{
cout << "A window ... click when done" << endl;
}
void twoWindows()
{
cout << "Two windows ... click when done" << endl;
}
void twoDimBasics() {
cout << "Basic 2D drawings ... click when done" << endl;
for (int i=0;i<20;i+=2)
int px[]={201,200,260,240},py[]={301,350,330,280};
int t[]={300,300,300,400,400,350};
}
void bitmapBasics() {
cout << "Basic bitmap drawings... click when done" << endl;
byte r[256*256],g[256*256],b[256*256];
for (int j=0;j<256;j++) {
for (int i=0;i<256;i++) {
r[i+256*j]=i;
g[i+256*j]=255-i;
b[i+256*j]=(j<128)?255:0;
}
}
for (int j=0;j<256;j++)
for (int i=0;i<256;i++)
cols[i+256*j]=
Color(i,(2*j)%256,(i+j)%256);
for (int j=0;j<256;j++)
for (int i=0;i<256;i++)
grey[i+256*j]=byte(128+127*sin((i+j)/10.));
}
void mouseBasics() {
cout << "Basic mouse functions" << endl;
int button;
}
void imageBasics() {
cout << "Basic image reading/writing. click when done" << endl;
int w,h;
byte *r,*g,*b;
delete[]r;delete[]g;delete[]b;
delete[]I;
}
void captureFunctions()
{
int w = 456;
int h = 444;
byte *img_source;
return;
do {
}
while(p2.
x()-p1.
x()<=0 || p2.
y()-p1.
y()<=0);
byte *capt_r =
new byte[(p2.
x()-p1.
x())*(p2.
y()-p1.
y())];
byte *capt_g =
new byte[(p2.
x()-p1.
x())*(p2.
y()-p1.
y())];
byte *capt_b =
new byte[(p2.
x()-p1.
x())*(p2.
y()-p1.
y())];
delete [] capt_r;
delete [] capt_g;
delete [] capt_b;
}
void naiveAnimation()
{
for(int i = 0; i < 10; i++)
{
fillRect(rand()%300, rand()%300, rand()%50, rand()%50,
Color(rand()%256, rand()%256, rand()%256));
}
cout << "Finished!" << endl;
}
void fastDrawings() {
cout << "Fast drawings ... click when done" << endl;
for (int i=0;i<1000;i++) {
double r=200*i/1000.;
}
for (int i=0;i<100;i+=5) {
}
const int sz=128;
byte r[sz*sz],g[sz*sz],b[sz*sz];
for (int y=0;y<sz;y++) {
for (int x=0;x<sz;x++) {
r[x+sz*y]=2*x;
g[x+sz*y]=2*y;
b[x+sz*y]=2*(x+y);
}
}
for (int y=0;y<64;y++)
for (int x=0;x<64;x++)
cl[x+64*y]=
Color((x+y)%256,0,0);
for (int x=0;x<sz;x++)
for (int i=0;i<20;i++) {
double f=1+0.8*sin(i/2.);
putNativeBitmap(
int(256-sz/2+100*cos(i/4.0)),
int(256-sz/2+100*sin(i/4.0)),natBM,
true,f);
putNativeBitmap(
int(256-sz/2+100*cos(i/4.0)),
int(256-sz/2+100*sin(i/4.0)),natBM,
true,f);
}
}
void imageAnimation()
{
cout << "check 'ksmall.jpg' path" << endl;
cout <<
srcPath(
"ksmall.jpg") << endl;
int w, h;
for (int y = 0; y < h; ++y)
for (int x = 0; x < w; ++x)
for (int y = 0; y < h; ++y)
for (int x = 0; x < w; ++x)
std::cout << "wait for click!" << std::endl;
int x = 0, y = 0;
int step = 1;
for(int i = 0; i < 5*w/2; i++)
{
x += step;
if (x < 0 || x > w)
step *= -1;
}
cout << "Finished!" << endl;
}
void advancedEvents()
{
cout << "Advanced event handling" << endl;
drawString(10,30,
"Come back here again and press Up Arrow when done",
RED);
do {
case EVT_NONE:
cout << "No event for 500ms" << endl;
break;
case EVT_MOTION:
cout << "Motion" << endl;
break;
case EVT_KEY_ON:
cout <<
"Key " << ev.
key <<
" pressed"<< endl;
break;
case EVT_KEY_OFF:
cout <<
"Key " << ev.
key <<
" released"<< endl;
break;
case EVT_BUT_ON:
cout <<
"Button " << ev.
button <<
" pressed"<< endl;
break;
case EVT_BUT_OFF:
cout <<
"Button " << ev.
button <<
" released"<< endl;
break;
}
cout <<
" Mouse=[" << ev.
pix.
x() <<
','<<ev.
pix.
y() <<
"] " <<
",Win=" << ev.
win <<
",SubWin=" << ev.
subWin << endl;
}
void subWindows()
{
cout << "A window with sub windows..." << endl;
string names[]={"sub window 0","sub window 1","sub window 2"};
}
#ifdef IMAGINE_OPENGL
void threeDim()
{
Mesh Sphere = Mesh::Sphere(centerSphere, 0.8);
Mesh Cylinder = Mesh::Cylinder(centerCylinder, axisCylinder, 0.8);
Mesh Cone = Mesh::Cone(centerCone, axisCone, 0.8);
Mesh Plane = Mesh::Plane(centerPlane, axisPlane1, axisPlane2);
Mesh Cube = Mesh::Cube(centerCube, axis1Cube, axis2Cube, axis3Cube);
Mesh Arrow = Mesh::Arrow(baseArrow, shaftArrow, 0.5);
for(int i = 0; i < n; i++)
{
points_[i].
x() = Sphere.
vertices()[i].x() + 3;
points_[i].
y() = Sphere.
vertices()[i].y() + 3;
points_[i].
z() = Sphere.
vertices()[i].z() + 3;
}
Mesh PointCloud = Mesh::PointCloud(points_, Sphere.
vertices().size());
Mesh PolyLine = Mesh::PolyLine(points_, n,
false);
string fileName =
srcPath(
"bunny.obj");
cout << "Reading filename: \"" << fileName << "\"" << endl;
readMeshFromObjFile(Bunny, fileName);
mesh=Bunny; cout << "Bunny" << endl;
mesh=Sphere; cout << "Sphere" << endl;
mesh=Cylinder; cout << "Cylinder" << endl;
mesh=Cone; cout << "Cone" << endl;
mesh=Plane; cout << "Plane" << endl;
mesh=Cube; cout << "Cube" << endl;
mesh=Arrow; cout << "Arrow" << endl;
mesh=PointCloud; cout << "Point cloud" << endl;
mesh=PolyLine; cout << "PolyLine" << endl;
}
#endif
int main(int argc, char** argv) {
typedef void (*FUNC)();
vector< pair<string,FUNC> > tests;
#define ADD_TEST(func) \
tests.push_back(make_pair(string(#func), func));
ADD_TEST(aWindow);
ADD_TEST(twoWindows);
ADD_TEST(twoDimBasics);
ADD_TEST(bitmapBasics);
ADD_TEST(mouseBasics);
ADD_TEST(imageBasics);
ADD_TEST(subWindows);
ADD_TEST(naiveAnimation);
ADD_TEST(imageAnimation);
ADD_TEST(fastDrawings);
ADD_TEST(advancedEvents);
ADD_TEST(captureFunctions);
#ifdef IMAGINE_OPENGL
ADD_TEST(threeDim);
#endif
std::vector< pair<string,FUNC> >::const_iterator it;
if(argc<=1)
for(it=tests.begin(); it!=tests.end(); ++it) {
cout << "---" << it->first << "---" << std::endl;
it->second();
}
else {
bool fail=false;
for(int i=1; i<argc; i++) {
for(it=tests.begin(); it!=tests.end(); ++it) {
if(it->first == argv[i]) {
cout << "---" << it->first << "---" << std::endl;
it->second();
break;
}
}
if(it==tests.end()) {
std::cout << "Unknown test " << argv[i] << endl;
fail = true;
}
}
if(fail) {
cout << "--- Available tests:" << endl;
for(it=tests.begin(); it!=tests.end(); ++it)
cout << it->first << ' ';
cout << endl;
}
}
return 0;
}