This bug must be a .98->1.0.1 bug. It worked in .98, but doesn't work in 1.0.1
Back up your simpmap directory, then paste the two attached files in, and
recompile, you'll see what I am talking about if you look closely. Don't
forget to make the directory Crystalspace/data/AWT/ and place X.TGA there.
When I get my iImageHelper.cpp working with the latest CS, I'll publish it. It
has some nice helper functions for iImages. I'm not sure why I didn't release
it before.
Jim Sager <[EMAIL PROTECTED]> wrote: void
setred (iImage * image, int x, int y, int red)
{
((csRGBpixel *) image->GetImageData ())[y * image->GetWidth () + x].red =
red;
}
csRef < iImage > xbut;
xbut =
loader->LoadImage ("/this/data/AWT/X.TGA",
CS_IMGFMT_TRUECOLOR | CS_IMGFMT_ALPHA);
setred(xbut,0,0,255); //This sets the 0,3 pixel to 255 red
setred(xbut,2,0,255); //This sets the 2,3 pixel to 255 red
setred(xbut,2,1,255); //This sets the 2,3 pixel to 255 red
setred(xbut,0,2,255); //This sets the 0,3 pixel to 255 red
setred(xbut,4,4,255); //This sets the 4,4 pixel to 255 red
This function worked properly in .98. Is there something I am missing in 1.1?
---------------------------------
Don't be flakey. Get Yahoo! Mail for Mobile and
always stay connected to
friends.-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/_______________________________________________
Crystal-main mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/crystal-main
Unsubscribe: mailto:[EMAIL PROTECTED]
---------------------------------
Sick sense of humor? Visit Yahoo! TV's Comedy with an Edge to see what's on,
when. /*
Copyright (C) 2001 by Jorrit Tyberghein
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "simpmap.h"
int getred (iImage * image, int x, int y);
int getgreen (iImage * image, int x, int y);
int getblue (iImage * image, int x, int y);
int getalpha (iImage * image, int x, int y);
void setgreen (iImage * image, int x, int y, int green);
void setblue (iImage * image, int x, int y, int blue);
void setred (iImage * image, int x, int y, int red);
void setalpha (iImage * image, int x, int y, int alpha);
void
setred (iImage * image, int x, int y, int red)
{
((csRGBpixel *) image->GetImageData ())[y * image->GetWidth () + x].red =
red;
}
void
setgreen (iImage * image, int x, int y, int green)
{
((csRGBpixel *) image->GetImageData ())[y * image->GetWidth () + x].green =
green;
}
void
setblue (iImage * image, int x, int y, int blue)
{
((csRGBpixel *) image->GetImageData ())[y * image->GetWidth () + x].blue =
blue;
}
void
setalpha (iImage * image, int x, int y, int alpha)
{
((csRGBpixel *) image->GetImageData ())[y * image->GetWidth () + x].alpha =
alpha;
}
int
getred (iImage * image, int x, int y)
{
return ((csRGBpixel *) image->GetImageData ())[y * image->GetWidth () +
x].red;
}
int
getgreen (iImage * image, int x, int y)
{
return ((csRGBpixel *) image->GetImageData ())[y * image->GetWidth () +
x].green;
}
int
getblue (iImage * image, int x, int y)
{
return ((csRGBpixel *) image->GetImageData ())[y * image->GetWidth () +
x].blue;
}
int
getalpha (iImage * image, int x, int y)
{
return ((csRGBpixel *) image->GetImageData ())[y * image->GetWidth () +
x].alpha;
}
CS_IMPLEMENT_APPLICATION
//-----------------------------------------------------------------------------
Simple::Simple ()
{
SetApplicationName ("CrystalSpace.SimpleMap");
}
Simple::~Simple ()
{
}
bool Simple::Setup ()
{
// Now get the pointer to various modules we need. We fetch them
// from the object registry. The RequestPlugins() call we did earlier
// registered all loaded plugins with the object registry.
// The virtual clock.
g3d = csQueryRegistry<iGraphics3D> (GetObjectRegistry());
if (!g3d) return ReportError ("Failed to locate 3D renderer!");
engine = csQueryRegistry<iEngine> (GetObjectRegistry());
if (!engine) return ReportError ("Failed to locate 3D engine!");
vc = csQueryRegistry<iVirtualClock> (GetObjectRegistry());
if (!vc) return ReportError ("Failed to locate Virtual Clock!");
kbd = csQueryRegistry<iKeyboardDriver> (GetObjectRegistry());
if (!kbd) return ReportError ("Failed to locate Keyboard Driver!");
loader = csQueryRegistry<iLoader> (GetObjectRegistry());
if (!loader) return ReportError ("Failed to locate Loader!");
cdsys = csQueryRegistry<iCollideSystem> (GetObjectRegistry());
if (!cdsys) return ReportError ("Failed to locate CD system!");
// We need a View to the virtual world.
view.AttachNew(new csView (engine, g3d));
iGraphics2D* g2d = g3d->GetDriver2D ();
// We use the full window to draw the world.
view->SetRectangle (0, 0, g2d->GetWidth (), g2d->GetHeight ());
// Here we load our world from a map file.
if (!LoadMap ()) return false;
// Initialize collision objects for all loaded objects.
csColliderHelper::InitializeCollisionWrappers (cdsys, engine);
// Let the engine prepare all lightmaps for use and also free all images
// that were loaded for the texture manager.
engine->Prepare ();
// Find the starting position in this level.
csVector3 pos (0);
if (engine->GetCameraPositions ()->GetCount () > 0)
{
// There is a valid starting position defined in the level file.
iCameraPosition* campos = engine->GetCameraPositions ()->Get (0);
room = engine->GetSectors ()->FindByName (campos->GetSector ());
pos = campos->GetPosition ();
}
else
{
// We didn't find a valid starting position. So we default
// to going to room called 'room' at position (0,0,0).
room = engine->GetSectors ()->FindByName ("room");
pos = csVector3 (0, 0, 0);
}
if (!room)
ReportError("Can't find a valid starting position!");
// Now we need to position the camera in our world.
view->GetCamera ()->SetSector (room);
view->GetCamera ()->GetTransform ().SetOrigin (pos);
// Initialize our collider actor.
collider_actor.SetCollideSystem (cdsys);
collider_actor.SetEngine (engine);
csVector3 legs (.2f, .3f, .2f);
csVector3 body (.2f, 1.2f, .2f);
csVector3 shift (0, -1, 0);
collider_actor.InitializeColliders (view->GetCamera (),
legs, body, shift);
iTextureWrapper *texh;
iTextureHandle* phTex;
// Create a 2D sprite for the Logo.
// texh = engine->GetTextureList ()->FindByName ("cslogo2");
texh = engine->GetTextureList ()->Get(15);
if (texh)
{
phTex = texh->GetTextureHandle();
if (phTex)
{
cslogo = new csSimplePixmap (phTex);
}
}
csRef < iImage > xbut;
csRef < iImage > xbut2;
xbut =
loader->LoadImage ("/this/data/AWT/X.TGA",
CS_IMGFMT_TRUECOLOR | CS_IMGFMT_ALPHA);
csImageMemory csim(xbut);
xbut2=xbut;
csRef < iTextureManager > txtmgr;
csRef < iTextureHandle > txt;
txtmgr = g3d->GetTextureManager ();
txt = txtmgr->RegisterTexture (xbut, CS_TEXTURE_2D);
pixmap = new csSimplePixmap (txt);
setred(xbut2,5,5,240);
txt = txtmgr->RegisterTexture (xbut2, CS_TEXTURE_2D);
pixmap2 = new csSimplePixmap (txt);
return true;
}
void Simple::ProcessFrame ()
{
static bool okk=true;
// First get elapsed time from the virtual clock.
csTicks elapsed_time = vc->GetElapsedTicks ();
csVector3 obj_move (0);
csVector3 obj_rotate (0);
if (kbd->GetKeyState (CSKEY_SHIFT))
{
// If the user is holding down shift, the arrow keys will cause
// the camera to strafe up, down, left or right from it's
// current position.
if (kbd->GetKeyState (CSKEY_RIGHT))
obj_move = CS_VEC_RIGHT * 3.0f;
if (kbd->GetKeyState (CSKEY_LEFT))
obj_move = CS_VEC_LEFT * 3.0f;
if (kbd->GetKeyState (CSKEY_UP))
obj_move = CS_VEC_UP * 3.0f;
if (kbd->GetKeyState (CSKEY_DOWN))
obj_move = CS_VEC_DOWN * 3.0f;
}
else
{
// left and right cause the camera to rotate on the global Y
// axis; page up and page down cause the camera to rotate on the
// _camera's_ X axis (more on this in a second) and up and down
// arrows cause the camera to go forwards and backwards.
if (kbd->GetKeyState (CSKEY_RIGHT))
obj_rotate.Set (0, 1, 0);
if (kbd->GetKeyState (CSKEY_LEFT))
obj_rotate.Set (0, -1, 0);
if (kbd->GetKeyState (CSKEY_PGUP))
obj_rotate.Set (1, 0, 0);
if (kbd->GetKeyState (CSKEY_PGDN))
obj_rotate.Set (-1, 0, 0);
if (kbd->GetKeyState (CSKEY_UP))
obj_move = CS_VEC_FORWARD * 3.0f;
if (kbd->GetKeyState (CSKEY_DOWN))
obj_move = CS_VEC_FORWARD * -3.0f;
}
collider_actor.Move (float (elapsed_time) / 1000.0f, 1.0f,
obj_move, obj_rotate);
// Tell 3D driver we're going to display 3D things.
if (!g3d->BeginDraw (engine->GetBeginDrawFlags () | CSDRAW_3DGRAPHICS))
return;
// Tell the camera to render into the frame buffer.
view->Draw ();
g3d->BeginDraw (engine->GetBeginDrawFlags () | CSDRAW_2DGRAPHICS);
cslogo->Draw (g3d, 0, 0);
pixmap->Draw (g3d, 0, 300);
pixmap2->Draw (g3d, 100, 300);
}
void Simple::FinishFrame ()
{
// Just tell the 3D renderer that everything has been rendered.
g3d->FinishDraw ();
g3d->Print (0);
}
bool Simple::OnKeyboard(iEvent& ev)
{
// We got a keyboard event.
csKeyEventType eventtype = csKeyEventHelper::GetEventType(&ev);
if (eventtype == csKeyEventTypeDown)
{
// The user pressed a key (as opposed to releasing it).
utf32_char code = csKeyEventHelper::GetCookedCode(&ev);
if (code == CSKEY_ESC)
{
// The user pressed escape to exit the application.
// The proper way to quit a Crystal Space application
// is by broadcasting a csevQuit event. That will cause the
// main runloop to stop. To do that we get the event queue from
// the object registry and then post the event.
csRef<iEventQueue> q =
csQueryRegistry<iEventQueue> (GetObjectRegistry());
if (q.IsValid()) q->GetEventOutlet()->Broadcast(csevQuit(GetObjectRegistry()));
}
}
return false;
}
bool Simple::OnInitialize(int /*argc*/, char* /*argv*/ [])
{
// RequestPlugins() will load all plugins we specify. In addition
// it will also check if there are plugins that need to be loaded
// from the config system (both the application config and CS or
// global configs). In addition it also supports specifying plugins
// on the commandline.
iObjectRegistry *object_reg;
if (!csInitializer::RequestPlugins(object_reg = GetObjectRegistry(),
CS_REQUEST_VFS,
CS_REQUEST_OPENGL3D,
CS_REQUEST_ENGINE,
CS_REQUEST_FONTSERVER,
CS_REQUEST_IMAGELOADER,
CS_REQUEST_LEVELLOADER,
CS_REQUEST_REPORTER,
CS_REQUEST_REPORTERLISTENER,
CS_REQUEST_PLUGIN("crystalspace.collisiondetection.opcode",
iCollideSystem),
CS_REQUEST_END))
return ReportError("Failed to initialize plugins!");
csBaseEventHandler::Initialize(GetObjectRegistry());
// Now we need to setup an event handler for our application.
// Crystal Space is fully event-driven. Everything (except for this
// initialization) happens in an event.
if (!RegisterQueue(GetObjectRegistry(), csevAllEvents(GetObjectRegistry())))
return ReportError("Failed to set up event handler!");
return true;
}
void Simple::OnExit()
{
}
bool Simple::Application()
{
// Open the main system. This will open all the previously loaded plug-ins.
// i.e. all windows will be opened.
if (!OpenApplication (GetObjectRegistry()))
return ReportError ("Error opening system!");
if (!Setup())
return false;
// This calls the default runloop. This will basically just keep
// broadcasting process events to keep the game going.
Run ();
return true;
}
bool Simple::LoadMap ()
{
// Set VFS current directory to the level we want to load.
csRef<iVFS> VFS (csQueryRegistry<iVFS> (GetObjectRegistry ()));
VFS->ChDir ("/lev/flarge");
// Load the level file which is called 'world'.
if (!loader->LoadMapFile ("world"))
ReportError("Error couldn't load level!");
return true;
}
/*---------------------------------------------------------------------*
* Main function
*---------------------------------------------------------------------*/
int main (int argc, char* argv[])
{
/* Runs the application.
*
* csApplicationRunner<> is a small wrapper to support "restartable"
* applications (ie where CS needs to be completely shut down and loaded
* again). Simple1 does not use that functionality itself, however, it
* allows you to later use "Simple.Restart();" and it'll just work.
*/
return csApplicationRunner<Simple>::Run (argc, argv);
}
/*
Copyright (C) 2001 by Jorrit Tyberghein
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __SIMPMAP_H__
#define __SIMPMAP_H__
#include <crystalspace.h>
/**
* This is the main class of this Tutorial. It contains the
* basic initialization code and the main event handler.
*
* csApplicationFramework provides a handy object-oriented wrapper around the
* Crystal Space initialization and start-up functions.
*
* csBaseEventHandler provides a base object which does absolutely nothing
* with the events that are sent to it.
*/
class Simple : public csApplicationFramework, public csBaseEventHandler
{
private:
bool Setup ();
/// A pointer to the 3D engine.
csRef<iEngine> engine;
/// A pointer to the map loader plugin.
csRef<iLoader> loader;
/// A pointer to the 3D renderer plugin.
csRef<iGraphics3D> g3d;
/// A pointer to the keyboard driver.
csRef<iKeyboardDriver> kbd;
/// A pointer to the virtual clock.
csRef<iVirtualClock> vc;
/// A pointer to the collision detection system.
csRef<iCollideSystem> cdsys;
/// A pointer to the view which contains the camera.
csRef<iView> view;
/// A pointer to the sector the camera will be in.
iSector* room;
/// Our collider used for gravity and CD.
csColliderActor collider_actor;
/**
* Handle keyboard events - ie key presses and releases.
* This routine is called from the event handler in response to a
* csevKeyboard event.
*/
bool OnKeyboard (iEvent&);
/**
* Setup everything that needs to be rendered on screen. This routine
* is called from the event handler in response to a csevProcess
* broadcast message.
*/
void ProcessFrame ();
/**
* Finally render the screen. This routine is called from the event
* handler in response to a csevFinalProcess broadcast message.
*/
void FinishFrame ();
/// Here we will load our world from a map file.
bool LoadMap ();
public:
/// Construct our game. This will just set the application ID for now.
Simple ();
/// Destructor.
~Simple ();
/// Final cleanup.
void OnExit ();
/**
* Main initialization routine. This routine will set up some basic stuff
* (like load all needed plugins, setup the event handler, ...).
* In case of failure this routine will return false. You can assume
* that the error message has been reported to the user.
*/
bool OnInitialize (int argc, char* argv[]);
/**
* Run the application.
* First, there are some more initialization (everything that is needed
* by Simple1 to use Crystal Space), then this routine fires up the main
* event loop. This is where everything starts. This loop will basically
* start firing events which actually causes Crystal Space to function.
* Only when the program exits this function will return.
*/
bool Application ();
csPixmap* cslogo;
csPixmap *pixmap;
csPixmap *pixmap2;
CS_EVENTHANDLER_NAMES ("crystalspace.simpmap")
CS_EVENTHANDLER_NIL_CONSTRAINTS
};
#endif // __SIMPMAP_H__
<<inline: X.TGA>>
------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/
_______________________________________________ Crystal-main mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/crystal-main Unsubscribe: mailto:[EMAIL PROTECTED]
