cpp_photon/test/Texture_test.cpp

99 lines
2.7 KiB
C++
Raw Normal View History

2005-06-13 05:38:06 +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-02 23:07:51 +00:00
// $Id: Texture_test.cpp,v 1.7 2005/08/02 23:07:53 cozman Exp $
2005-06-13 05:38:06 +00:00
#include "photon.hpp"
using namespace photon;
#include "FPSDisplayTask.hpp" // used to display FPS in title bar
2005-06-13 05:38:06 +00:00
class MainTask : public Task
{
public:
MainTask() :
Task("MainTask"),
2005-08-02 23:07:51 +00:00
app(Application::getAppCore()),
video(Application::getVideoCore())
2005-06-13 05:38:06 +00:00
{
video.setOrthoView(800,600);
2005-07-20 01:35:11 +00:00
video::Texture::addResource("data/icon.png");
video::Texture::addResource("robo","data/robo.png");
2005-06-27 04:24:08 +00:00
2005-07-20 01:35:11 +00:00
// Testing of errors, uncomment to get various errors
//video::Texture::addResource("nonfile"); // non-existant file
//video::Texture::addResource("Texture_test.cpp"); // non-image file
//tex[0].open("badresource"); // opening of non-existant resource
2005-06-27 04:24:08 +00:00
2005-07-20 01:35:11 +00:00
tex[0].open("data/icon.png");
tex[1].open("robo");
2005-06-27 04:24:08 +00:00
tex[2] = tex[1];
2005-06-13 05:38:06 +00:00
}
void update()
{
2005-07-20 01:35:11 +00:00
// draw first texture at actual size
2005-06-27 04:24:08 +00:00
tex[0].bind();
2005-06-13 05:38:06 +00:00
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex2f(0,0);
2005-07-20 01:35:11 +00:00
glTexCoord2f(1,0); glVertex2f(tex[0].getWidth(),0);
glTexCoord2f(1,1); glVertex2f(tex[0].getWidth(),tex[0].getHeight());
2005-06-13 05:38:06 +00:00
glTexCoord2f(0,1); glVertex2f(0,100);
glEnd();
2005-06-27 04:24:08 +00:00
2005-07-20 01:35:11 +00:00
// draw second texture on a diamond shaped polygon
2005-06-27 04:24:08 +00:00
tex[1].bind();
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex2f(250,200);
glTexCoord2f(1,0); glVertex2f(300,250);
glTexCoord2f(1,1); glVertex2f(250,300);
glTexCoord2f(0,1); glVertex2f(200,250);
glEnd();
2005-07-20 01:35:11 +00:00
// draw texture and test Texture's boolean operator
2005-06-27 04:24:08 +00:00
if(tex[2])
{
tex[2].bind();
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex2f(400,400);
glTexCoord2f(1,0); glVertex2f(500,400);
glTexCoord2f(1,1); glVertex2f(500,500);
glTexCoord2f(0,1); glVertex2f(400,500);
glEnd();
}
2005-06-13 05:38:06 +00:00
}
private:
2005-06-27 04:24:08 +00:00
video::Texture tex[3];
2005-07-20 01:35:11 +00:00
2005-06-13 05:38:06 +00:00
AppCore& app;
video::VideoCore& video;
};
2005-07-20 01:35:11 +00:00
// standard application, creates window, registers task and runs
2005-06-27 04:24:08 +00:00
class TextureTest : public Application
2005-06-13 05:38:06 +00:00
{
public:
int main(const StrVec& args)
{
2005-08-02 23:07:51 +00:00
Application::getAppCore().createDisplay(800,600,32,0,0,false);
2005-06-13 05:38:06 +00:00
// be sure to add FPSDisplayTask
2005-08-02 23:07:51 +00:00
Application::getKernel().addTask(TaskPtr(new FPSDisplayTask()));
Application::getKernel().addTask(TaskPtr(new MainTask()));
2005-06-13 05:38:06 +00:00
2005-08-02 23:07:51 +00:00
Application::getKernel().run();
2005-06-13 05:38:06 +00:00
return 0;
}
};
2005-06-27 04:24:08 +00:00
ENTRYPOINT(TextureTest)