Skip to content

Commit

Permalink
Added Texture Rendering
Browse files Browse the repository at this point in the history
Allows Smart or Browsers to draw graphics.
  • Loading branch information
Brandon-T authored and Brandon-T committed Jan 24, 2014
1 parent f5732e4 commit 5806cae
Show file tree
Hide file tree
Showing 21 changed files with 4,299 additions and 11 deletions.
9 changes: 7 additions & 2 deletions DXI/DXI.depend
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# depslib dependency file v1.0
1387667367 source:c:\users\brandon\desktop\dxi\sharedmemory.cpp
1388751552 source:c:\users\brandon\desktop\dxi\sharedmemory.cpp
"SharedMemory.hpp"

1387667354 c:\users\brandon\desktop\dxi\sharedmemory.hpp
1388751552 c:\users\brandon\desktop\dxi\sharedmemory.hpp
<windows.h>
<sys/types.h>
<sys/mman.h>
Expand All @@ -13,3 +13,8 @@
<iostream>
<map>

1388753939 source:c:\users\brandon\desktop\dxi\main.cpp
<windows.h>
<memory>
"SharedMemory.hpp"

12 changes: 6 additions & 6 deletions DXI/DXI.layout
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<ActiveTarget name="Release" />
<File name="main.cpp" open="1" top="1" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="SharedMemory.hpp" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2768" topLine="71" />
<Cursor1 position="83" topLine="0" />
</Cursor>
</File>
<File name="SharedMemory.cpp" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="356" topLine="189" />
<Cursor1 position="1692" topLine="93" />
</Cursor>
</File>
<File name="SharedMemory.hpp" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="SharedMemory.cpp" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="83" topLine="0" />
<Cursor1 position="356" topLine="189" />
</Cursor>
</File>
</CodeBlocks_layout_file>
2 changes: 1 addition & 1 deletion DXI/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ bool UnMapSharedMemory()

extern "C" bool __declspec(dllexport) DXISetup(int ProcessID)
{
return (CreateSharedMemory(ProcessID) || OpenSharedMemory(ProcessID));
return OpenSharedMemory(ProcessID);
}

extern "C" void* __declspec(dllexport) DXIImagePointer()
Expand Down
70 changes: 70 additions & 0 deletions d3d9/Graphics.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include "Graphics.hpp"

HRESULT Graphics::Capture(IDirect3DDevice9* Device, const char* FilePath, int Width, int Height, D3DFORMAT Format)
{
IDirect3DSurface9* RenderTarget = nullptr;
IDirect3DSurface9* DestTarget = nullptr;
HRESULT result = Device->GetRenderTarget(0, &RenderTarget);

if (result == S_OK)
{
if (Width == 0 || Height == 0 || Format == D3DFMT_UNKNOWN)
{
D3DSURFACE_DESC descriptor = {};
RenderTarget->GetDesc(&descriptor);
Width = descriptor.Width;
Height = descriptor.Height;
Format = descriptor.Format;
}

result = Device->CreateOffscreenPlainSurface(Width, Height, Format, D3DPOOL_SYSTEMMEM, &DestTarget, nullptr);
result = Device->GetRenderTargetData(RenderTarget, DestTarget);
result = D3DXSaveSurfaceToFile(FilePath, D3DXIFF_PNG, DestTarget, nullptr, nullptr);
}

SafeRelease(RenderTarget);
SafeRelease(DestTarget);
return result;
}

HRESULT Graphics::Capture2(IDirect3DDevice9* Device, const char* FilePath)
{
IDirect3DSurface9* RenderTarget = nullptr;
HRESULT result = Device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &RenderTarget);
result = D3DXSaveSurfaceToFile(FilePath, D3DXIFF_PNG, RenderTarget, nullptr, nullptr);
SafeRelease(RenderTarget);
return result;
}

HRESULT Graphics::Capture3(IDirect3DDevice9* Device, std::uint8_t* &Buffer, int Width, int Height, D3DFORMAT Format)
{
IDirect3DSurface9* RenderTarget = nullptr;
IDirect3DSurface9* DestTarget = nullptr;
HRESULT result = Device->GetRenderTarget(0, &RenderTarget);

if (result == S_OK)
{
if (Width == 0 || Height == 0 || Format == D3DFMT_UNKNOWN)
{
D3DSURFACE_DESC descriptor = {};
RenderTarget->GetDesc(&descriptor);
Width = descriptor.Width;
Height = descriptor.Height;
Format = descriptor.Format;
}

result = Device->CreateOffscreenPlainSurface(Width, Height, Format, D3DPOOL_SYSTEMMEM, &DestTarget, nullptr);
result = Device->GetRenderTargetData(RenderTarget, DestTarget);

D3DLOCKED_RECT rect;
DestTarget->LockRect(&rect, 0, D3DLOCK_READONLY);

//std::unique_ptr<std::uint8_t[]> mem(new std::uint8_t[Width * Height * 4]);
//memcpy(mem.get(), rect.pBits, Width * Height * 4);
Buffer = reinterpret_cast<std::uint8_t*>(rect.pBits);
}

SafeRelease(RenderTarget);
SafeRelease(DestTarget);
return result;
}
29 changes: 29 additions & 0 deletions d3d9/Graphics.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef GRAPHICS_HPP_INCLUDED
#define GRAPHICS_HPP_INCLUDED

#include <d3d9.h>
#include <D3Dx9tex.h>
#include <cstdint>
#include <memory>
#include "Images.hpp"


template<typename T>
void SafeRelease(T* &Ptr)
{
if (Ptr)
{
Ptr->Release();
Ptr = nullptr;
}
}

class Graphics
{
public:
HRESULT Capture(IDirect3DDevice9* Device, const char* FilePath, int Width = 0, int Height = 0, D3DFORMAT Format = D3DFMT_UNKNOWN);
HRESULT Capture2(IDirect3DDevice9* Device, const char* FilePath);
HRESULT Capture3(IDirect3DDevice9* Device, std::uint8_t* &Buffer, int Width = 0, int Height = 0, D3DFORMAT Format = D3DFMT_UNKNOWN);
};

#endif // GRAPHICS_HPP_INCLUDED
Loading

0 comments on commit 5806cae

Please sign in to comment.