1) Fixed render-to-texture bug (which resulted in black background instead of

transparent one for the kart selection screen and mini map).
2) Added very first version of minimap (scale is wrong, no kart display yet).


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3778 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2009-07-20 12:35:34 +00:00
parent 317c3ee707
commit d8b212aa44
10 changed files with 100 additions and 46 deletions

View File

@ -274,6 +274,31 @@ scene::ISceneNode *IrrDriver::addMesh(scene::IMesh *mesh)
return m_scene_manager->addMeshSceneNode(mesh);
} // addMesh
// ----------------------------------------------------------------------------
/** Begins a rendering to a texture.
* \param dimension The size of the texture.
* \param name Name of the texture.
*/
void IrrDriver::beginRenderToTexture(const core::dimension2di &dimension,
const std::string &name)
{
m_render_target_texture = m_video_driver->addRenderTargetTexture(dimension,
name.c_str());
m_device->getVideoDriver()->setRenderTarget(m_render_target_texture);
} // beginRenderToTexture
// ----------------------------------------------------------------------------
/** Does the actual rendering to a texture, and switches the rendering system
* back to render on the screen.
* \return A pointer to the texture on which the scene was rendered.
*/
video::ITexture *IrrDriver::endRenderToTexture()
{
m_scene_manager->drawAll();
m_device->getVideoDriver()->setRenderTarget(0, false, false);
return m_render_target_texture;
} // endRenderToTexture
// ----------------------------------------------------------------------------
/** Renders a given vector of meshes onto a texture. Parameters:
* \param mesh Vector of meshes to render.
@ -343,7 +368,7 @@ void IrrDriver::renderToTexture(ptr_vector<scene::IMesh, REF>& mesh,
ICameraSceneNode* camera = m_scene_manager->addCameraSceneNode();
camera->setPosition( core::vector3df(0.0, 30.0f, 70.0f) );
camera->setUpVector( core::vector3df(0.0, -1.0, 0.0) );
camera->setUpVector( core::vector3df(0.0, 1.0, 0.0) );
camera->setTarget( core::vector3df(0, 10, 0.0f) );
camera->updateAbsolutePosition();

View File

@ -48,6 +48,9 @@ private:
/** Irrlicht race font. */
irr::gui::IGUIFont *m_race_font;
/** A pointer to texture on which a scene is rendered. Only used
* in between beginRenderToTexture() and endRenderToTexture calls. */
video::ITexture *m_render_target_texture;
void setAllMaterialFlags(scene::IAnimatedMesh *mesh) const;
std::vector<VideoMode> m_modes;
@ -104,6 +107,9 @@ public:
void renderToTexture(ptr_vector<scene::IMesh, REF>& mesh,
std::vector<Vec3>& mesh_location,
video::ITexture* target, float angle);
void beginRenderToTexture(const core::dimension2di &dimension,
const std::string &name);
video::ITexture *endRenderToTexture();
}; // IrrDriver
extern IrrDriver *irr_driver;

View File

@ -53,7 +53,7 @@ void ModelViewWidget::add()
m_element->setTabStop(false);
std::string name = "model view "; name += m_properties[PROP_ID].c_str();
m_texture = GUIEngine::getDriver()->addTexture( core::dimension2d< s32 >(512, 512), name.c_str() );
m_texture = GUIEngine::getDriver()->addRenderTargetTexture( core::dimension2d< s32 >(512, 512), name.c_str() );
}
// -----------------------------------------------------------------------------
void ModelViewWidget::clearModels()

View File

@ -214,9 +214,8 @@ void RaceGUI::drawPlayerIcons (const KartIconDisplayInfo* info)
int w = kart->isPlayerKart() ? ICON_PLAYER_WIDTH : ICON_WIDTH;
const core::rect<s32> pos(x, y, x+w, y+w);
const core::rect<s32> rect(core::position2d<s32>(0,0), icon->getOriginalSize());
static const video::SColor white(255,255,255,255);
irr_driver->getVideoDriver()->draw2DImage(icon, pos, rect, 0,
&white, true);
&video::SColor(255,255,255,255), true);
} // next kart
@ -243,13 +242,11 @@ void RaceGUI::drawPowerupIcons(Kart* player_kart, int offset_x,
video::ITexture *t=powerup->getIcon()->getTexture();
core::rect<s32> rect(core::position2di(0, 0), t->getOriginalSize());
static const video::SColor white(255,255,255,255);
for ( int i = 0 ; i < n ; i++ )
{
core::rect<s32> pos(x1+i*30, y1, x1+i*30+nSize, y1+nSize);
irr_driver->getVideoDriver()->draw2DImage(t, pos, rect, 0,
&white,
&video::SColor(255,255,255,255),
true);
} // for i
} // drawPowerupIcons
@ -679,7 +676,7 @@ void RaceGUI::drawStatusText()
drawMusicDescription();
}
//drawMap();
drawMap();
drawPlayerIcons(info);
} // drawStatusText

