multi window ?
multi window ?
I'd like to use two windows, displaying two viewport and don't know how to do ?
multi windows
Thanks a lot.
I managed to open 2 windows, but it don't works fine.
I tried to make a thread, with:
boost ::thread tache1 ( boost::bind ( &Moteur3D::run, moteur ) )but it don't work. Can you look at the code please ?
( i haven't put the mutex yet )
The code ( visual express ) :
Mioteur3D.h ( 3DEngine.h in english ) !
Moteur3D.cpp:
Main:
I managed to open 2 windows, but it don't works fine.
I tried to make a thread, with:
boost ::thread tache1 ( boost::bind ( &Moteur3D::run, moteur ) )but it don't work. Can you look at the code please ?
( i haven't put the mutex yet )
The code ( visual express ) :
Mioteur3D.h ( 3DEngine.h in english ) !
Code: Select all
#ifndef __Moteur3D__
#define __Moteur3D__
#include <conio.h>
#include <stdio.h>
#include <iostream>
#include <irrlicht.h>
#include <time.h>
#include <sys/timeb.h>
#include <boost/thread/thread.hpp>
#include <boost/bind.hpp>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#include "IEventReceiver.h"
#ifndef _IRR_WINDOWS_
#error Windows only example
#else
#pragma comment(lib, "Irrlicht.lib")
#include <windows.h> // this example only runs with windows
#endif
class Moteur3D {
IrrlichtDevice* device;
IVideoDriver* driver;
ISceneManager* smgr;
IAnimatedMesh* mesh ;
IAnimatedMeshSceneNode* node ;
IBillboardSceneNode* our_bill_node;
ICameraSceneNode* camera;
// ***
IrrlichtDevice* device2;
IVideoDriver* driver2;
ISceneManager* smgr2;
IAnimatedMesh* mesh2 ;
IAnimatedMeshSceneNode* node2 ;
IBillboardSceneNode* our_bill_node2;
ICameraSceneNode* camera2;
double last_time ;
double add_on_time , add_on_time2;
bool running;
HWND hIrrlichtWindow;
HWND hIrrlichtWindow2;
irr::SIrrlichtCreationParameters param;
irr::SIrrlichtCreationParameters param2;
public:
static LRESULT CALLBACK CustomWndProc(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK CustomWndProc2(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam);
Moteur3D ();
void setMesh( int numCamera, std::string nomMesh, std::string nomTexture ) ;
void drop ();
void setBillBoard (int numCam, dimension2d<f32> dim, irr::core::vector3df pos );
void setCamera (int numCamera, irr::core::vector3df pos, irr::core::vector3df target);
void run ();
double current_time ();
void startStop ();
bool isRunning ();
};
#endif
Code: Select all
#include "moteur3D.h"
LRESULT CALLBACK Moteur3D::CustomWndProc(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_COMMAND:
{
HWND hwndCtl = (HWND)lParam;
int code = HIWORD(wParam);
/* if (hwndCtl == hOKButton) {
DestroyWindow(hWnd);
PostQuitMessage(0);
return 0;
} */
}
break;
case WM_DESTROY:
exit(0);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, message, wParam, lParam);
};
LRESULT CALLBACK Moteur3D::CustomWndProc2(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_COMMAND:
{
HWND hwndCtl = (HWND)lParam;
int code = HIWORD(wParam);
/* if (hwndCtl == hOKButton)
{
DestroyWindow(hWnd);
PostQuitMessage(0);
return 0;
}
*/
}
break;
case WM_DESTROY:
exit(0);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, message, wParam, lParam);
};
void Moteur3D::run () {
if ( !device ) return;
if ( !device2 ) return;
while ( running )
{
if (device->run() )
{
driver2->beginScene(true, true, SColor(255,100,101,140), param2.WindowId);
smgr2->setActiveCamera(camera2);
smgr2->drawAll();
driver2->endScene();
//device ->sleep(10 );
}
if (device2->run() )
{
driver->beginScene(true, true, SColor(255,100,101,140), param.WindowId);
smgr->setActiveCamera(camera);
smgr->drawAll();
driver->endScene();
//device2 ->sleep(10);
}
}
}
Moteur3D::Moteur3D ()
{
// variables pour la création des fenetres :
HINSTANCE hInstance = 0;
const char* Win32ClassName = "Fenetre1";
const char* Win32ClassName2 = "Fenetre2";
HINSTANCE hInstance2 = 0;
WNDCLASSEX wcex;
WNDCLASSEX wcex2;
DWORD style = WS_SYSMENU | WS_BORDER | WS_CAPTION |
WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SIZEBOX;
int windowWidth = 440;
int windowHeight = 380;
// Première fenêtre :
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = reinterpret_cast<WNDPROC> (CustomWndProc) ;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = DLGWINDOWEXTRA;
wcex.hInstance = hInstance;
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW);
wcex.lpszMenuName = 0;
wcex.lpszClassName = Win32ClassName;
wcex.hIconSm = 0;
RegisterClassEx(&wcex);
hIrrlichtWindow = CreateWindow( Win32ClassName, "Irrlicht 1",
style, 100, 100, windowWidth, windowHeight,
NULL, NULL, hInstance, NULL);
// Seconde fenêtre :
wcex2.cbSize = sizeof(WNDCLASSEX);
wcex2.style = CS_HREDRAW | CS_VREDRAW;
wcex2.lpfnWndProc = reinterpret_cast<WNDPROC> (CustomWndProc2) ;
wcex2.cbClsExtra = 0;
wcex2.cbWndExtra = DLGWINDOWEXTRA;
wcex2.hInstance = hInstance2;
wcex2.hIcon = NULL;
wcex2.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex2.hbrBackground = (HBRUSH)(COLOR_WINDOW);
wcex2.lpszMenuName = 0;
wcex2.lpszClassName = Win32ClassName2;
wcex2.hIconSm = 0;
RegisterClassEx(&wcex2);
hIrrlichtWindow2 = CreateWindow( Win32ClassName2, "Irrlicht 2",
style, 100, 100, windowWidth, windowHeight,
NULL, NULL, hInstance2, NULL);
// Premier device :
param.WindowId = reinterpret_cast<void*>(hIrrlichtWindow);
param.DriverType = video::EDT_OPENGL;
device = irr::createDeviceEx(param);
if ( !device )
return;
else {
driver = device->getVideoDriver();
smgr = device->getSceneManager();
std::cout << "\nMoteur 1 lance\n";
}
// Second device :
param2.WindowId = reinterpret_cast<void*>(hIrrlichtWindow2);
param2.DriverType = video::EDT_DIRECT3D8;
device2 = irr::createDeviceEx(param2);
if ( !device2 )
return;
else {
driver2 = device2->getVideoDriver();
smgr2 = device2->getSceneManager();
std::cout << "\nMoteur 2 lance\n";
}
// Affichage des fenêtres:
ShowWindow(hIrrlichtWindow , SW_SHOW);
UpdateWindow(hIrrlichtWindow);
ShowWindow(hIrrlichtWindow2 , SW_SHOW);
UpdateWindow(hIrrlichtWindow2);
last_time = current_time();
add_on_time = 0;
add_on_time2 = 0;
running = true; // Démarre par défaut !
}
void Moteur3D ::setMesh( int numCamera, std::string nomMesh, std::string nomTexture )
{
if (numCamera == 1 )
{
if ( !device ) return;
mesh = smgr->getMesh(nomMesh.c_str() );
node = smgr->addAnimatedMeshSceneNode( mesh );
if (node)
{
node->setMaterialFlag ( EMF_LIGHTING, false);
node->setMD2Animation ( scene::EMAT_STAND );
node->setMaterialTexture ( 0, driver->getTexture(nomTexture.c_str() ) );
}
//node ->setPosition( irr::core::vector3df ( 0,0,0) );
}
if (numCamera == 2 )
{
if ( !device2 ) return;
mesh2 = smgr2->getMesh(nomMesh.c_str() );
node2 = smgr2->addAnimatedMeshSceneNode( mesh2 );
if (node2) {
node2->setMaterialFlag ( EMF_LIGHTING, false);
node2->setMD2Animation ( scene::EMAT_STAND );
node2->setMaterialTexture ( 0, driver2->getTexture(nomTexture.c_str() ) );
}
// node2 ->setPosition( irr::core::vector3df ( 0,0,0) );
}
}
void Moteur3D ::setBillBoard (int numCam, dimension2d<f32> dims, irr::core::vector3df pos )
{
if ( numCam == 1 )
if ( !device )
return;
else {
our_bill_node = smgr->addBillboardSceneNode(NULL, dims, pos);
our_bill_node->setMaterialFlag(video::EMF_LIGHTING, false);
}
if ( numCam == 2 )
if ( !device2 )
return;
else {
our_bill_node2 = smgr2->addBillboardSceneNode(NULL, dims, pos);
our_bill_node2->setMaterialFlag(video::EMF_LIGHTING, false);
}
}
void Moteur3D ::setCamera (int numCamera, irr::core::vector3df pos, irr::core::vector3df target)
{
/*
Position et cible.
*/
if ( !device ) return;
camera = smgr->addCameraSceneNode();
camera->setPosition(pos);
camera->setTarget(target);
if ( !device2 ) return;
camera2 = smgr->addCameraSceneNode();
camera2->setPosition(pos);
camera2->setTarget(target);
}
//this function brings back seconds with milliseconds since it was first called
double Moteur3D ::current_time()
{
static int first_sec = 0;
static int first_msec = 0;
struct timeb new_time;
//set current time
ftime(&new_time);
//set if not set
if(!first_sec)
{
first_sec = new_time.time;
first_msec = new_time.millitm;
}
return (new_time.time - first_sec) + ((new_time.millitm - first_msec) * 0.001);
}
void Moteur3D ::startStop ( )
{
if ( running)
running = true;
else
running = false ;
}
bool Moteur3D ::isRunning ()
{
return running;
}
void Moteur3D ::drop()
{
if ( !device ) return;
device ->drop();
if ( !device2 ) return;
device2->drop();
}
Code: Select all
#include "moteur3D.h"
#include <boost/thread/thread.hpp>
#include <boost/thread/tss.hpp>
#include <boost/thread/xtime.hpp>
#include <boost/bind.hpp>
#include <vector>
#include <iostream>
#ifndef _IRR_WINDOWS_
#error Windows only example
#else
#pragma comment(lib, "Irrlicht.lib")
#include <windows.h> // this example only runs with windows
// #pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif
int main()
{
Moteur3D * moteur = new Moteur3D();
moteur->setBillBoard (1 , dimension2d<f32> ( 25.0f, 25.0f ) , irr::core::vector3df ( -30,0,0) ) ;
moteur->setBillBoard (2 , dimension2d<f32> ( 25.0f, 25.0f ) , irr::core::vector3df ( -30,0,0) ) ;
moteur->setCamera( 1, irr::core::vector3df(0, 0,100 ) , irr::core::vector3df (0,0,0));
moteur->setCamera( 2, irr::core::vector3df(0, 0,100 ) , irr::core::vector3df (0,0,0));
moteur->setMesh( 2, "../bin/media/sydney.md2", "../media/sydney.bmp" ) ;
moteur->setMesh( 1, "../bin/media/faerie.md2", "../media/faerie2.bmp" ) ;
//boost ::thread tache1 ( boost::bind ( &Moteur3D::run, moteur ) );
// boost ::thread tache2 ( &go );
while ( moteur->isRunning() ) moteur->run();
std::cin.ignore( 100, '\n' );
std:: cout << "Les deux moteurs tournent ";
moteur->startStop();
moteur->drop();
return 0;
}
one devcie, onde driver and 2 smgr
I tried with something like this :
[code]
while ( running )
{
if (device->run() )
{
driver->beginScene(true, true, SColor(255,100,0,140), param.WindowId);
smgr->setActiveCamera(camera);
smgr->drawAll();
driver->endScene();
driver2->beginScene(true, true, SColor(255,100,101,140), param2.WindowId);
smgr2->setActiveCamera(camera2);
smgr2->drawAll();
driver2->endScene();
}
}
[/code]
The windowId are different , nothing is null, smgr is different from smgr2 but thre's nothing in the second window !
One device and 2 driver ? is it possible ?
[code]
while ( running )
{
if (device->run() )
{
driver->beginScene(true, true, SColor(255,100,0,140), param.WindowId);
smgr->setActiveCamera(camera);
smgr->drawAll();
driver->endScene();
driver2->beginScene(true, true, SColor(255,100,101,140), param2.WindowId);
smgr2->setActiveCamera(camera2);
smgr2->drawAll();
driver2->endScene();
}
}
[/code]
The windowId are different , nothing is null, smgr is different from smgr2 but thre's nothing in the second window !
One device and 2 driver ? is it possible ?