-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
21 changed files
with
4,299 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.