void VideoVisual::render(const cv::Mat& image) { // Fix image size if necessary const cv::Mat* image_ptr = ℑ cv::Mat converted_image; if (image_ptr->rows != height_ || image_ptr->cols != width_) { cv::resize(*image_ptr, converted_image, cv::Size(width_, height_)); image_ptr = &converted_image; } // Get the pixel buffer Ogre::HardwarePixelBufferSharedPtr pixelBuffer = this->texture_->getBuffer(); // Lock the pixel buffer and get a pixel box pixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD); const Ogre::PixelBox& pixelBox = pixelBuffer->getCurrentLock(); uint8_t* pDest = static_cast<uint8_t*>(pixelBox.data); memcpy(pDest, image_ptr->data, height_ * width_ * 4); // Unlock the pixel buffer pixelBuffer->unlock(); }
//------------------------------------------------------------------------------ void OgreVideoTexture::_initTexture(Ogre::TexturePtr _texture) { // Get the pixel buffer Ogre::HardwarePixelBufferSharedPtr pixelBuffer = _texture->getBuffer(); // Lock the pixel buffer and get a pixel box pixelBuffer->lock(Ogre::HardwareBuffer::HBL_NORMAL); // for best performance use HBL_DISCARD! const Ogre::PixelBox& pixelBox = pixelBuffer->getCurrentLock(); Ogre::uint8* pDest = static_cast<Ogre::uint8*>(pixelBox.data); for (size_t j = 0; j < _texture->getHeight(); j++) for(size_t i = 0; i < _texture->getWidth() ; i++) { if (j<480-5 && i<640-5) { *pDest++ = 255; // B *pDest++ = 0; // G *pDest++ = 255; // R } else { *pDest++ = 255; // B *pDest++ = 0; // G *pDest++ = 0; // R } } pixelBuffer->unlock(); }
//------------------------------------------------------------------------------ void OgreVideoTexture::_copyImagePerPixel(const IplImage *_image ,Ogre::HardwarePixelBufferSharedPtr _pixelBuffer) { // Lock the pixel buffer and get a pixel box _pixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD); // for best performance use HBL_DISCARD! const Ogre::PixelBox& pixelBox = _pixelBuffer->getCurrentLock(); Ogre::uint32* pDest = static_cast<Ogre::uint32*>(pixelBox.data); size_t w, h, widthStep; w = _image->width; h = _image->height; widthStep = _image->widthStep; Ogre::uint32 pixelBGRA; for(size_t i=0 ; i < h ; i++) { size_t offset = i*widthStep; for (size_t j=0 ; j < w ; j++) { memcpy(&pixelBGRA, _image->imageData + offset +j*3, sizeof(Ogre::uint32)); pDest[i *1024 + j] = pixelBGRA; } } _pixelBuffer->unlock(); }
//------------------------------------------------------------------------------ void OgreVideoTexture::_copyImagePerChannel(const IplImage *_image ,Ogre::HardwarePixelBufferSharedPtr _pixelBuffer) { // Lock the pixel buffer and get a pixel box _pixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD); // for best performance use HBL_DISCARD! const Ogre::PixelBox& pixelBox = _pixelBuffer->getCurrentLock(); Ogre::uint8* pDest = static_cast<Ogre::uint8*>(pixelBox.data); for (size_t j = 0; j < _image->height; j++) for(size_t i = 0; i < _image->width ; i++) { char pixelR = CV_IMAGE_ELEM(_image, char, j, i*3+2 ); char pixelG = CV_IMAGE_ELEM(_image, char, j, i*3+1); char pixelB = CV_IMAGE_ELEM(_image, char, j, i*3 ); int w = mVideoTexture->getWidth(); pDest[j*1024*4 + i*4] = pixelB; pDest[j*1024*4 + i*4+1] = pixelG; pDest[j*1024*4 + i*4+2] = pixelR; //pDest[j*w*4 + i*4+3] = 255; } _pixelBuffer->unlock(); }
void RenderHandler::OnPaint(CefRefPtr<CefBrowser> browser, PaintElementType type, const RectList &dirtyRects, const void *buffer, int width, int height) { Ogre::HardwarePixelBufferSharedPtr texBuf = m_texture->getBuffer(); texBuf->lock(Ogre::HardwareBuffer::HBL_DISCARD); memcpy(texBuf->getCurrentLock().data, buffer, width*height*4); texBuf->unlock(); }
void DataManager::_updateVolTextureData(Cell ***c, const VolTextureId& TexId, const int& nx, const int& ny, const int& nz) { Ogre::HardwarePixelBufferSharedPtr buffer = mVolTextures[TexId]->getBuffer(0,0); buffer->lock(Ogre::HardwareBuffer::HBL_DISCARD); const Ogre::PixelBox &pb = buffer->getCurrentLock(); Ogre::uint32 *pbptr = static_cast<Ogre::uint32*>(pb.data); size_t x, y, z; for (z=pb.front; z<pb.back; z++) { for (y=pb.top; y<pb.bottom; y++) { for (x=pb.left; x<pb.right; x++) { Ogre::PixelUtil::packColour(c[x][y][z].dens/* TODO!!!! */, c[x][y][z].light, 0, 0, pb.format, &pbptr[x]); } pbptr += pb.rowPitch; } pbptr += pb.getSliceSkip(); } buffer->unlock(); }
bool TextureManager::_updateNormalMap(Image &Image) { if (!mCreated) { HydraxLOG("Error in TextureManager::_updateNormalMap, create() does not called."); return false; } if (Image.getType() != Image::TYPE_RGB) { HydraxLOG("Error in TextureManager::_updateNormalMap, Image type isn't correct."); return false; } Ogre::TexturePtr &Texture = getTexture(TEX_NORMAL_ID); Size ImageSize = Image.getSize(); if (Texture->getWidth() != ImageSize.Width || Texture->getHeight() != ImageSize.Height) { HydraxLOG("Error in TextureManager::update, Update size doesn't correspond to " + getTextureName(TEX_NORMAL_ID) + " texture size"); return false; } Ogre::HardwarePixelBufferSharedPtr pixelBuffer = Texture->getBuffer(); pixelBuffer->lock(Ogre::HardwareBuffer::HBL_NORMAL); const Ogre::PixelBox& pixelBox = pixelBuffer->getCurrentLock(); Ogre::uint8* pDest = static_cast<Ogre::uint8*>(pixelBox.data); int x, y; for (x = 0; x < ImageSize.Width; x++) { for (y = 0; y < ImageSize.Height; y++) { *pDest++ = Image.getValue(x,y,2); // B *pDest++ = Image.getValue(x,y,1); // G *pDest++ = Image.getValue(x,y,0); // R *pDest++ = 255; // A } } pixelBuffer->unlock(); return true; }
void SourceTexture::Rectangle(int x, int y, int width, int height, unsigned long color) { Ogre::HardwarePixelBufferSharedPtr pixelBuffer = m_spTexture->getBuffer(); pixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD); const Ogre::PixelBox& pixelbox = pixelBuffer->getCurrentLock(); /*unsigned int dstBpp = Ogre::PixelUtil::getNumElemBytes(pixelbox.format); unsigned int dstPitch = pixelbox.rowPitch * dstBpp;*/ unsigned char *pImage = static_cast<unsigned char*>(pixelbox.data); int dst_width = pixelbox.getWidth(); unsigned char *pTmp = pImage + ( ( y*m_nWidth) + x )*4; for(int i = 0 ; i < width ; i++, pTmp += 4) { *(pTmp+0) = (unsigned char)(color >> 16); *(pTmp+1) = (unsigned char)(color >> 8); *(pTmp+2) = (unsigned char)(color); *(pTmp+3) = 255; } pTmp = pImage + ( ( (y+height-1)*m_nWidth) + x )*4; for(int i = 0 ; i < width ; i++, pTmp += 4) { *(pTmp+0) = (unsigned char)(color >> 16); *(pTmp+1) = (unsigned char)(color >> 8); *(pTmp+2) = (unsigned char)(color); *(pTmp+3) = 255; } pTmp = pImage + ( ( y*m_nWidth) + x )*4; for(int i = 0 ; i < height ; i++, pTmp += m_nWidth*4) { *(pTmp+0) = (unsigned char)(color >> 16); *(pTmp+1) = (unsigned char)(color >> 8); *(pTmp+2) = (unsigned char)(color); *(pTmp+3) = 255; } pTmp = pImage + ( ( y*m_nWidth) + x+width-1 )*4; for(int i = 0 ; i < height ; i++, pTmp += m_nWidth*4) { *(pTmp+0) = (unsigned char)(color >> 16); *(pTmp+1) = (unsigned char)(color >> 8); *(pTmp+2) = (unsigned char)(color); *(pTmp+3) = 255; } //m_spImageData->SetFlag(NxImageData::UPDATE_PIXEL); }
void UiManager::renderIntoTexture(const Ogre::TexturePtr &aTexture) { assert(!aTexture.isNull()); assert(isViewSizeMatching(aTexture)); Ogre::HardwarePixelBufferSharedPtr hwBuffer = aTexture->getBuffer(0, 0); hwBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD); const Ogre::PixelBox &pb = hwBuffer->getCurrentLock(); // render into texture buffer QImage textureImg((uchar *)pb.data, pb.getWidth(), pb.getHeight(), QImage::Format_ARGB32); textureImg.fill(0); QPainter painter(&textureImg); mWidgetView->render(&painter, QRect(QPoint(0, 0), mWidgetView->size()), QRect(QPoint(0, 0), mWidgetView->size())); hwBuffer->unlock(); }
//------------------------------------------------------------------------------ void OgreVideoTexture::_copyImagePerLine(const IplImage *_image ,Ogre::HardwarePixelBufferSharedPtr _pixelBuffer) { // Lock the pixel buffer and get a pixel box _pixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD); // for best performance use HBL_DISCARD! const Ogre::PixelBox& pixelBox = _pixelBuffer->getCurrentLock(); //Ogre::uint32* pDest = static_cast<Ogre::uint32*>(pixelBox.data); Ogre::uint8* pDest = static_cast<Ogre::uint8*>(pixelBox.data); for (size_t i = 0 ; i < _image->height ; i++) { memcpy(pDest + i*1024*4 , (_image->imageData) + i*_image->width * 3 , _image->width * 3); } _pixelBuffer->unlock(); }
void DirectShowMovieTexture::cleanTextureContents() { unsigned int idx; int x, y; // OGRE TEXTURE LOCK // get the texture pixel buffer int texw=mTexture->getWidth(); int texh=mTexture->getHeight(); Ogre::HardwarePixelBufferSharedPtr pixelBuffer = mTexture->getBuffer(); // lock the pixel buffer and get a pixel box pixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD); const Ogre::PixelBox& pixelBox = pixelBuffer->getCurrentLock(); Ogre::uint8* pDest = static_cast<Ogre::uint8*>(pixelBox.data); // FILL! for (x=0, y=0; y<texh; ){ idx=(x*4)+y*pixelBox.rowPitch*4; // paint pDest[idx]=0;//b pDest[idx+1]=0;//g pDest[idx+2]=0;//r pDest[idx+3]=255;//a x++; if (x>=texw) { x=0; y++; } } // UNLOCK EVERYTHING! // unlock the pixel buffer pixelBuffer->unlock(); // OGRE END }
//----------------------------------------------------------------------- CoherentUIView::CoherentUIView(Ogre::CoherentUIViewListener* listener, int width, int height, bool enableDepthWrite) : mView(NULL) { mViewListener = OGRE_NEW CoherentUIViewListenerBridge(this, listener); static int _textureCounter = 0; Ogre::StringStream ss; ss << "CoherentDynamicTexture" << ++_textureCounter; Ogre::String textureName = ss.str(); ss << "_Mat"; Ogre::String materialName = ss.str(); // Create a texture mTexture = TextureManager::getSingleton().createManual( textureName, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, width, height, 1, PF_BYTE_BGRA, TU_DYNAMIC_WRITE_ONLY_DISCARDABLE); // Clear the texture Ogre::HardwarePixelBufferSharedPtr pixelBuffer = mTexture->getBuffer(); pixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD); const Ogre::PixelBox& pixelBox = pixelBuffer->getCurrentLock(); Ogre::uint32* dest = static_cast<Ogre::uint32*>(pixelBox.data); std::memset(dest, 0, (width * 4 + pixelBox.getRowSkip()) * height); pixelBuffer->unlock(); // Create a material using the texture mTextureMaterial = MaterialManager::getSingleton().create( materialName, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); mTextureMaterial->getTechnique(0)->getPass(0)->createTextureUnitState(textureName); mTextureMaterial->getTechnique(0)->getPass(0)->setSceneBlending(SBF_ONE, SBF_ONE_MINUS_SOURCE_ALPHA); mTextureMaterial->getTechnique(0)->getPass(0)->setDepthWriteEnabled(enableDepthWrite); }
void test(const std::vector<std::vector<TxzFileSerializer::rgba>>& data) { //Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().load("clf_l.png.png", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); // kWorldResourceGroup Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().createManual("BackgroundTex", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, 640, 256, 0, Ogre::PF_B8G8R8, Ogre:: TU_DYNAMIC); Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create("BackgroundMat",Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); material->getTechnique(0)->getPass(0)->createTextureUnitState("BackgroundTex"); //material->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_COLOUR); Ogre::HardwarePixelBufferSharedPtr pixelBuffer = texture->getBuffer(); pixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD); const Ogre::PixelBox& pixelBox = pixelBuffer->getCurrentLock(); Ogre::uint8* pDest = static_cast<Ogre::uint8*>(pixelBox.data); for(size_t i=0; i < 256; i++) { for(size_t j=0; j < 640; j++) { *pDest++ = data[i][j].b; *pDest++ = data[i][j].g; *pDest++ = data[i][j].r; *pDest++ = 0; } } pixelBuffer->unlock(); }
/*! Get the result of the rendering loop. \param I : The image on which to copy the result of the rendering loop. \param cMo : The desired camera pose. */ void vpAROgre::getRenderingOutput(vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo) { updateCameraParameters(cMo); Ogre::TexturePtr dynTexPtr = Ogre::TextureManager::getSingleton().getByName("rtf"); //#if ( OGRE_VERSION >= (1 << 16 | 9 << 8 | 0) ) // .dynamicCast<Ogre::Texture>(); //#else // ; //#endif Ogre::RenderTexture* RTarget = dynTexPtr->getBuffer()->getRenderTarget(); mWindow->update(); RTarget->update(); if(I.getHeight() != mWindow->getHeight() || I.getWidth() != mWindow->getWidth()){ I.resize(mWindow->getHeight(), mWindow->getWidth()); } Ogre::HardwarePixelBufferSharedPtr mPixelBuffer = dynTexPtr->getBuffer(); mPixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD); const Ogre::PixelBox& pixelBox = mPixelBuffer->getCurrentLock(); dynTexPtr->getBuffer()->blitToMemory(pixelBox); Ogre::uint8* pDest = static_cast<Ogre::uint8*>(pixelBox.data); #if 1 // if texture in BGRa format for(unsigned int i=0; i<I.getHeight(); i++){ for(unsigned int j=0; j<I.getWidth(); j++){ // Color Image I[i][j].B = *pDest++; // Blue component I[i][j].G = *pDest++; // Green component I[i][j].R = *pDest++; // Red component I[i][j].A = *pDest++; // Alpha component } } #else // if texture in RGBa format which is the format of the input image memcpy(I.bitmap, pDest, I.getHeight()*I.getWidth()*sizeof(vpRGBa)); #endif // Unlock the pixel buffer mPixelBuffer->unlock(); }
void DirectShowMovieTexture::updateMovieTexture() { HRESULT hr; unsigned int i, idx; int x, y; BYTE* bmpTmp; // only do this if there is a graph that has been set up if (!dsdata->pGraph) return; // Find the required buffer size. long cbBuffer = 0; hr = dsdata->pGrabber->GetCurrentBuffer(&cbBuffer, NULL); if (cbBuffer<=0) { // nothing to do here yet return; } char *pBuffer = new char[cbBuffer]; if (!pBuffer) { // out of memory! throw("[DSHOW] Out of memory or empty buffer"); } hr = dsdata->pGrabber->GetCurrentBuffer(&cbBuffer, (long*)pBuffer); if (hr==E_INVALIDARG || hr==VFW_E_NOT_CONNECTED || hr==VFW_E_WRONG_STATE) { // we aren't buffering samples yet, do nothing delete[] pBuffer; return; } if (FAILED(hr)) throw("[DSHOW] Failed at GetCurrentBuffer!"); // OGRE BEGIN // OGRE TEXTURE LOCK // get the texture pixel buffer int texw=mTexture->getWidth(); int texh=mTexture->getHeight(); Ogre::HardwarePixelBufferSharedPtr pixelBuffer = mTexture->getBuffer(); bmpTmp=(BYTE*)pBuffer; // lock the pixel buffer and get a pixel box pixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD); const Ogre::PixelBox& pixelBox = pixelBuffer->getCurrentLock(); Ogre::uint8* pDest = static_cast<Ogre::uint8*>(pixelBox.data); // FILL! // check for mirroring... bool shouldBeMirrored=mHorizontalMirroring; if (shouldBeMirrored){ x=dsdata->videoWidth-1; y=dsdata->videoHeight-1; }else{ x=0; y=dsdata->videoHeight-1; } // go set all bits... for (i=0; i<(dsdata->videoWidth*dsdata->videoHeight*3); i+=3){ idx=(x*4)+y*pixelBox.rowPitch*4; // paint pDest[idx]=bmpTmp[i];//b pDest[idx+1]=bmpTmp[i+1];//g pDest[idx+2]=bmpTmp[i+2];//r pDest[idx+3]=255;//a if (shouldBeMirrored){ x--; if (x<0){ x=dsdata->videoWidth-1; y--; if (y<0) y=0; } }else{ x++; if (x>=dsdata->videoWidth){ x=0; y--; if (y<0) y=0; } } } // UNLOCK EVERYTHING! // unlock the pixel buffer pixelBuffer->unlock(); // OGRE END // bye delete[] pBuffer; }
int main( int argc, char *argv[] ) { Ogre::Root* root; Ogre::RenderWindow* window; root = new Ogre::Root( "", "" ); #ifndef _DEBUG root->loadPlugin( "RenderSystem_GL.dll" ); #else root->loadPlugin( "RenderSystem_GL_d.dll" ); #endif root->setRenderSystem( root->getAvailableRenderers()[ 0 ] ); root->initialise( false ); Ogre::NameValuePairList misc; misc[ "title" ] = "FFVII Exporter"; window = root->createRenderWindow( "QGearsWindow", 800, 600, false, &misc ); FILESYSTEM = new FileSystem(); LOGGER = new Logger( "game.log" ); state = GAME; { BinGZipFile* file = new BinGZipFile( "data/en/WINDOW.BIN" ); File* font_graf = file->ExtractGZip( 1 ); File* font_padding = file->ExtractGZip( 2 ); FontFile font( font_padding ); font.Export( "export_en/ui/fonts/ffvii_en.xml", true ); //font_graf->WriteFile( "font.tim" ); Vram* vram = new Vram(); LoadTimFileToVram( font_graf, 0, vram ); //vram->Save( "text" ); Ogre::TexturePtr ptex; Ogre::HardwarePixelBufferSharedPtr buffer; ptex = Ogre::TextureManager::getSingleton().createManual( "DynaTex", "General", Ogre::TEX_TYPE_2D, 256, 256, 0, Ogre::PF_R8G8B8A8, Ogre::TU_STATIC ); buffer = ptex->getBuffer( 0, 0 ); buffer->lock( Ogre::HardwareBuffer::HBL_DISCARD ); const Ogre::PixelBox& pb = buffer->getCurrentLock(); CreateTextureFromVram( pb, vram, 0, 0, 0x80, 0x1f7, 0x380, 0x100, BPP_4 , false ); Ogre::Image image; image.loadDynamicImage( ( Ogre::uchar* )pb.data, 256, 256, Ogre::PF_R8G8B8A8 ); image.save( "export_en/ui/fonts/ffvii_en.png" ); buffer->unlock(); delete vram; delete file; } { BinGZipFile* file = new BinGZipFile( "data/jp/WINDOW.BIN" ); File* font_graf = file->ExtractGZip( 1 ); File* font_graf2 = file->ExtractGZip( 2 ); File* font_padding = file->ExtractGZip( 3 ); font_padding->WriteFile( "font_padding.dat" ); FontFile font( font_padding ); font.Export( "export_jp/ui/fonts/ffvii_jp.xml", false ); font_graf->WriteFile( "font.tim" ); font_graf2->WriteFile( "font2.tim" ); Vram* vram = new Vram(); LoadTimFileToVram( font_graf, 0, vram ); LoadTimFileToVram( font_graf2, 0, vram ); //vram->Save( "text" ); Ogre::TexturePtr ptex; Ogre::HardwarePixelBufferSharedPtr buffer; ptex = Ogre::TextureManager::getSingleton().createManual( "DynaTex", "General", Ogre::TEX_TYPE_2D, 512, 256, 0, Ogre::PF_R8G8B8A8, Ogre::TU_STATIC ); buffer = ptex->getBuffer( 0, 0 ); buffer->lock( Ogre::HardwareBuffer::HBL_DISCARD ); const Ogre::PixelBox& pb = buffer->getCurrentLock(); CreateTextureFromVram( pb, vram, 0, 0, 0x80, 0x1f7, 0x380, 0x100, BPP_4 , false ); CreateTextureFromVram( pb, vram, 256, 0, 0x90, 0x1f7, 0x380, 0x100, BPP_4 , false ); Ogre::Image image; image.loadDynamicImage( ( Ogre::uchar* )pb.data, 512, 256, Ogre::PF_R8G8B8A8 ); image.save( "export_jp/ui/fonts/ffvii_jp.png" ); buffer->unlock(); delete vram; delete file; } { File sword( "sword.tim" ); Vram* vram = new Vram(); LoadTimFileToVram( &sword, 0, vram ); //vram->Save( "sword" ); Ogre::TexturePtr ptex; Ogre::HardwarePixelBufferSharedPtr buffer; ptex = Ogre::TextureManager::getSingleton().createManual( "DynaTex", "General", Ogre::TEX_TYPE_2D, 256, 256, 0, Ogre::PF_R8G8B8A8, Ogre::TU_STATIC ); buffer = ptex->getBuffer( 0, 0 ); buffer->lock( Ogre::HardwareBuffer::HBL_DISCARD ); const Ogre::PixelBox& pb = buffer->getCurrentLock(); CreateTextureFromVram( pb, vram, 0, 0, 0x0, 0x1e0, 0x0, 0x0, BPP_8 , false ); Ogre::Image image; image.loadDynamicImage( ( Ogre::uchar* )pb.data, 256, 256, Ogre::PF_R8G8B8A8 ); image.save( "sword.png" ); buffer->unlock(); delete vram; } LOGGER->Log("===================== Stop the game!!!"); delete FILESYSTEM; delete LOGGER; delete root; return 0; }
void SourceTexture::DrawImageFlipY(const unsigned char *pSrcImg, int x, int y, int width, int height, int sx, int sy, int src_width, int src_height) { if(x < 0) { width += x; sx -= x; x = 0; } if(y < 0) { height += y; sy -= y; y = 0; } if(x + width > m_nWidth) width = m_nWidth - x; if(sx + width > src_width) width = src_width - sx; if(y + height > m_nHeight) height = m_nHeight-y; if(sy + height > src_height) height = src_height - sy; Ogre::HardwarePixelBufferSharedPtr pixelBuffer = m_spTexture->getBuffer(); pixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD); const Ogre::PixelBox& pixelbox = pixelBuffer->getCurrentLock(); /*unsigned int dstBpp = Ogre::PixelUtil::getNumElemBytes(pixelbox.format); unsigned int dstPitch = pixelbox.rowPitch * dstBpp;*/ unsigned char *pDstImg = static_cast<unsigned char*>(pixelbox.data); memset(pDstImg, 0, m_nWidth*m_nHeight*4); if(x + width > m_nWidth) width = m_nWidth - x; if(y + height > m_nHeight) height = m_nHeight - y; // nothing to draw if(width <= 0 || height <= 0) return; #if 1 for(int i = 0; i < height; i++) { unsigned char *pDstTmp = (pDstImg + (x + (y + i) * m_nWidth) * 4); const unsigned char *pSrcTmp = (pSrcImg + (sx + (src_height - sy - i -1) * src_width) * 4); for(int j = 0 ; j < width ; j++) { if( pSrcTmp[0] || pSrcTmp[1] || pSrcTmp[2] ) { pDstTmp[0] = pSrcTmp[0]; pDstTmp[1] = pSrcTmp[1]; pDstTmp[2] = pSrcTmp[2]; pDstTmp[3] = 0xff; } pDstTmp += 4; pSrcTmp += 4; } } #else for( int i = 0 ; i < height*width ; i++ ) { *(pDstImg + i*4 + 0 ) = ((i+(i/width))%2)*255; *(pDstImg + i*4 + 1 ) = ((i+(i/width))%2)*255; *(pDstImg + i*4 + 2 ) = ((i+(i/width))%2)*255; *(pDstImg + i*4 + 3 ) = 255; } #endif pixelBuffer->unlock(); //m_spImageData->SetFlag(NxImageData::UPDATE_PIXEL); }
//------------------------------------------------------ void TextureAtlas::build() { if (!mIsDirty) return; bool fitted; size_t area = 0; // build the fonts (if this didn't happen already) // so we'll be sure the glyphs are there to be atlassed FontSet::iterator fit = mMyFonts.begin(); while (fit != mMyFonts.end()) { FontDrawSource* fdsp = *fit++; if (!fdsp->isBuilt()) fdsp->build(); } // First, we sort by size of the DrawSource mMyDrawSources.sort(DrawSourceLess()); // now try to allocate all the draw sources. If we fail, grow and try again do { fitted = true; area = 0; // try to fit DrawSourceList::iterator it = mMyDrawSources.begin(); while (it != mMyDrawSources.end()) { const DrawSourcePtr& ds = *it++; const PixelSize& ps = ds->getPixelSize(); area += ps.getPixelArea(); LOG_VERBOSE("TextureAtlas: (%s) Trying to place %d x %d (%d -> %d)", mAtlasName.c_str(), ps.width, ps.height, ps.getPixelArea(), area); // try to allocate FreeSpaceInfo* fsi = mAtlasAllocation->allocate(ps.width, ps.height); if (fsi) { ds->setPlacementPtr(fsi); } else { fitted = false; break; } } // fitted? if (!fitted) // nope - Enlarge! enlarge(area); } while (!fitted); LOG_INFO("TextureAtlas: (%s) Creating atlas with dimensions %d x %d", mAtlasName.c_str(), mAtlasSize.width, mAtlasSize.height); if (mTexture.isNull()) prepareResources(); // TODO: Reallocate the texture here if needed! Ogre::HardwarePixelBufferSharedPtr pixelBuffer = mTexture->getBuffer(); pixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD); const Ogre::PixelBox& targetBox = pixelBuffer->getCurrentLock(); size_t pixelsize = Ogre::PixelUtil::getNumElemBytes(targetBox.format); size_t rowsize = targetBox.rowPitch * pixelsize; Ogre::uint8* dstData = static_cast<Ogre::uint8*>(targetBox.data); // We'll iterate over all draw sources, painting the pixels onto the allocated space DrawSourceList::iterator it = mMyDrawSources.begin(); while (it != mMyDrawSources.end()) { const DrawSourcePtr& ds = *it++; // render all pixels into the right place FreeSpaceInfo* fsi = reinterpret_cast<FreeSpaceInfo*>(ds->getPlacementPtr()); assert(fsi); // render into the specified place unsigned char* conversionBuf = NULL; const PixelSize& dps = ds->getPixelSize(); Ogre::Image* img = ds->getImage(); Ogre::PixelBox srcPixels = img->getPixelBox(); // convert if the source data don't match if(img->getFormat() != Ogre::PF_BYTE_BGRA) { conversionBuf = new unsigned char[img->getWidth() * img->getHeight() * pixelsize]; Ogre::PixelBox convPixels(Ogre::Box(0, 0, dps.width, dps.height), Ogre::PF_BYTE_BGRA, conversionBuf); Ogre::PixelUtil::bulkPixelConversion(srcPixels, convPixels); srcPixels = convPixels; } size_t srcrowsize = srcPixels.rowPitch * pixelsize; Ogre::uint8* srcData = static_cast<Ogre::uint8*>(srcPixels.data); // TODO: we're always handling 32bit data, so we could as well transfer 4 bytes each iteration instead of one (speedup) for(size_t row = 0; row < dps.height; row++) { for(size_t col = 0; col < srcrowsize; col++) { dstData[((row + fsi->y) * rowsize) + (fsi->x * pixelsize) + col] = srcData[(row * srcrowsize) + col]; } } delete[] conversionBuf; // Convert the full draw source pixel coordinates to the atlas contained ones (initializes the texturing coordinates transform) ds->atlas(mMaterial, fsi->x, fsi->y, mAtlasSize.width, mAtlasSize.height); } // for debug, write the texture to a file /*unsigned char *readrefdata = static_cast<unsigned char*>(targetBox.data); Ogre::Image img; img = img.loadDynamicImage (readrefdata, mTexture->getWidth(), mTexture->getHeight(), mTexture->getFormat()); img.save(mAtlasName + ".png");*/ // and close the pixel buffer of the atlas at the end pixelBuffer->unlock(); mIsDirty = false; }
void CompoundCloudSystem::update(int renderTime, int) { //auto start = std::chrono::high_resolution_clock::now(); // Get the player's position. playerNode = static_cast<OgreSceneNodeComponent*>(gameState->entityManager().getComponent( Entity(gameState->engine().playerData().playerName(), gameState).id(), OgreSceneNodeComponent::TYPE_ID)); // If the player moves out of the current grid, move the grid. if (playerNode->m_transform.position.x > offsetX + width/3*gridSize/2 || playerNode->m_transform.position.y > offsetY + height/3*gridSize/2 || playerNode->m_transform.position.x < offsetX - width/3*gridSize/2 || playerNode->m_transform.position.y < offsetY - height/3*gridSize/2) { if (playerNode->m_transform.position.x > offsetX + width/3*gridSize/2 ) offsetX += width/3*gridSize; if (playerNode->m_transform.position.y > offsetY + height/3*gridSize/2) offsetY += height/3*gridSize; if (playerNode->m_transform.position.x < offsetX - width/3*gridSize/2 ) offsetX -= width/3*gridSize; if (playerNode->m_transform.position.y < offsetY - height/3*gridSize/2) offsetY -= height/3*gridSize; compoundCloudsPlane->getParentSceneNode()->setPosition(offsetX, offsetY, -1.0); } // For all newly created entities, initialize their parameters. for (auto& value : m_impl->m_compounds.addedEntities()) { CompoundCloudComponent* compoundCloud = std::get<0>(value.second); // Set the size of each grid tile and its position. compoundCloud->width = width; compoundCloud->height = height; compoundCloud->offsetX = offsetX; compoundCloud->offsetY = offsetY; compoundCloud->gridSize = gridSize; compoundCloud->density.resize(width, std::vector<float>(height, 0)); compoundCloud->oldDens.resize(width, std::vector<float>(height, 0)); // Modifies the material to draw this compound cloud in addition to the others. Ogre::MaterialPtr materialPtr = Ogre::MaterialManager::getSingleton().getByName("CompoundClouds", "General"); Ogre::Pass* pass = materialPtr->getTechnique(0)->createPass(); pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA); pass->setVertexProgram("CompoundCloud_VS"); pass->setFragmentProgram("CompoundCloud_PS"); //Ogre::TexturePtr texturePtr = Ogre::TextureManager::getSingleton().load(compoundCloud->compound + ".bmp", "General"); Ogre::TexturePtr texturePtr = Ogre::TextureManager::getSingleton().createManual(CompoundRegistry::getCompoundInternalName(compoundCloud->m_compoundId), "General", Ogre::TEX_TYPE_2D, width, height, 0, Ogre::PF_BYTE_BGRA, Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE); Ogre::HardwarePixelBufferSharedPtr cloud; cloud = texturePtr->getBuffer(); cloud->lock(Ogre::HardwareBuffer::HBL_DISCARD); const Ogre::PixelBox& pixelBox = cloud->getCurrentLock(); uint8_t* pDest = static_cast<uint8_t*>(pixelBox.data); // Fill in some pixel data. This will give a semi-transparent blue, // but this is of course dependent on the chosen pixel format. for (int i = 0; i < width; i++) { for(int j = 0; j < height; j++) { // Set the colors in Blue, Green, Red, Alpha format. *pDest++ = compoundCloud->color.b; *pDest++ = compoundCloud->color.g; *pDest++ = compoundCloud->color.r; *pDest++ = 0; } pDest += pixelBox.getRowSkip() * Ogre::PixelUtil::getNumElemBytes(pixelBox.format); } // Unlock the pixel buffer cloud->unlock(); pass->createTextureUnitState(CompoundRegistry::getCompoundInternalName(compoundCloud->m_compoundId)); texturePtr = Ogre::TextureManager::getSingleton().load("PerlinNoise.jpg", "General"); pass->createTextureUnitState()->setTexture(texturePtr); compoundCloudsPlane->getSubEntity(0)->setCustomParameter(1, Ogre::Vector4(0.0f, 0.0f, 0.0f, 0.0f)); } // Clear the list of newly added entities so that we don't reinitialize them next frame. m_impl->m_compounds.clearChanges(); // For all types of compound clouds... for (auto& value : m_impl->m_compounds) { CompoundCloudComponent* compoundCloud = std::get<0>(value.second); // If the offset of the compound cloud is different from the fluid systems offset, // then the player must have moved, so we need to adjust the texture. if (compoundCloud->offsetX != offsetX || compoundCloud->offsetY != offsetY) { // If we moved up. if (compoundCloud->offsetX == offsetX && compoundCloud->offsetY < offsetY) { for (int x = 0; x < width; x++) { for (int y = 0; y < height/3; y++) { compoundCloud->density[x][y] = compoundCloud->density[x][y+height/3]; compoundCloud->density[x][y+height/3] = compoundCloud->density[x][y+height*2/3]; compoundCloud->density[x][y+height*2/3] = 0.0; } } Ogre::Vector4 offset = compoundCloudsPlane->getSubEntity(0)->getCustomParameter(1); compoundCloudsPlane->getSubEntity(0)->setCustomParameter(1, Ogre::Vector4(offset.x, offset.y-1.0f/3, 0.0f, 0.0f)); } // If we moved right. else if (compoundCloud->offsetX < offsetX && compoundCloud->offsetY == offsetY) { for (int x = 0; x < width/3; x++) { for (int y = 0; y < height; y++) { compoundCloud->density[x][y] = compoundCloud->density[x+height/3][y]; compoundCloud->density[x+height/3][y] = compoundCloud->density[x+height*2/3][y]; compoundCloud->density[x+height*2/3][y] = 0.0; } } Ogre::Vector4 offset = compoundCloudsPlane->getSubEntity(0)->getCustomParameter(1); compoundCloudsPlane->getSubEntity(0)->setCustomParameter(1, Ogre::Vector4(offset.x-1.0f/3, offset.y, 0.0f, 0.0f)); } // If we moved left. else if (compoundCloud->offsetX > offsetX && compoundCloud->offsetY == offsetY) { for (int x = 0; x < width/3; x++) { for (int y = 0; y < height; y++) { compoundCloud->density[x+height*2/3][y] = compoundCloud->density[x+height/3][y]; compoundCloud->density[x+height/3][y] = compoundCloud->density[x][y]; compoundCloud->density[x][y] = 0.0; } } Ogre::Vector4 offset = compoundCloudsPlane->getSubEntity(0)->getCustomParameter(1); compoundCloudsPlane->getSubEntity(0)->setCustomParameter(1, Ogre::Vector4(offset.x+1.0f/3, offset.y, 0.0f, 0.0f)); } // If we moved downwards. else if (compoundCloud->offsetX == offsetX && compoundCloud->offsetY > offsetY) { for (int x = 0; x < width; x++) { for (int y = 0; y < height/3; y++) { compoundCloud->density[x][y+height*2/3] = compoundCloud->density[x][y+height/3]; compoundCloud->density[x][y+height/3] = compoundCloud->density[x][y]; compoundCloud->density[x][y] = 0.0; } } Ogre::Vector4 offset = compoundCloudsPlane->getSubEntity(0)->getCustomParameter(1); compoundCloudsPlane->getSubEntity(0)->setCustomParameter(1, Ogre::Vector4(offset.x, offset.y+1.0f/3, 0.0f, 0.0f)); } compoundCloud->offsetX = offsetX; compoundCloud->offsetY = offsetY; } // Compound clouds move from area of high concentration to area of low. diffuse(.01, compoundCloud->oldDens, compoundCloud->density, renderTime); // Move the compound clouds about the velocity field. advect(compoundCloud->oldDens, compoundCloud->density, renderTime); // Store the pixel data in a hardware buffer for quick access. Ogre::HardwarePixelBufferSharedPtr cloud; cloud = Ogre::TextureManager::getSingleton().getByName(CompoundRegistry::getCompoundInternalName(compoundCloud->m_compoundId), "General")->getBuffer(); cloud->lock(Ogre::HardwareBuffer::HBL_DISCARD); const Ogre::PixelBox& pixelBox = cloud->getCurrentLock(); uint8_t* pDest = static_cast<uint8_t*>(pixelBox.data); pDest+=3; // Copy the density vector into the buffer. for (int j = 0; j < height; j++) { for(int i = 0; i < width; i++) { int intensity = static_cast<int>(compoundCloud->density[i][height-j-1]); if (intensity < 0) { intensity = 0; } else if (intensity > 255) { intensity = 255; } *pDest = intensity; // Alpha value of texture. pDest+=4; } pDest += pixelBox.getRowSkip() * Ogre::PixelUtil::getNumElemBytes(pixelBox.format); } // Unlock the pixel buffer. cloud->unlock(); } //auto end = std::chrono::high_resolution_clock::now(); //std::cout << "total: " << std::to_string(std::chrono::duration_cast<std::chrono::microseconds>(end-start).count()) << std::endl; }
Surface* FontFile::GetSurface(void) { int width = 512; int height = 4096; int chars = 0; int char_num = 6165; Surface* ret = CreateSurface(width, height); int x_16 = 0; int y_16 = 0; struct ClutColor { u8 r; /**< @brief red color in CLUT */ u8 g; /**< @brief green color in CLUT */ u8 b; /**< @brief blue color in CLUT */ u8 a; /**< @brief alpha in CLUT */ }; ClutColor color; color.r = 0; color.g = 0; color.b = 0; color.a = 255; u8 data = 0; for (int chars = 0; chars < char_num; ++chars) { Surface* glyth = CreateSurface(16, 16); for (int y = 0; y < 16; ++y) { data = (y < 11) ? GetU8(0xE + chars * 22 + y * 2 + 0) : 0; //LOGGER->Log(LOGGER_INFO, "%x, %02x", y, data); int j = 0; for (int i = 7; i >= 0; --i) { color.r = ((data >> i) & 0x01 == 1) ? 0 : 255; color.g = ((data >> i) & 0x01 == 1) ? 0 : 255; color.b = ((data >> i) & 0x01 == 1) ? 0 : 255; color.a = ((data >> i) & 0x01 == 1) ? 255 : 255; memcpy(glyth->pixels + 64 * y + j, &color, sizeof(ClutColor)); j += 4; } data = (y < 11) ? GetU8(0xE + chars * 22 + y * 2 + 1) : 0; //LOGGER->Log(LOGGER_INFO, "%02x", data); for (int i = 7; i >= 0; --i) { color.r = ((data >> i) & 0x01 == 1) ? 0 : 255; color.g = ((data >> i) & 0x01 == 1) ? 0 : 255; color.b = ((data >> i) & 0x01 == 1) ? 0 : 255; color.a = ((data >> i) & 0x01 == 1) ? 255 : 255; memcpy(glyth->pixels + 64 * y + j, &color, sizeof(ClutColor)); j += 4; } } CopyToSurface(ret, x_16, y_16, glyth); delete glyth; x_16 += 16; if (x_16 == ret->width) { y_16 += 16; x_16 = 0; } } Ogre::TexturePtr ptex; Ogre::HardwarePixelBufferSharedPtr buffer; ptex = Ogre::TextureManager::getSingleton().createManual("DynaTex", "General", Ogre::TEX_TYPE_2D, ret->width, ret->height, 0, Ogre::PF_R8G8B8A8, Ogre::TU_STATIC); buffer = ptex->getBuffer(0, 0); buffer->lock(Ogre::HardwareBuffer::HBL_DISCARD); const Ogre::PixelBox& pb = buffer->getCurrentLock(); for (Uint32 y = 0; y < ret->height; ++y) { Uint32* data = static_cast<Uint32*>(pb.data) + y * pb.rowPitch; for (Uint32 x = 0; x < ret->width; ++x) { Uint32 clut = ret->pixels[y * ret->width * 4 + x * 4 + 3] | (ret->pixels[y * ret->width * 4 + x * 4 + 2] << 8) | (ret->pixels[y * ret->width * 4 + x * 4 + 1] << 16) | (ret->pixels[y * ret->width * 4 + x * 4 + 0] << 24); data[x] = clut; } } Ogre::Image image; image.loadDynamicImage((Ogre::uchar*)pb.data, ret->width, ret->height, Ogre::PF_R8G8B8A8); image.save("font.png"); buffer->unlock(); Ogre::TextureManager::getSingleton().remove("DynaTex"); return ret; }
void _makeScene() { mCamera->setNearClipDistance(1); mCamera->setFarClipDistance(1000); // Create the texture Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().createManual( "DynamicTexture", // name Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, // type 128, 128, // width & height 0, // number of mipmaps Ogre::PF_BYTE_BGRA, // pixel format Ogre::TU_DEFAULT); // usage; should be TU_DYNAMIC_WRITE_ONLY_DISCARDABLE for // textures updated very often (e.g. each frame) // Get the pixel buffer Ogre::HardwarePixelBufferSharedPtr pixelBuffer = texture->getBuffer(); // Lock the pixel buffer and get a pixel box pixelBuffer->lock(Ogre::HardwareBuffer::HBL_NORMAL); // for best performance use HBL_DISCARD! const Ogre::PixelBox& pixelBox = pixelBuffer->getCurrentLock(); Ogre::uint8* pDest = static_cast<Ogre::uint8*>(pixelBox.data); // Fill in some pixel data. This will give a semi-transparent blue, // but this is of course dependent on the chosen pixel format. for (size_t j = 0; j < 128; j++) for(size_t i = 0; i < 128; i++) { *pDest++ = 82 + (Ogre::Math::Sin(i) + Ogre::Math::Cos(j) * 10.5); *pDest++ = 45 + (Ogre::Math::Cos(i) + Ogre::Math::Sin(j) * 10.5); *pDest++ = 128 + (Ogre::Math::Tan(i) + Ogre::Math::Cos(j) * 10.5); *pDest++ = 255; // A } // Unlock the pixel buffer pixelBuffer->unlock(); // Create a material using the texture Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create( "DynamicTextureMaterial", // name Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); Ogre::TextureUnitState* tus = material->getTechnique(0)->getPass(0)->createTextureUnitState("DynamicTexture"); tus->setScrollAnimation(0.005f, 0.0025f); tus->setRotateAnimation(0.009f); material->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA); Ogre::Plane plane(Ogre::Vector3::UNIT_Y, 0); Ogre::MeshManager::getSingleton().createPlane("ground", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, 1500, 1500, 1, 1, true, 1, 1, 1, Ogre::Vector3::UNIT_Z); Ogre::Entity* entGround = mSceneMgr->createEntity("GroundEntity", "ground"); mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entGround); entGround->setMaterialName("DynamicTextureMaterial"); entGround->setCastShadows(false); mCamera->setPosition(25,100,30); mCamera->lookAt(0,0,0); }
void TestGame::DrawPlanetMap(Logic::PlanetJustGenerateEvent *evnt){ std::map<Logic::BaseCountry*,std::vector<Logic::CountryTile>>::iterator CntrItr; std::vector<Logic::CountryTile>::iterator TileItr; int tilesize=TILESIZE; bool why; Ogre::Vector3 tempVect; int maxX = (int)Logic::BaseAsset::GetSigleton("MAP_X"),maxY=(int)Logic::BaseAsset::GetSigleton("MAP_Y"); Ogre::SceneNode* node,*capitalNode,*mapnode =mSceneMgr->getRootSceneNode()->createChildSceneNode("Map"); mapnode->translate(-maxX/2*tilesize,-maxY/2*tilesize,0); Ogre::Entity* entNinja = 0; Ogre::FontPtr font = Ogre::FontManager::getSingleton().getResourceIterator().begin()->second; // Make sure the texture is not WRITE_ONLY, we need to read the buffer to do the blending with the font (get the alpha for example) int j =0; for(CntrItr=evnt->allTiles.begin();CntrItr!=evnt->allTiles.end(); CntrItr++){ Ogre::ManualObject* manual = mSceneMgr->createManualObject("CountryObject"+CntrItr->first->mName); Ogre::Texture* texture = Ogre::TextureManager::getSingleton().createManual("CountryText"+CntrItr->first->mName,"General",Ogre::TEX_TYPE_2D,512, 512, 0, Ogre::PF_FLOAT32_RGBA , Ogre::TU_DEFAULT).getPointer(); Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create("CountryMaterial"+CntrItr->first->mName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); //Draw the background to the new texture Ogre::HardwarePixelBufferSharedPtr pixelBuffer = texture->getBuffer(); // Lock the pixel buffer and get a pixel box pixelBuffer->lock(Ogre::HardwareBuffer::HBL_NORMAL); // for best performance use HBL_DISCARD! const Ogre::PixelBox& pixelBox = pixelBuffer->getCurrentLock(); float *pDest = static_cast<float*>(pixelBox.data); Ogre::ColourValue *temp = &CntrItr->first->mColor; // Fill in some pixel data. This will give a semi-transparent blue, // but this is of course dependent on the chosen pixel format. for (size_t k = 0; k < 512; k++) for(size_t q = 0; q < 512; q++) { *pDest++ =temp->b; // B *pDest++ = temp->g; *pDest++ =temp->r; *pDest++ = 0; // A*/ /* *pDest++ = 255; // B *pDest++ = 0; // G *pDest++ = 0; // R *pDest++ = 127; // A*/ } // Unlock the pixel buffer pixelBuffer->unlock(); ///WriteToTexture(Logic::LogicStd::IntToString(j),Ogre::TexturePtr(texture),Ogre::Image::Box(25,275,370,500),font,Ogre::ColourValue(1.0,1.0,1.0,1.0),'c'); mat->getTechnique(0)->getPass(0)->createTextureUnitState("CountryText"+CntrItr->first->mName); // mat->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA); j++; // specify the material (by name) and rendering type manual->begin("CountryMaterial"+CntrItr->first->mName, Ogre::RenderOperation::OT_TRIANGLE_LIST); int i=0; for(TileItr= CntrItr->second.begin();TileItr!= CntrItr->second.end();TileItr++){ tempVect = calculateActualPointFromCenter(CntrItr->first->mCapital.mPosition,(*TileItr).mPosition); tempVect =tempVect*tilesize; manual->position(tempVect.x-tilesize/2,tempVect.y+tilesize/2,tempVect.z); //manual->colour(CntrItr->first->mColor); manual->position(tempVect.x+tilesize/2,tempVect.y+tilesize/2,tempVect.z); //manual->colour(CntrItr->first->mColor); manual->position(tempVect.x+tilesize/2,tempVect.y-tilesize/2,tempVect.z); //manual->colour(CntrItr->first->mColor); manual->position(tempVect.x-tilesize/2,tempVect.y-tilesize/2,tempVect.z); //manual->colour(CntrItr->first->mColor); manual->triangle(i*4+0,i*4+2,i*4+1); manual->triangle(i*4+0,i*4+3,i*4+2); //manual->quad(i*4+0,i*4+2,i*4+3,i*4+1); i++; } // tell Ogre, your definition has finished manual->end(); // add ManualObject to the RootSceneNode (so it will be visible) node =mapnode->createChildSceneNode(); entNinja= mSceneMgr->createEntity("Capital/"+CntrItr->first->mName, "capital.mesh"); entNinja->setCastShadows(true); entNinja->setMaterialName("CountryMaterial"+CntrItr->first->mName); Control::ClickHelper* helpr = new Control::ClickHelper(Logic::CHT_COUNTRY); helpr->target = CntrItr->first; entNinja->setUserAny(Ogre::Any(helpr)); CntrItr->first->mNode = node; capitalNode = node->createChildSceneNode(); capitalNode->attachObject(entNinja); capitalNode->pitch(Ogre::Degree(90)); node->attachObject(manual); // I move the SceneNode so that it is visible to the camera. tempVect = Ogre::Vector3(CntrItr->first->mCapital.mPosition.x*tilesize,CntrItr->first->mCapital.mPosition.y*tilesize,-10); node->translate(tempVect); } mapnode->pitch(Ogre::Degree(-45)); }