• R/O
  • SSH
  • HTTPS

eirsamples: Commit


Commit MetaInfo

Revision1 (tree)
Time2017-04-07 00:38:09
Authorquiret

Log Message

- migrated from CodePlex (https://magicrwsample.codeplex.com/)

Change Summary

Incremental Difference

--- magicrwsample/README.md (nonexistent)
+++ magicrwsample/README.md (revision 1)
@@ -0,0 +1 @@
1+Basic sample application written using the rwtools RenderWare ecosystem.
\ No newline at end of file
--- magicrwsample/src/main.cpp (nonexistent)
+++ magicrwsample/src/main.cpp (revision 1)
@@ -0,0 +1,138 @@
1+#include <renderware.h>
2+
3+#include <rwframework.h>
4+
5+namespace rw
6+{
7+ LibraryVersion app_version( void )
8+ {
9+ LibraryVersion ver;
10+
11+ ver.rwLibMajor = 3;
12+ ver.rwLibMinor = 7;
13+ ver.rwRevMajor = 0;
14+ ver.rwRevMinor = 0;
15+
16+ return ver;
17+ }
18+
19+ static void window_closing_event_handler( RwObject *obj, event_t eventID, void *callbackData, void *ud )
20+ {
21+ // We request destruction of the window.
22+ obj->engineInterface->DeleteRwObject( obj );
23+ }
24+
25+ int32 rwmain( Interface *engineInterface )
26+ {
27+ // Give information about the running application to the runtime.
28+ softwareMetaInfo metaInfo;
29+ metaInfo.applicationName = "RenderWare Sample";
30+ metaInfo.applicationVersion = "test";
31+ metaInfo.description = "A test application for the rwtools runtime";
32+
33+ engineInterface->SetApplicationInfo( metaInfo );
34+
35+ // Create a window and render into it.
36+ Window *rwWindow = MakeWindow( engineInterface, 640, 480 );
37+
38+ if ( !rwWindow )
39+ return -1;
40+
41+ // We hold an extra reference.
42+ AcquireObject( rwWindow );
43+
44+ // Handle the window closing event.
45+ RegisterEventHandler( rwWindow, event_t::WINDOW_CLOSING, window_closing_event_handler );
46+ RegisterEventHandler( rwWindow, event_t::WINDOW_QUIT, window_closing_event_handler );
47+
48+ // Show the window, since we have set it up by now.
49+ rwWindow->SetVisible( true );
50+
51+ // Create the game renderer.
52+ Driver *d3dDriver = CreateDriver( engineInterface, "Direct3D12" );
53+
54+ assert( d3dDriver != NULL );
55+
56+ // We need a command queue for drawing commands.
57+ DriverCmdQueue *cmdQueue = d3dDriver->CreateCommandQueue( eCmdBufType::GRAPHICS, 0 );
58+
59+ assert( cmdQueue != NULL );
60+
61+ // Set up the game resources.
62+ DriverSwapChain *swapChain = d3dDriver->CreateSwapChain( rwWindow, 2, cmdQueue ); // we want to double-buffer.
63+
64+ DrawingLayer2D *guiContext = CreateDrawingLayer2D( d3dDriver );
65+
66+ // We have to get the ref count over here, because the swap chain increases the ref count as well.
67+ uint32 wndBaseRefCount = GetRefCount( rwWindow );
68+
69+ // Execute the main loop
70+ while ( GetRefCount( rwWindow ) >= wndBaseRefCount ) // we wait until somebody requested to destroy the window.
71+ {
72+ // Draw the game scene.
73+ {
74+ // Set render states.
75+ guiContext->SetRenderState( DrawingLayer2D::RWSTATE_UTEXADDRESSMODE, RWTEXADDRESS_WRAP );
76+ guiContext->SetRenderState( DrawingLayer2D::RWSTATE_VTEXADDRESSMODE, RWTEXADDRESS_WRAP );
77+ guiContext->SetRenderState( DrawingLayer2D::RWSTATE_ZWRITEENABLE, true );
78+ guiContext->SetRenderState( DrawingLayer2D::RWSTATE_TEXFILTER, RWFILTER_POINT );
79+ guiContext->SetRenderState( DrawingLayer2D::RWSTATE_SRCBLEND, RWBLEND_ONE );
80+ guiContext->SetRenderState( DrawingLayer2D::RWSTATE_DSTBLEND, RWBLEND_ZERO );
81+ guiContext->SetRenderState( DrawingLayer2D::RWSTATE_ALPHABLENDENABLE, true );
82+ guiContext->SetRenderState( DrawingLayer2D::RWSTATE_ALPHAFUNC, RWCMP_ALWAYS );
83+ guiContext->SetRenderState( DrawingLayer2D::RWSTATE_ALPHAREF, 0 );
84+
85+#if 0
86+ // Execute draws.
87+ guiContext->Begin();
88+
89+ guiContext->DrawRect( 50, 50, 100, 100 );
90+ guiContext->DrawRect( 60, 60, 80, 80 );
91+ guiContext->DrawLine( 10, 10, 290, 150 );
92+
93+ guiContext->End();
94+#endif
95+ }
96+
97+ // Present the rendered result.
98+ swapChain->Present( false );
99+
100+ // Give cycles to the window manager.
101+ // In the multi-threaded environment, this will effectively be a no-op.
102+ PulseWindowingSystem( engineInterface );
103+
104+ // We want to give some cycles to the OS.
105+ // Otherwise our thread would starve everything.
106+ YieldExecution( 1 );
107+ }
108+
109+ // Hide the window.
110+ // Do this because terminating resources takes some time and
111+ // the user already knows this application is terminating.
112+ rwWindow->SetVisible( false );
113+
114+ // Destroy drawing contexts.
115+ DeleteDrawingLayer2D( guiContext );
116+
117+ // Release the swap chain device resource.
118+ d3dDriver->DestroySwapChain( swapChain );
119+
120+ d3dDriver->DestroyCommandQueue( cmdQueue );
121+
122+ // Terminate the driver.
123+ DestroyDriver( engineInterface, d3dDriver );
124+
125+ // Release our window reference.
126+ // This will destroy it.
127+ engineInterface->DeleteRwObject( rwWindow );
128+
129+ return 0;
130+ }
131+};
132+
133+// We use the windows subsystem.
134+BOOL WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow )
135+{
136+ // Redirect to RenderWare.
137+ return rw::frameworkEntryPoint_win32( hInst, hPrevInst, lpCmdLine, nCmdShow );
138+}
\ No newline at end of file
Show on old repository browser