View File

@ -149,12 +149,11 @@ void QuadGraph::setDefaultSuccessors()
} // setDefaultSuccessors
// -----------------------------------------------------------------------------
/** Creates the debug mesh to display the quad graph on top of the track
* model. */
void QuadGraph::createDebugMesh()
/** Creates a mesh for this graph. The mesh is not added to a scene node and
* is stored in m_mesh.
*/
void QuadGraph::createMesh()
{
if(m_all_nodes.size()<=0) return; // no debug output if not graph
// The debug track will not be lighted or culled.
video::SMaterial m;
m.BackfaceCulling = false;
@ -171,7 +170,7 @@ void QuadGraph::createDebugMesh()
// we need 2*3 indices for each quad.
irr::u16 *ind = new irr::u16[n*6];
// Now add all other quads
// Now add all quads
for(unsigned int i=0; i<n; i++)
{
// Swap the colours from red to blue and back
@ -197,6 +196,28 @@ void QuadGraph::createDebugMesh()
//m_node->setAutomaticCulling(scene::EAC_OFF);
m_mesh_buffer->recalculateBoundingBox();
m_mesh->setBoundingBox(m_mesh_buffer->getBoundingBox());
} // createMesh
// -----------------------------------------------------------------------------
/** Creates the debug mesh to display the quad graph on top of the track
* model. */
void QuadGraph::createDebugMesh()
{
if(m_all_nodes.size()<=0) return; // no debug output if not graph
createMesh();
// Now colour the quads red/blue/red ...
video::SColor c(255, 255, 0, 0);
video::S3DVertex *v = (video::S3DVertex*)m_mesh_buffer->getVertices();
for(unsigned int i=0; m_mesh_buffer->getVertexCount(); i++)
{
// Swap the colours from red to blue and back
c.setRed (i%2 ? 255 : 0);
c.setBlue(i%2 ? 0 : 255);
v[i].Color = c;
}
m_node = irr_driver->addMesh(m_mesh);
} // createDebugMesh
@ -381,28 +402,29 @@ int QuadGraph::findOutOfRoadSector(const Vec3& xyz,
* \param where the top left and lower right corner for the mini map.
*/
video::ITexture *QuadGraph::makeMiniMap(const core::dimension2di &dimension,
const std::string &name)
const std::string &name,
const video::SColor &fill_color)
{
return NULL;
video::ITexture *texture =
irr_driver->getVideoDriver()->addTexture(dimension, name.c_str());
// FIXME: all very much work in progress, only committed as a backup
// (and to include the debug cleanup)
// createDebugMesh();
scene::IMesh *mesh = irr_driver->createQuadMesh();
scene::IMeshBuffer *buffer = mesh->getMeshBuffer(0);
unsigned int n = m_all_nodes.size();
for(unsigned int i=0; i<n; i++)
irr_driver->beginRenderToTexture(dimension, name);
createMesh();
video::S3DVertex *v = (video::S3DVertex*)m_mesh_buffer->getVertices();
for(unsigned int i=0; i<m_mesh_buffer->getVertexCount(); i++)
{
const Quad &q=m_all_quads->getQuad(m_all_nodes[i]->getIndex());
v[i].Color = fill_color;
}
irr_driver->removeMesh(mesh);
const std::string f=file_manager->getTrackFile("waterfall.png", "beach");
return irr_driver->getTexture(f);
m_node = irr_driver->addMesh(m_mesh); // add Debug Mesh
m_node->setMaterialFlag(video::EMF_LIGHTING, false);
// Add the camera:
Vec3 bb_min, bb_max;
m_all_quads->getBoundingBox(&bb_min, &bb_max);
Vec3 center = (bb_max+bb_min)*0.5f;
scene::ICameraSceneNode *camera = irr_driver->addCamera();
camera->setPosition(core::vector3df(center.getX(), 120, center.getY()));
camera->setUpVector(core::vector3df(0,0,1));
camera->setTarget(core::vector3df(center.getX(),0,center.getY()));
video::ITexture *texture=irr_driver->endRenderToTexture();
cleanupDebugMesh();
return texture;
} // drawMiniMap

View File

@ -43,6 +43,7 @@ private:
void setDefaultSuccessors();
void load (const std::string &filename);
void createMesh();
public:
static const int UNKNOWN_SECTOR;
@ -62,7 +63,9 @@ public:
std::vector<int> *all_sectors=NULL
) const;
video::ITexture *makeMiniMap(const core::dimension2di &where,
const std::string &name);
const std::string &name,
const video::SColor &fill_color
=video::SColor(127, 255, 255, 255) );
/** Returns the number of nodes in the graph. */
unsigned int getNumNodes() const { return m_all_nodes.size(); }

