cpp_photon/test/Image_test.cpp

78 lines
1.7 KiB
C++
Raw Normal View History

2005-06-27 04:27:49 +00:00
//This file is part of Photon (http://photon.sourceforge.net)
//Copyright (C) 2004-2005 James Turk
//
// Author:
// James Turk (jpt2433@rit.edu)
//
// Version:
2005-08-08 06:37:10 +00:00
// $Id: Image_test.cpp,v 1.10 2005/08/08 06:37:10 cozman Exp $
2005-06-27 04:27:49 +00:00
#include "photon.hpp"
using namespace photon;
#include "FPSDisplayTask.hpp" // used to display FPS in title bar
2005-06-27 04:27:49 +00:00
class MainState : public State
2005-06-27 04:27:49 +00:00
{
public:
MainState() :
app(Application::getInstance())
2005-06-27 04:27:49 +00:00
{
2005-07-19 20:31:41 +00:00
// load the images
2005-07-20 01:35:11 +00:00
video::Image::addResource("data/icon.png");
video::Texture::addResource("robo","data/robo.png");
2005-06-27 04:27:49 +00:00
2005-07-19 20:31:41 +00:00
// load img[0], set to half translucency and resize
2005-07-20 01:35:11 +00:00
img[0].open("robo");
2005-06-29 00:02:51 +00:00
img[0].setAlpha(128);
img[0].resize(100,200);
2005-07-19 20:31:41 +00:00
// load img[1]
2005-07-20 01:35:11 +00:00
img[1].open("data/icon.png");
2005-07-19 20:31:41 +00:00
// copy img[0] into img[2] and flip it
2005-06-29 00:02:51 +00:00
img[2] = img[0];
img[2].flip(true,true);
2005-06-27 04:27:49 +00:00
}
void render()
2005-06-27 04:27:49 +00:00
{
2005-07-19 20:31:41 +00:00
// draw in top left corner
2005-06-27 04:27:49 +00:00
img[0].draw(0,0);
2005-07-19 20:31:41 +00:00
// rotate according to timer
2005-06-27 04:27:49 +00:00
img[1].drawRotated(200,200,app.getTime()*5);
2005-07-19 20:31:41 +00:00
// example usage of Images boolean operator
2005-06-27 04:27:49 +00:00
if(img[2])
{
2005-07-20 01:35:11 +00:00
img[2].draw(0,200);
2005-06-27 04:27:49 +00:00
}
}
private:
video::Image img[3];
Application& app;
2005-06-27 04:27:49 +00:00
};
int PhotonMain(const StrVec& args)
2005-06-27 04:27:49 +00:00
{
2005-08-08 06:37:10 +00:00
// create window
Application::getInstance().createDisplay(800,600,32,0,0,false);
2005-06-27 04:27:49 +00:00
// be sure to add FPSDisplayTask
Kernel::getInstance().addTask(TaskPtr(new FPSDisplayTask()));
2005-06-27 04:27:49 +00:00
2005-08-08 06:37:10 +00:00
// set current state
Application::getInstance().setCurrentState<MainState>();
2005-06-27 04:27:49 +00:00
2005-08-08 06:37:10 +00:00
// run until finished
Kernel::getInstance().run();
return 0;
}
2005-06-27 04:27:49 +00:00