Discord
Steam
/
Developers
/
Direct3D Offsc..
Login/Join
Event Log
Direct3D Offscreen Buffer
1 replies, posted
Search
In This Thread
I'm trying to use Direct3D to render to an offscreen buffer, and then convert to ASCII and output to the console window. I've come up with this thus far, but colour is always (0, 0, 0) regardless of what colour the screen is cleared with: [cpp]#include <windows.h> #include <d3d9.h> int main(int argc, char *argv[]) { IDirect3D9 *pD3D9 = Direct3DCreate9(D3D_SDK_VERSION); HWND hWnd = GetConsoleWindow(); D3DPRESENT_PARAMETERS d3dpp = { 0 }; d3dpp.BackBufferWidth = 640; d3dpp.BackBufferHeight = 300; d3dpp.BackBufferCount = 1; IDirect3DDevice9 *pD3DDevice9 = NULL; pD3D9->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_NULLREF, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &pD3DDevice9 ); IDirect3DSurface9 *pBackBuffer = NULL; pD3DDevice9->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer ); IDirect3DSurface9 *pSurface = NULL; pD3DDevice9->CreateOffscreenPlainSurface( 640, 300, D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, &pSurface, NULL ); D3DLOCKED_RECT rect; HDC hdc = GetDC(hWnd); while(true) { pD3DDevice9->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255, 255, 255), 1.f, 0 ); pD3DDevice9->BeginScene(); pD3DDevice9->EndScene(); pD3DDevice9->GetRenderTargetData(pBackBuffer, pSurface); pSurface->LockRect( &rect, NULL, D3DLOCK_NO_DIRTY_UPDATE | D3DLOCK_READONLY ); for(int y = 0; y < 300; y++) { for(int x = 0; x < 640; x++) { D3DCOLOR Color = ((D3DCOLOR *)rect.pBits)[y * (rect.Pitch / sizeof(int)) + x]; SetPixel(hdc, x, y, Color); } } pSurface->UnlockRect(); } ReleaseDC(hWnd, hdc); pBackBuffer->Release(); pSurface->Release(); pD3DDevice9->Release(); pD3D9->Release(); return 0; } [/cpp] Is this even possible without a window? If so, what am I doing wrong?
Bump!
Sorry, you need to
Log In
to post a reply to this thread.