Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

233 lines
6.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // The copyright to the contents herein is the property of Valve, L.L.C.
  4. // The contents may be used and/or copied only with the written permission of
  5. // Valve, L.L.C., or in accordance with the terms and conditions stipulated in
  6. // the agreement/contract under which the contents have been supplied.
  7. //
  8. // $Header: $
  9. // $NoKeywords: $
  10. //
  11. // Material editor
  12. //=============================================================================
  13. #include <windows.h>
  14. #include "appframework/vguimatsysapp.h"
  15. #include "filesystem.h"
  16. #include "materialsystem/imaterialsystem.h"
  17. #include "materialsystem/imesh.h"
  18. #include "vgui/ISurface.h"
  19. #include "vgui/IVGui.h"
  20. #include "vgui_controls/controls.h"
  21. #include "VGuiMatSurface/IMatSystemSurface.h"
  22. #include "vgui/ILocalize.h"
  23. #include "vgui/IScheme.h"
  24. #include "avi/iavi.h"
  25. #include "avi/ibik.h"
  26. #include "tier3/tier3.h"
  27. //-----------------------------------------------------------------------------
  28. // The application object
  29. //-----------------------------------------------------------------------------
  30. class CAVITestApp : public CVguiMatSysApp
  31. {
  32. typedef CVguiMatSysApp BaseClass;
  33. public:
  34. // Methods of IApplication
  35. virtual bool Create();
  36. virtual bool PreInit( );
  37. virtual int Main();
  38. virtual void PostShutdown( );
  39. virtual const char *GetAppName() { return "AVITest"; }
  40. virtual bool AppUsesReadPixels() { return true; }
  41. private:
  42. // Draws a quad
  43. void DrawStuff( AVIMaterial_t hMaterial );
  44. IMaterial *m_pMaterial;
  45. float m_flStartTime;
  46. };
  47. DEFINE_WINDOWED_STEAM_APPLICATION_OBJECT( CAVITestApp );
  48. //-----------------------------------------------------------------------------
  49. // Create all singleton systems
  50. //-----------------------------------------------------------------------------
  51. bool CAVITestApp::Create()
  52. {
  53. if ( !BaseClass::Create() )
  54. return false;
  55. AppSystemInfo_t appSystems[] =
  56. {
  57. { "valve_avi.dll", AVI_INTERFACE_VERSION },
  58. { "valve_avi.dll", BIK_INTERFACE_VERSION },
  59. { "", "" } // Required to terminate the list
  60. };
  61. return AddSystems( appSystems );
  62. }
  63. //-----------------------------------------------------------------------------
  64. // PreInit, PostShutdown
  65. //-----------------------------------------------------------------------------
  66. bool CAVITestApp::PreInit( )
  67. {
  68. if ( !BaseClass::PreInit() )
  69. return false;
  70. if ( !g_pFullFileSystem || !g_pMaterialSystem || !g_pVGui || !g_pVGuiSurface || !g_pAVI || !g_pBIK )
  71. return false;
  72. g_pAVI->SetMainWindow( GetAppWindow() );
  73. return true;
  74. }
  75. void CAVITestApp::PostShutdown( )
  76. {
  77. g_pAVI->SetMainWindow( NULL );
  78. BaseClass::PostShutdown();
  79. }
  80. //-----------------------------------------------------------------------------
  81. // Draws a quad
  82. //-----------------------------------------------------------------------------
  83. void CAVITestApp::DrawStuff( AVIMaterial_t hMaterial )
  84. {
  85. int iViewableWidth = GetWindowWidth();
  86. int iViewableHeight = GetWindowHeight();
  87. g_pAVI->SetTime( hMaterial, Sys_FloatTime() - m_flStartTime );
  88. float flMaxU, flMaxV;
  89. g_pAVI->GetTexCoordRange( hMaterial, &flMaxU, &flMaxV );
  90. IMaterial *pMaterial = g_pAVI->GetMaterial( hMaterial );
  91. CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
  92. pRenderContext->MatrixMode( MATERIAL_PROJECTION );
  93. pRenderContext->LoadIdentity();
  94. pRenderContext->Ortho( 0, 0, iViewableWidth, iViewableHeight, 0, 1 );
  95. pRenderContext->Bind( pMaterial );
  96. IMesh *pMesh = pRenderContext->GetDynamicMesh();
  97. CMeshBuilder meshBuilder;
  98. meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 );
  99. // Draw a polygon the size of the panel
  100. meshBuilder.Color4ub( 255, 255, 255, 255 );
  101. meshBuilder.Position3f( -0.5, iViewableHeight + 0.5, 0 );
  102. meshBuilder.TexCoord2f( 0, 0, 0 );
  103. meshBuilder.AdvanceVertex();
  104. meshBuilder.Color4ub( 255, 255, 255, 255 );
  105. meshBuilder.Position3f( -0.5, 0.5, 0 );
  106. meshBuilder.TexCoord2f( 0, 0, flMaxV );
  107. meshBuilder.AdvanceVertex();
  108. meshBuilder.Color4ub( 255, 255, 255, 255 );
  109. meshBuilder.Position3f( iViewableWidth - 0.5, 0.5, 0 );
  110. meshBuilder.TexCoord2f( 0, flMaxU, flMaxV );
  111. meshBuilder.AdvanceVertex();
  112. meshBuilder.Color4ub( 255, 255, 255, 255 );
  113. meshBuilder.Position3f( iViewableWidth - 0.5, iViewableHeight + 0.5, 0 );
  114. meshBuilder.TexCoord2f( 0, flMaxU, 0 );
  115. meshBuilder.AdvanceVertex();
  116. meshBuilder.End();
  117. pMesh->Draw();
  118. }
  119. //-----------------------------------------------------------------------------
  120. // main application
  121. //-----------------------------------------------------------------------------
  122. int CAVITestApp::Main()
  123. {
  124. if (!SetVideoMode())
  125. return 0;
  126. // load scheme
  127. if (!vgui::scheme()->LoadSchemeFromFile("resource/BoxRocket.res", "ElementViewer" ))
  128. {
  129. Assert( 0 );
  130. }
  131. // load the boxrocket localization file
  132. g_pVGuiLocalize->AddFile( "resource/boxrocket_%language%.txt" );
  133. // load the base localization file
  134. g_pVGuiLocalize->AddFile( "Resource/valve_%language%.txt" );
  135. g_pFullFileSystem->AddSearchPath("platform", "PLATFORM");
  136. g_pVGuiLocalize->AddFile( "Resource/vgui_%language%.txt");
  137. // start vgui
  138. g_pVGui->Start();
  139. // add our main window
  140. // vgui::Panel *mainPanel = CreateElementViewerPanel();
  141. CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
  142. AVIParams_t params;
  143. Q_strcpy( params.m_pFileName, "c:\\temp\\out.avi" );
  144. Q_strcpy( params.m_pPathID, "MOD" );
  145. pRenderContext->GetWindowSize( params.m_nWidth, params.m_nHeight );
  146. params.m_nFrameRate = 24;
  147. params.m_nFrameScale = 1;
  148. params.m_nNumChannels = 0;
  149. AVIHandle_t h = g_pAVI->StartAVI( params );
  150. AVIMaterial_t hAVIMaterial = g_pAVI->CreateAVIMaterial( "avitest", "c:\\temp\\test.avi", "MOD" );
  151. // run app frame loop
  152. vgui::VPANEL root = g_pVGuiSurface->GetEmbeddedPanel();
  153. g_pVGuiSurface->Invalidate( root );
  154. int imagesize = params.m_nWidth * params.m_nHeight;
  155. BGR888_t *hp = new BGR888_t[ imagesize ];
  156. m_flStartTime = Sys_FloatTime();
  157. m_pMaterial = g_pMaterialSystem->FindMaterial( "debug/debugempty", "app" );
  158. while ( g_pVGui->IsRunning() )
  159. {
  160. AppPumpMessages();
  161. pRenderContext->ClearColor4ub( 76, 88, 68, 255 );
  162. pRenderContext->ClearBuffers( true, true );
  163. DrawStuff( hAVIMaterial );
  164. g_pVGui->RunFrame();
  165. g_pVGuiSurface->PaintTraverse( root );
  166. // Get Bits from material system
  167. Rect_t rect;
  168. rect.x = rect.y = 0;
  169. rect.width = params.m_nWidth;
  170. rect.height = params.m_nHeight;
  171. pRenderContext->ReadPixelsAndStretch( &rect, &rect, (unsigned char*)hp,
  172. IMAGE_FORMAT_BGR888, rect.width * sizeof( BGR888_t ) );
  173. g_pAVI->AppendMovieFrame( h, hp );
  174. g_pMaterialSystem->SwapBuffers();
  175. }
  176. delete[] hp;
  177. g_pAVI->FinishAVI( h );
  178. g_pAVI->DestroyAVIMaterial( hAVIMaterial );
  179. // delete mainPanel;
  180. return 1;
  181. }