View File

@ -59,8 +59,8 @@ void QuadSet::getPoint(const XMLNode *xml, const std::string &attribute_name,
} // getPoint
// -----------------------------------------------------------------------------
void QuadSet::load(const std::string &filename) {
m_xMin = m_zMin = 9999999.9f;
m_xMax = m_zMax = -9999999.9f;
m_min = Vec3( 99999, 99999, 99999);
m_max = Vec3(-99999, -99999, -99999);
XMLNode *xml = file_manager->createXMLTree(filename);
if(!xml || xml->getName()!="quads")
@ -85,6 +85,8 @@ void QuadSet::load(const std::string &filename) {
getPoint(xml_node, "p3", &p3);
Quad* q=new Quad(p0,p1,p2,p3);
m_all_quads.push_back(q);
m_max.max(p0);m_max.max(p1);m_max.max(p2);m_max.max(p3);
m_min.min(p0);m_min.min(p1);m_min.min(p2);m_min.min(p3);
}
delete xml;

View File

@ -24,15 +24,15 @@
#include <string>
#include "tracks/quad.hpp"
#include "utils/vec3.hpp"
class Vec3;
class XMLNode;
class QuadSet {
private:
/** The 2d bounding box, used for hashing. */
// FIXME: named with z being the forward axis
float m_xMin, m_xMax, m_zMin, m_zMax;
Vec3 m_min;
Vec3 m_max;
/** The list of all quads. */
std::vector<Quad*> m_all_quads;
void load (const std::string &filename);
@ -51,10 +51,8 @@ public:
/** Returns true if the point p is in the n-th. quad. */
bool pointInQuad (int n, const btVector3& p) const
{return pointInQuad(*m_all_quads[n],p);}
void getBoundingBox(float* xMin, float* xMax,
float* zMin, float* zMax) const
{ *xMin=m_xMin; *xMax=m_xMax;
*zMin=m_zMin; *zMax=m_zMax;}
/** Return the minimum and maximum coordinates of this quad set. */
void getBoundingBox(Vec3 *min, Vec3 *max) { *min=m_min; *max=m_max; }
/** Returns the number of quads. */
unsigned int getNumberOfQuads() const
{return (unsigned int)m_all_quads.size(); }

View File

@ -600,7 +600,7 @@ void Track::loadQuadGraph()
{
m_quad_graph = new QuadGraph(file_manager->getTrackFile(m_ident+".quads"),
file_manager->getTrackFile(m_ident+".graph"));
m_mini_map = m_quad_graph->makeMiniMap(core::dimension2di(100,100), m_ident);
m_mini_map = m_quad_graph->makeMiniMap(core::dimension2di(128,128), m_ident);
if(m_quad_graph->getNumNodes()==0)
{
fprintf(stderr, "No graph nodes defined for track '%s'\n",

View File

@ -74,7 +74,8 @@ public:
/** Helper functions to treat this vec3 as a 2d vector. This returns the
* square of the length of the first 2 dimensions. */
float length2_2d() const {return m_x*m_x + m_y*m_y;}
/** Returns the length of the vector. */
/** Returns the length of this vector in the plane, i.e. the vector is
* used as a 2d vector. */
float length_2d() const {return sqrt(m_x*m_x + m_y*m_y);}
/** Sets this = max(this, a) componentwise.
* \param Vector to compare with. */