jason_rea
jason_rea

Reputation: 43

Ogre and Allegro direct3d device 9 conflict

I've been trying to write a program that uses Allegro 5 to handle 2D rendering and and Ogre for 3D rendering but I've had problems with initialization, I've got most of the issues down which were the hInstance of the window, but now the issue is that Ogre::D3D9RenderWindow::setDevice() only takes Ogre's type and that is set by an ID3Device9 according to the Ogre API reference and not what al_get_d3d9_device() returns which is an LPDIRECT3DDEVICE9. I need help trying to figure out how to convert the LPDIRECT3DDEVICE9 to a ID3Device9.

Here is the code the I have so far:

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{

ALLEGRO_DISPLAY *al_display = NULL;

if(!al_init())
{
    fprintf(stderr, "Cannot initialize allegro");
    return -1;
}

al_display = al_create_display(640, 480);

if(!al_display)
{
    fprintf(stderr,"Cannot initialize the display");
    return -1;
}

HWND hWnd = al_get_win_window_handle(al_display);

HINSTANCE hInst = (HINSTANCE)GetWindowLong( hWnd, GWL_HINSTANCE);

Ogre::D3D9RenderWindow ogre_window(hInst);

ogre_window.setDevice(al_get_d3d_device(al_display)); // Function only takes an Ogre::D3D9Device

return 0;
}

Upvotes: 1

Views: 164

Answers (2)

jason_rea
jason_rea

Reputation: 43

After much work and tedious studying with the help of Matthew's answer I was able to find the solution to the problem through a few pointers on pointers.

Here is the final code:

int _tmain(int argc, _TCHAR* argv[])
{
ALLEGRO_DISPLAY *al_display = NULL;

if(!al_init())
{
    fprintf(stderr, "Cannot initialize allegro");
    return -1;
}

al_display = al_create_display(640, 480);

if(!al_display)
{
    fprintf(stderr,"Cannot initialize the display");
    return -1;
}

HWND hWnd = al_get_win_window_handle(al_display);

HINSTANCE hInst = (HINSTANCE)GetWindowLong( hWnd, GWL_HINSTANCE);

Ogre::D3D9RenderWindow ogre_window(hInst);

LPDIRECT3DDEVICE9 D3dDev = al_get_d3d_device(al_display);
IDirect3DDevice9 *iD3dDev = D3dDev;
Ogre::D3D9DeviceManager D3dDevManager;
Ogre::D3D9Device *OD3dDev = D3dDevManager.getDeviceFromD3D9Device(iD3dDev);
ogre_window.setDevice(OD3dDev);

return 0;
}

Upvotes: 0

Matthew
Matthew

Reputation: 48294

It's possible if you use OpenGL. An example comes with Allegro.

Not sure about D3D.

Upvotes: 1

Related Questions