Browse Source

Before adding camera

Marko Pintera 13 years ago
parent
commit
f908d8a771

+ 2 - 2
CamelotRenderer/CamelotRenderer.vcxproj

@@ -59,7 +59,7 @@
       <AdditionalIncludeDirectories>C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <AdditionalIncludeDirectories>C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     </ClCompile>
     </ClCompile>
     <Link>
     <Link>
-      <SubSystem>Console</SubSystem>
+      <SubSystem>NotSet</SubSystem>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <AdditionalDependencies>d3d9.lib;d3dx9.lib;DxErr.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <AdditionalDependencies>d3d9.lib;d3dx9.lib;DxErr.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies>
     </Link>
     </Link>
@@ -75,7 +75,7 @@
       <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;OGRE_STATIC_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;OGRE_STATIC_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
     </ClCompile>
     </ClCompile>
     <Link>
     <Link>
-      <SubSystem>Console</SubSystem>
+      <SubSystem>NotSet</SubSystem>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <OptimizeReferences>true</OptimizeReferences>
       <OptimizeReferences>true</OptimizeReferences>

+ 131 - 1
CamelotRenderer/CmApplication.cpp

@@ -3,15 +3,27 @@
 #include "OgreRenderSystem.h"
 #include "OgreRenderSystem.h"
 #include "CmRenderSystemManager.h"
 #include "CmRenderSystemManager.h"
 
 
+#include "OgreWindowEventUtilities.h"
+#include "OgreHardwareBufferManager.h"
+
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
 	Application::Application()
 	Application::Application()
+		:mRenderWindow(nullptr), mViewport(nullptr)
 	{ }
 	{ }
 
 
 	void Application::startUp()
 	void Application::startUp()
 	{
 	{
 		RenderSystemManager::initialize("D3D9RenderSystem");
 		RenderSystemManager::initialize("D3D9RenderSystem");
-		RenderSystemManager::getActive()->_initialise(true, "Camelot Renderer");
+		
+		Ogre::RenderSystem* renderSystem = RenderSystemManager::getActive();
+		renderSystem->_initialise(false, "Camelot Renderer");
+		mRenderWindow = renderSystem->_createRenderWindow("Camelot Renderer", 800, 600, false);
+
+		while(true)
+		{
+			Ogre::WindowEventUtilities::messagePump();
+		}
 	}
 	}
 
 
 	void Application::shutDown()
 	void Application::shutDown()
@@ -20,6 +32,124 @@ namespace CamelotEngine
 			RenderSystemManager::getActive()->shutdown();
 			RenderSystemManager::getActive()->shutdown();
 	}
 	}
 
 
