|
@@ -30,97 +30,18 @@
|
|
|
#include <Input.h>
|
|
#include <Input.h>
|
|
|
#include <Shell.h>
|
|
#include <Shell.h>
|
|
|
#include "RenderInterfaceDirectX.h"
|
|
#include "RenderInterfaceDirectX.h"
|
|
|
-#include <d3d9.h>
|
|
|
|
|
-#include <d3dx9.h>
|
|
|
|
|
-
|
|
|
|
|
-static LPDIRECT3D9 g_pD3D = NULL;
|
|
|
|
|
-static LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;
|
|
|
|
|
|
|
|
|
|
static Rocket::Core::Context* context = NULL;
|
|
static Rocket::Core::Context* context = NULL;
|
|
|
|
|
|
|
|
-bool InitialiseDirectX()
|
|
|
|
|
-{
|
|
|
|
|
- g_pD3D = Direct3DCreate9(D3D_SDK_VERSION);
|
|
|
|
|
- if (g_pD3D == NULL)
|
|
|
|
|
- return false;
|
|
|
|
|
-
|
|
|
|
|
- D3DPRESENT_PARAMETERS d3dpp;
|
|
|
|
|
- ZeroMemory(&d3dpp, sizeof(d3dpp));
|
|
|
|
|
- d3dpp.Windowed = TRUE;
|
|
|
|
|
- d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
|
|
|
|
- d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
|
|
|
|
|
-
|
|
|
|
|
- if (FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT,
|
|
|
|
|
- D3DDEVTYPE_HAL,
|
|
|
|
|
- (HWND) Shell::GetWindowHandle(),
|
|
|
|
|
- D3DCREATE_SOFTWARE_VERTEXPROCESSING,
|
|
|
|
|
- &d3dpp,
|
|
|
|
|
- &g_pd3dDevice)))
|
|
|
|
|
- {
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Set up an orthographic projection.
|
|
|
|
|
- D3DXMATRIX projection;
|
|
|
|
|
- D3DXMatrixOrthoOffCenterLH(&projection, 0, 1024, 768, 0, -1, 1);
|
|
|
|
|
- g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &projection);
|
|
|
|
|
-
|
|
|
|
|
- // Switch to clockwise culling instead of counter-clockwise culling; Rocket generates counter-clockwise geometry,
|
|
|
|
|
- // so you can either reverse the culling mode when Rocket is rendering, or reverse the indices in the render
|
|
|
|
|
- // interface.
|
|
|
|
|
- g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
|
|
|
|
|
-
|
|
|
|
|
- // Enable alpha-blending for Rocket.
|
|
|
|
|
- g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
|
|
|
|
|
- g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
|
|
|
|
|
- g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
|
|
|
|
|
-
|
|
|
|
|
- // Set up the texture stage states for the diffuse texture.
|
|
|
|
|
- g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
|
|
|
|
|
- g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
|
|
|
|
|
- g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
|
|
|
|
|
- g_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
|
|
|
|
|
- g_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
|
|
|
|
|
-
|
|
|
|
|
- g_pd3dDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
|
|
|
|
|
- g_pd3dDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
|
|
|
|
|
-
|
|
|
|
|
- // Disable lighting for Rocket.
|
|
|
|
|
- g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
|
|
|
|
|
-
|
|
|
|
|
- return true;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-void ShutdownDirectX()
|
|
|
|
|
-{
|
|
|
|
|
- if (g_pd3dDevice != NULL)
|
|
|
|
|
- {
|
|
|
|
|
- // Release the last resources we bound to the device.
|
|
|
|
|
- g_pd3dDevice->SetTexture(0, NULL);
|
|
|
|
|
- g_pd3dDevice->SetStreamSource(0, NULL, 0, 0);
|
|
|
|
|
- g_pd3dDevice->SetIndices(NULL);
|
|
|
|
|
-
|
|
|
|
|
- g_pd3dDevice->Release();
|
|
|
|
|
- g_pd3dDevice = NULL;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (g_pD3D != NULL)
|
|
|
|
|
- {
|
|
|
|
|
- g_pD3D->Release();
|
|
|
|
|
- g_pD3D = NULL;
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ShellRenderInterfaceExtensions *shell_renderer;
|
|
|
|
|
|
|
|
void GameLoop()
|
|
void GameLoop()
|
|
|
{
|
|
{
|
|
|
- g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
|
|
|
|
|
- g_pd3dDevice->BeginScene();
|
|
|
|
|
-
|
|
|
|
|
context->Update();
|
|
context->Update();
|
|
|
- context->Render();
|
|
|
|
|
|
|
|
|
|
- g_pd3dDevice->EndScene();
|
|
|
|
|
- g_pd3dDevice->Present(NULL, NULL, NULL, NULL);
|
|
|
|
|
|
|
+ shell_renderer->PrepareRenderBuffer();
|
|
|
|
|
+ context->Render();
|
|
|
|
|
+ shell_renderer->PresentRenderBuffer();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#if defined ROCKET_PLATFORM_WIN32
|
|
#if defined ROCKET_PLATFORM_WIN32
|
|
@@ -140,25 +61,21 @@ int main(int ROCKET_UNUSED_PARAMETER(argc), char** ROCKET_UNUSED_PARAMETER(argv)
|
|
|
ROCKET_UNUSED(argv);
|
|
ROCKET_UNUSED(argv);
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
- // Generic OS initialisation, creates a window and does not attach OpenGL.
|
|
|
|
|
- if (!Shell::Initialise("../Samples/basic/directx/") ||
|
|
|
|
|
- !Shell::OpenWindow("DirectX Sample", false))
|
|
|
|
|
- {
|
|
|
|
|
- Shell::Shutdown();
|
|
|
|
|
- return -1;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ int window_width = 1024;
|
|
|
|
|
+ int window_height = 768;
|
|
|
|
|
|
|
|
- // DirectX initialisation.
|
|
|
|
|
- if (!InitialiseDirectX())
|
|
|
|
|
|
|
+ RenderInterfaceDirectX directx_renderer;
|
|
|
|
|
+ shell_renderer = &directx_renderer;
|
|
|
|
|
+
|
|
|
|
|
+ // Generic OS initialisation, creates a window
|
|
|
|
|
+ if (!Shell::Initialise("../Samples/basic/directx/") ||
|
|
|
|
|
+ !Shell::OpenWindow("DirectX Sample", shell_renderer, window_width, window_height, true))
|
|
|
{
|
|
{
|
|
|
- Shell::CloseWindow();
|
|
|
|
|
Shell::Shutdown();
|
|
Shell::Shutdown();
|
|
|
-
|
|
|
|
|
return -1;
|
|
return -1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Install our DirectX render interface into Rocket.
|
|
// Install our DirectX render interface into Rocket.
|
|
|
- RenderInterfaceDirectX directx_renderer(g_pD3D, g_pd3dDevice);
|
|
|
|
|
Rocket::Core::SetRenderInterface(&directx_renderer);
|
|
Rocket::Core::SetRenderInterface(&directx_renderer);
|
|
|
|
|
|
|
|
ShellSystemInterface system_interface;
|
|
ShellSystemInterface system_interface;
|
|
@@ -167,7 +84,7 @@ int main(int ROCKET_UNUSED_PARAMETER(argc), char** ROCKET_UNUSED_PARAMETER(argv)
|
|
|
Rocket::Core::Initialise();
|
|
Rocket::Core::Initialise();
|
|
|
|
|
|
|
|
// Create the main Rocket context and set it on the shell's input layer.
|
|
// Create the main Rocket context and set it on the shell's input layer.
|
|
|
- context = Rocket::Core::CreateContext("main", Rocket::Core::Vector2i(1024, 768));
|
|
|
|
|
|
|
+ context = Rocket::Core::CreateContext("main", Rocket::Core::Vector2i(window_width, window_height));
|
|
|
if (context == NULL)
|
|
if (context == NULL)
|
|
|
{
|
|
{
|
|
|
Rocket::Core::Shutdown();
|
|
Rocket::Core::Shutdown();
|
|
@@ -194,8 +111,6 @@ int main(int ROCKET_UNUSED_PARAMETER(argc), char** ROCKET_UNUSED_PARAMETER(argv)
|
|
|
context->RemoveReference();
|
|
context->RemoveReference();
|
|
|
Rocket::Core::Shutdown();
|
|
Rocket::Core::Shutdown();
|
|
|
|
|
|
|
|
- ShutdownDirectX();
|
|
|
|
|
-
|
|
|
|
|
Shell::CloseWindow();
|
|
Shell::CloseWindow();
|
|
|
Shell::Shutdown();
|
|
Shell::Shutdown();
|
|
|
|
|
|