2002-11-21 05:40:49 +00:00
|
|
|
/*******************************************************************************
|
2002-12-29 06:50:19 +00:00
|
|
|
This file is Part of the ZEngine Library for 2D game development.
|
|
|
|
Copyright (C) 2002, 2003 James Turk
|
2002-11-21 05:40:49 +00:00
|
|
|
|
2003-07-10 20:45:39 +00:00
|
|
|
ZEngine is Licensed under a BSD-style license.
|
|
|
|
This example file is in the public domain, it may be used with no restrictions.
|
2002-11-21 05:40:49 +00:00
|
|
|
|
2002-12-29 06:50:19 +00:00
|
|
|
The maintainer of this library is James Turk (james@conceptofzero.net)
|
|
|
|
and the home of this Library is http://www.zengine.sourceforge.net
|
2002-11-21 05:40:49 +00:00
|
|
|
*******************************************************************************/
|
2002-12-29 07:09:44 +00:00
|
|
|
|
2003-09-09 02:45:58 +00:00
|
|
|
/*$Id: ZImageTest.cpp,v 1.24 2003/09/09 02:45:58 cozman Exp $*/
|
2003-01-04 05:17:56 +00:00
|
|
|
|
2002-11-21 05:40:49 +00:00
|
|
|
#include <ZEngine.h>
|
|
|
|
#include <string>
|
|
|
|
using namespace std;
|
|
|
|
using namespace ZE;
|
|
|
|
|
2003-01-12 19:00:14 +00:00
|
|
|
bool Initialize()
|
2002-11-21 05:40:49 +00:00
|
|
|
{
|
|
|
|
ZEngine *engine = ZEngine::GetInstance();
|
|
|
|
ZConfigFile cfg("tests.zcf");
|
2003-01-04 05:16:01 +00:00
|
|
|
int w,h,bpp,rate;
|
2002-11-21 05:40:49 +00:00
|
|
|
bool fs;
|
2003-06-11 05:51:15 +00:00
|
|
|
std::string title;
|
2002-11-21 05:40:49 +00:00
|
|
|
|
|
|
|
w = cfg.GetInt("ZImageTest","width",800);
|
|
|
|
h = cfg.GetInt("ZImageTest","height",600);
|
|
|
|
bpp = cfg.GetInt("ZImageTest","bpp",32);
|
2002-12-27 03:15:33 +00:00
|
|
|
fs = cfg.GetBool("ZImageTest","fullscreen",true);
|
2002-11-21 05:40:49 +00:00
|
|
|
title = cfg.GetString("ZImageTest","title","ZImage Test");
|
2003-01-04 05:16:01 +00:00
|
|
|
rate = cfg.GetInt("ZImageTest","framerate",60);
|
2002-11-21 05:40:49 +00:00
|
|
|
|
|
|
|
engine->SetupDisplay(w,h,bpp,fs);
|
2003-01-04 05:16:01 +00:00
|
|
|
engine->SetDesiredFramerate(rate);
|
2003-01-12 19:00:14 +00:00
|
|
|
return engine->CreateDisplay(title);
|
2002-11-21 05:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Test()
|
|
|
|
{
|
|
|
|
ZEngine *engine = ZEngine::GetInstance();
|
2003-09-01 03:30:39 +00:00
|
|
|
float angle=0.0f,movDelta;
|
2003-01-25 19:56:05 +00:00
|
|
|
Uint8 alpha=128,alphaDelta=1;
|
2002-11-21 05:40:49 +00:00
|
|
|
|
|
|
|
//Open and Setup all the Images//
|
|
|
|
SDL_Surface *temp;
|
2003-09-01 03:30:39 +00:00
|
|
|
ZImage image1,image2,image3,image4,textImage;
|
2002-11-21 05:40:49 +00:00
|
|
|
ZFont font("data/almontew.ttf",30);
|
2003-09-01 03:30:39 +00:00
|
|
|
ZRect clipRect(400,300,30,30);
|
2002-12-01 07:56:17 +00:00
|
|
|
|
2002-11-21 05:40:49 +00:00
|
|
|
font.SetColor(0,255,0);
|
|
|
|
font.SetBGColor(0,0,255);
|
|
|
|
|
2002-12-27 18:56:17 +00:00
|
|
|
temp = SDL_LoadBMP("data/test02.bmp"); //this is a separate surface
|
|
|
|
image1.Attach(temp); //this attaches the surface into itself
|
|
|
|
image2.Open("data/test01.bmp");
|
|
|
|
image3.OpenFromImage(image2.Surface(),5,5,20,20);
|
2003-09-05 19:44:13 +00:00
|
|
|
image4.Open("data/test02.bmp");
|
2002-12-27 18:56:17 +00:00
|
|
|
temp = NULL; //and temp will now be controlled and freed by image1
|
|
|
|
image1.SetColorKey(255,0,255);
|
|
|
|
image2.SetColorKey(255,0,255);
|
2003-09-01 06:01:06 +00:00
|
|
|
#if (GFX_BACKEND == ZE_OGL)
|
2003-09-01 03:30:39 +00:00
|
|
|
image4.Resize(400,300);
|
2003-09-05 19:44:13 +00:00
|
|
|
image4.Flip(true,false);
|
2003-09-01 06:01:06 +00:00
|
|
|
#endif
|
2002-12-27 18:56:17 +00:00
|
|
|
font.DrawShadedText("ZImage Test.",textImage);
|
|
|
|
|
2002-11-21 05:40:49 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
//In the active loop, check events first//
|
|
|
|
engine->CheckEvents();
|
2002-12-27 03:15:33 +00:00
|
|
|
|
2003-01-12 19:00:14 +00:00
|
|
|
if(engine->IsActive())
|
2002-12-27 03:15:33 +00:00
|
|
|
{
|
2003-01-12 19:00:14 +00:00
|
|
|
if(engine->ImagesNeedReload())
|
|
|
|
{
|
|
|
|
image1.Reload();
|
|
|
|
image2.Reload();
|
|
|
|
image3.Reload();
|
|
|
|
textImage.Reload();
|
|
|
|
engine->SetReloadNeed(false); //very important for speed, without this you'd be reloading every frame
|
|
|
|
}
|
|
|
|
|
2003-09-01 03:30:39 +00:00
|
|
|
//movement//
|
|
|
|
movDelta = static_cast<float>(engine->GetFrameTime()*30);
|
|
|
|
if(engine->KeyIsPressed(SDLK_LEFT))
|
|
|
|
clipRect.MoveRel(-movDelta,0);
|
|
|
|
if(engine->KeyIsPressed(SDLK_RIGHT))
|
|
|
|
clipRect.MoveRel(movDelta,0);
|
|
|
|
if(engine->KeyIsPressed(SDLK_UP))
|
|
|
|
clipRect.MoveRel(0,-movDelta);
|
|
|
|
if(engine->KeyIsPressed(SDLK_DOWN))
|
|
|
|
clipRect.MoveRel(0,movDelta);
|
|
|
|
if(engine->KeyIsPressed(SDLK_EQUALS))
|
2003-01-12 19:00:14 +00:00
|
|
|
{
|
2003-09-01 03:30:39 +00:00
|
|
|
clipRect.MoveRel(-1,-1);
|
|
|
|
clipRect.ResizeRel(2,2);
|
|
|
|
}
|
|
|
|
if(engine->KeyIsPressed(SDLK_MINUS))
|
|
|
|
{
|
|
|
|
clipRect.MoveRel(1,1);
|
|
|
|
clipRect.ResizeRel(-2,-2);
|
2003-01-12 19:00:14 +00:00
|
|
|
}
|
2003-09-01 03:30:39 +00:00
|
|
|
|
|
|
|
if(engine->KeyIsPressed(SDLK_s))
|
|
|
|
engine->ToggleFullscreen();
|
2003-01-12 19:00:14 +00:00
|
|
|
if(engine->KeyIsPressed(SDLK_ESCAPE))
|
|
|
|
engine->RequestQuit();
|
|
|
|
|
|
|
|
engine->Clear(); //clear screen
|
|
|
|
//draw the images//
|
2003-01-25 19:56:05 +00:00
|
|
|
alpha += alphaDelta;
|
|
|
|
if(alpha ==255 || alpha == 0)
|
|
|
|
alphaDelta *= -1;
|
|
|
|
image1.SetAlpha(alpha);
|
2003-01-12 19:00:14 +00:00
|
|
|
image1.Draw(0,0);
|
2003-01-25 19:56:05 +00:00
|
|
|
|
2003-08-02 01:18:45 +00:00
|
|
|
#if (GFX_BACKEND == ZE_OGL)
|
2003-01-12 19:00:14 +00:00
|
|
|
image2.DrawRotated(100,0,angle);
|
|
|
|
if(++angle > 360)
|
|
|
|
angle = 0.0f;
|
2003-08-02 01:18:45 +00:00
|
|
|
#elif (GFX_BACKEND == ZE_SDL)
|
|
|
|
image2.Draw(100,0);
|
|
|
|
#endif
|
2003-01-12 19:00:14 +00:00
|
|
|
|
|
|
|
image3.Draw(200,0);
|
2003-09-01 03:30:39 +00:00
|
|
|
image4.DrawClipped(400,300,clipRect);
|
2003-01-12 19:00:14 +00:00
|
|
|
textImage.Draw(0,100);
|
|
|
|
engine->Update(); //update the screen
|
2002-12-27 03:15:33 +00:00
|
|
|
}
|
2003-01-25 19:56:05 +00:00
|
|
|
else
|
|
|
|
engine->Delay(10);
|
2002-12-27 03:15:33 +00:00
|
|
|
|
2002-11-21 05:40:49 +00:00
|
|
|
} while(!engine->QuitRequested()); //quit only when engine has encountered a quit request
|
|
|
|
}
|
|
|
|
|
2003-09-09 02:45:58 +00:00
|
|
|
int ZE_main(int argc, char *argv[])
|
2002-11-21 05:40:49 +00:00
|
|
|
{
|
2003-01-12 19:00:14 +00:00
|
|
|
if(Initialize())
|
|
|
|
Test();
|
2002-11-21 05:40:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|