Ogre和Allegro direct3d设备9冲突

时间:2013-02-28 23:25:33

标签: windows direct3d ogre allegro

我一直在尝试编写一个使用Allegro 5来处理2D渲染的程序和用于3D渲染的Ogre,但是我在初始化方面遇到了问题,我已经解决了大部分问题,其中包括hInstance。窗口,但现在的问题是Ogre::D3D9RenderWindow::setDevice()只接受Ogre的类型,并且根据Ogre API引用由ID3Device9设置,而不是al_get_d3d9_device()返回的是LPDIRECT3DDEVICE9 }。我需要帮助才能弄清楚如何将LPDIRECT3DDEVICE9转换为ID3Device9

这是我到目前为止的代码:

#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;
}

2 个答案:

答案 0 :(得分:1)

如果您使用OpenGL,则可能。 Allegro附带example

不确定D3D。

答案 1 :(得分:0)

经过大量的工作和在Matthew的回答的帮助下进行繁琐的学习,我能够通过一些关于指针的指针找到问题的解决方案。

以下是最终代码:

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;
}