+	void Application::DBG_renderSimpleFrame()
+	{
+		Ogre::RenderOperation ro;
+		Ogre::IndexData* indexData = new Ogre::IndexData();
+
+		indexData->indexCount = 36;
+		indexData->indexBuffer = Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(
+			Ogre::HardwareIndexBuffer::IT_16BIT,
+			36, 
+			Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
+
+		unsigned short* idxData = static_cast<unsigned short*>(indexData->indexBuffer->lock(Ogre::HardwareBuffer::HBL_NORMAL));
+
+		idxData[0] = 0; idxData[1] = 1; idxData[2] = 2;
+		idxData[3] = 2; idxData[4] = 3; idxData[5] = 0;
+
+		idxData[6] = 4; idxData[7] = 5; idxData[8] = 6;
+		idxData[9] = 6; idxData[10] = 7; idxData[11] = 4;
+
+		idxData[12] = 0; idxData[13] = 3; idxData[14] = 5;
+		idxData[15] = 5; idxData[16] = 4; idxData[17] = 0;
+
+		idxData[18] = 3; idxData[19] = 2; idxData[20] = 6;
+		idxData[21] = 6; idxData[22] = 5; idxData[23] = 3;
+
+		idxData[24] = 2; idxData[25] = 1; idxData[26] = 7;
+		idxData[27] = 7; idxData[28] = 6; idxData[29] = 2;
+
+		idxData[30] = 1; idxData[31] = 0; idxData[32] = 4;
+		idxData[33] = 4; idxData[34] = 7; idxData[35] = 1;
+
+		indexData->indexBuffer->unlock();
+
+
+		Ogre::VertexData* vertexData = new Ogre::VertexData();
+
+		vertexData->vertexStart = 0;
+		vertexData->vertexCount = 8;
+
+		Ogre::VertexDeclaration* decl = vertexData->vertexDeclaration;
+		decl->removeAllElements();
+
+		size_t offset = 0;
+		decl->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
+		offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
+
+		//decl->addElement(0, offset, Ogre::VET_COLOUR, Ogre::VES_DIFFUSE);
+		//offset += Ogre::VertexElement::getTypeSize(Ogre::VET_COLOUR);
+
+		Ogre::HardwareVertexBufferSharedPtr vertexBuffer = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
+			vertexData->vertexDeclaration->getVertexSize(0),
+			vertexData->vertexCount,
+			Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
+
+		vertexData->vertexBufferBinding->setBinding(0, vertexBuffer);
+
+		size_t vertexSize = vertexBuffer->getVertexSize();
+		char* vertBufferData = static_cast<char*>(vertexBuffer->lock(Ogre::HardwareBuffer::HBL_NORMAL));
+
+		Ogre::Vector3 position(-5.0f, -5.0f, -5.0f);
+		memcpy(vertBufferData, &position, vertexSize);
+		vertBufferData += vertexSize;
+
+		position = 	Ogre::Vector3(-5.0f, 5.0f, -5.0f);
+		memcpy(vertBufferData, &position, vertexSize);
+		vertBufferData += vertexSize;
+
+		position = 	Ogre::Vector3(5.0f, 5.0f, -5.0f);
+		memcpy(vertBufferData, &position, vertexSize);
+		vertBufferData += vertexSize;
+
+		position = 	Ogre::Vector3(5.0f, -5.0f, -5.0f);
+		memcpy(vertBufferData, &position, vertexSize);
+		vertBufferData += vertexSize;
+
+		position = 	Ogre::Vector3(-5.0f, -5.0f, 5.0f);
+		memcpy(vertBufferData, &position, vertexSize);
+		vertBufferData += vertexSize;
+
+		position = 	Ogre::Vector3(5.0f, -5.0f, 5.0f);
+		memcpy(vertBufferData, &position, vertexSize);
+		vertBufferData += vertexSize;
+
+		position = 	Ogre::Vector3(5.0f, 5.0f, 5.0f);
+		memcpy(vertBufferData, &position, vertexSize);
+		vertBufferData += vertexSize;
+
+		position = 	Ogre::Vector3(-5.0f, 5.0f, 5.0f);
+		memcpy(vertBufferData, &position, vertexSize);
+		vertBufferData += vertexSize;
+
+		vertexBuffer->unlock();
+
+		ro.indexData = indexData;
+		ro.vertexData = vertexData;
+		ro.useIndexes = true;
+		ro.operationType = Ogre::RenderOperation::OT_TRIANGLE_LIST;
+
+		Ogre::RenderSystem* renderSystem = RenderSystemManager::getActive();
+		renderSystem->_setViewport(mViewport);
+
+		Ogre::Matrix4 projMatrix = mCamera->getProjectionMatrixRS();
+		renderSystem->_setProjectionMatrix(projMatrix);
+
+		Ogre::Matrix4 viewMatrix = mCamera->getViewMatrix(true);
+		renderSystem->_setViewMatrix(viewMatrix);
+
+		renderSystem->setInvertVertexWinding(true);
+		renderSystem->clearFrameBuffer(Ogre::FBT_COLOUR | Ogre::FBT_DEPTH, Ogre::ColourValue::Blue);
+		renderSystem->_beginFrame();
+
+		renderSystem->_render(ro);
+
+		renderSystem->_endFrame();
+
+		renderSystem->_swapAllRenderTargetBuffers(false);
+	}
+
 	Application& gApplication()
 	Application& gApplication()
 	{
 	{
 		static Application application;
 		static Application application;

+ 12 - 0
CamelotRenderer/CmApplication.h

@@ -2,6 +2,12 @@
 
 
 #include <memory>
 #include <memory>
 
 
+namespace Ogre
+{
+	class RenderWindow;
+	class Viewport;
+}
+
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
 	class Application
 	class Application
@@ -11,6 +17,12 @@ namespace CamelotEngine
 
 
 			void startUp();
 			void startUp();
 			void shutDown();
 			void shutDown();
+
+			void DBG_renderSimpleFrame();
+
+		private:
+			Ogre::RenderWindow* mRenderWindow;
+			Ogre::Viewport* mViewport;
 	};
 	};
 
 
 	Application& gApplication();
 	Application& gApplication();

+ 5 - 1
CamelotRenderer/TODO.txt

@@ -84,4 +84,8 @@ Other notes:
  - Ogre::ColourValue -> CamelotEngine::Color (Other struct names are okay for the most part)
  - Ogre::ColourValue -> CamelotEngine::Color (Other struct names are okay for the most part)
  - Port all math methods to Camelot
  - Port all math methods to Camelot
  - Rename all macros and other OGRE references to CM
  - Rename all macros and other OGRE references to CM
- - How am I notified on device reset? (When I need to reload my resources)
+ - How am I notified on device reset? (When I need to reload my resources)
+ 
+After everything is polished:
+ - Make sure the renderer can run on a separate thread
+ - Get 64bit version working