IImage* createRainbowImage( u32 w, u32 h, u8 transparency, f64 gamma) { // create image core::dimension2du size(w,h); IImage* img = (IImage*)new CImage(ECF_A8R8G8B8, size); if (!img) return 0; size = img->getDimension(); // loop pixels per col for (u32 y=0; y<size.Height; y++) { // calculate rainbow-color SColor c = createRainbowColor( y, size.Height, gamma); // set transparency c.setAlpha(transparency); // write one row with same color for (u32 x=0; x<size.Width; x++) { // write rainbow-color img->setPixel(x,y,c,false); } } return img; }
irr::video::ITexture* EffectHandler::generateRandomVectorTexture(const irr::core::dimension2du& dimensions, const irr::core::stringc& name) { IImage* tmpImage = driver->createImage(irr::video::ECF_A8R8G8B8, dimensions); srand(device->getTimer()->getRealTime()); for (u32 x = 0; x < dimensions.Width; ++x) { for (u32 y = 0; y < dimensions.Height; ++y) { vector3df randVec; // Reject vectors outside the unit sphere to get a uniform distribution. do { randVec = vector3df((f32)rand() / (f32)RAND_MAX, (f32)rand() / (f32)RAND_MAX, (f32)rand() / (f32)RAND_MAX); } while (randVec.getLengthSQ() > 1.0f); const SColorf randCol(randVec.X, randVec.Y, randVec.Z); tmpImage->setPixel(x, y, randCol.toSColor()); } } ITexture* randTexture = driver->addTexture(name, tmpImage); tmpImage->drop(); return randTexture; }
void CGWIC_Cell::SaveTerrainBitmap() { path flnm = GWIC_TERRAIN_DIR; flnm += (GetCellFileSuffix() + ".bmp"); dimension2d<u32> dim(256,256); IImage *img = irDriver->createImage(ECF_R8G8B8,dim); u32 VertexCount = terrain->getMesh()->getMeshBuffer(0)->getVertexCount(); S3DVertex2TCoords* verts = reinterpret_cast<S3DVertex2TCoords*> (terrain->getMesh()->getMeshBuffer(0)->getVertices()); S3DVertex2TCoords* vertex; u8 y; u32 x,z; for (u32 i=0; i<VertexCount; i++) { vertex = verts + i; x = static_cast<u32> (vertex->Pos.X); y = static_cast<u8> (vertex->Pos.Y); z = static_cast<u32> (vertex->Pos.Z); img->setPixel(x,z,SColor(0,y,y,y)); } irDriver->writeImageToFile(img,flnm,0); img->drop(); std::cout << "Cell " << posX << ';' << posY << " terrain bitmap saved!" << std::endl; }