Thanks to your answer but ,,, i don't understand how to change the pixel data of the texture ... I don't know any CImage.cpp and CNullDriver.cpp ( I am very bad )vitek wrote: Your code should look something like the makeColorKeyTexture code in CNullDriver.cpp. If you wanted to support scaling the texture, there is code for that in CImage.cpp.
this is my code :
Code: Select all
Imagebool=-1;
int lastFPS = -1;
ITexture * TextureWebcam = driver->addTexture(core::dimension2d<s32>(VMAX, HMAX), "My Webcam", video::ECF_A8R8G8B8); ;
IplImage * frame;
u32 now;
const u32 camera_fps = 30;
const u32 ms_at_camera_fps = 1000 / camera_fps;
u32 then = device->getTimer()->getRealTime();
IImage * ImageWebcam;
while(device->run())
if (device->isWindowActive())
{
//DraGon.BougeDragon(smgr, driver, dragon);
/** Dessin de la Scene **/
driver->beginScene(true, true, SColor(0,0,0,0));
smgr->drawAll();
if (Imagebool!=-1)
driver->draw2DImage(TextureWebcam, position2d<s32>(351, 30));
guienv->drawAll();
now = device->getTimer()->getRealTime();
if (ms_at_camera_fps < (now - then))
{
then = now;
void* lock = TextureWebcam->lock();
if (lock)
{
// Mise à jour des pixels de la texture
/** On Envoie La WebCam =D **/
RecupFrame(guienv,driver,smgr,device,capture,TextureWebcam,frame);
ImageWebcam=WebCam.AfficheImage(Image1,321,0,driver,TextureWebcam,ImageWebcam);
if (ImageWebcam!=NULL)
memcpy(lock, ImageWebcam, sizeof (ImageWebcam));
TextureWebcam->unlock();
}
}
driver->endScene();
/** Pour récuperer le FPS **/
int fps = driver->getFPS();
if (lastFPS != fps) // Pour eviter d'afficher toujours le meme FPS si celui ci reste inchangé
{
stringw str = L"Irrlicht Engine - BiGMaC's Adventure ["; str += driver->getName();str += "] FPS:";str += fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
Code: Select all
IImage * Webcam::AfficheImage(Image * ImageAAfficher, int x, int y, IVideoDriver* driver,ITexture * TextureWebcam,IImage * ImageWebcam)
{
int i, j;
LPBYTE DonneeWebcam = new BYTE[4*VMAX*HMAX];
// Parcoure le tbl
for(i=0; i<HMAX; i++)
for(j=0; j<VMAX; j++)
{
DonneeWebcam[4*VMAX*(HMAX-1-i)+4*j+2] = ImageAAfficher->Couleur(HMAX-i-1,j,'r');
DonneeWebcam[4*VMAX*(HMAX-1-i)+4*j+1] = ImageAAfficher->Couleur(HMAX-i-1,j,'g');
DonneeWebcam[4*VMAX*(HMAX-1-i)+4*j] = ImageAAfficher->Couleur(HMAX-i-1,j,'b');
}
ImageWebcam = driver->createImageFromData(ECF_A8R8G8B8, dimension2d<s32>(VMAX,HMAX), DonneeWebcam,true);
delete (DonneeWebcam);
return ImageWebcam;
}