Click here to Skip to main content
15,887,135 members
Home / Discussions / Graphics
   

Graphics

 
QuestionD2D + WPF + SwapChain = ??? Pin
Max Dhom17-May-16 0:56
Max Dhom17-May-16 0:56 
QuestionHow to create complex 3d Objects with direct3d? Pin
Member 1226818310-Apr-16 6:17
Member 1226818310-Apr-16 6:17 
QuestionHow to render multiple 3D objects separately? Pin Pin
Member 1226818327-Mar-16 4:24
Member 1226818327-Mar-16 4:24 
AnswerRe: How to render multiple 3D objects separately? Pin Pin
Graham Breach27-Mar-16 23:29
Graham Breach27-Mar-16 23:29 
GeneralRe: How to render multiple 3D objects separately? Pin Pin
Member 122681833-Apr-16 6:41
Member 122681833-Apr-16 6:41 
AnswerRe: How to render multiple 3D objects separately? Pin Pin
Forrest9012-Jul-16 1:36
Forrest9012-Jul-16 1:36 
GeneralRe: How to render multiple 3D objects separately? Pin Pin
Romain3413-Jul-16 22:33
Romain3413-Jul-16 22:33 
QuestionD2D/GDI+ Interop Problem Pin
Member 1171275327-Feb-16 19:21
Member 1171275327-Feb-16 19:21 
I have recently read an article about Direct2D and GDI Interop from MSDN and I just wanted to make an attempt on that.

The problem with my code is that there is no (D2D) red rectangles at the output file but it does not produce any compile-time or runtime errors.

That really makes me frustrated as I have already spent my valuable weekend for that without any progress. Cry | :((

Any help is appreciated.Rose | [Rose]

Ref. article: Direct2D and GDI Interoperability Overview (Windows)[^]

Code block:
C++
#include<d2d1_2.h>
#include<gdiplus.h>
#include<iostream>
#include<wincodec.h>

#pragma comment(lib, "d2d1.lib")
#pragma comment(lib, "GdiPlus.lib")
#pragma comment(lib, "Windowscodecs.lib")

using namespace std;

void main()
{
	HRESULT hr;
	ID2D1Factory* factory;
	ID2D1DCRenderTarget* target;
	ID2D1SolidColorBrush* brush;

	D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &factory);

	// initialize GDI+
	ULONG_PTR token;
	Gdiplus::GdiplusStartup(&token, new Gdiplus::GdiplusStartupInput(), nullptr);


	auto image = new Gdiplus::Image(L"C:\\temp\\test.jpg");

	auto g = Gdiplus::Graphics::FromImage(image);

	auto prop = D2D1_RENDER_TARGET_PROPERTIES{
		D2D1_RENDER_TARGET_TYPE_HARDWARE ,
		D2D1_PIXEL_FORMAT{ DXGI_FORMAT_B8G8R8A8_UNORM , D2D1_ALPHA_MODE_PREMULTIPLIED },
		144.0f,
		144.0f,
		D2D1_RENDER_TARGET_USAGE_GDI_COMPATIBLE,
		D2D1_FEATURE_LEVEL_DEFAULT
	};


	hr = factory->CreateDCRenderTarget(&prop, &target);

	auto rect = RECT{ 0L,0L,800L, 600L };

	cout << boolalpha << (image == nullptr) << boolalpha << (g == nullptr) << endl;

	HDC deviceContext = g->GetHDC();

	// binds D2D device context to GDI+ device context.
	target->BindDC(deviceContext, &rect);

	// DrawRectangle using D2d
	target->BeginDraw();

	target->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Red, 1.0f), &brush);
	target->DrawRectangle(D2D1_RECT_F{ 5.0f,5.0f,10.0f,10.0f }, brush);
	target->DrawRectangle(D2D1_RECT_F{ 10.0f,10.0f,30.0f,30.0f }, brush);

	hr = target->EndDraw();

	cout << boolalpha << SUCCEEDED(hr) << endl;

	CLSID pngEncoderClsId = { 0x557cf406, 0x1a04, 0x11d3,{ 0x9a,0x73,0x00,0x00,0xf8,0x1e,0xf3,0x2e } };

	// Transcode and save as PNG image file
	image->Save(L"C:\\temp\\output.png", &pngEncoderClsId);

	Gdiplus::GdiplusShutdown(token);
}

AnswerRe: D2D/GDI+ Interop Problem Pin
Richard MacCutchan27-Feb-16 21:11
mveRichard MacCutchan27-Feb-16 21:11 
QuestionDirect3d Game programming error Pin
Member 1226818323-Feb-16 22:12
Member 1226818323-Feb-16 22:12 
SuggestionRe: Direct3d Game programming error Pin
Richard Deeming24-Feb-16 1:05
mveRichard Deeming24-Feb-16 1:05 
GeneralRe: Direct3d Game programming error Pin
Member 1226818324-Feb-16 20:15
Member 1226818324-Feb-16 20:15 
GeneralRe: Direct3d Game programming error Pin
Pete O'Hanlon24-Feb-16 22:03
mvePete O'Hanlon24-Feb-16 22:03 
GeneralRe: Direct3d Game programming error Pin
Archard25215-Jul-16 0:06
Archard25215-Jul-16 0:06 
GeneralRe: Direct3d Game programming error Pin
Richard MacCutchan24-Feb-16 1:19
mveRichard MacCutchan24-Feb-16 1:19 
AnswerRe: Direct3d Game programming error Pin
Pete O'Hanlon24-Feb-16 2:16
mvePete O'Hanlon24-Feb-16 2:16 
GeneralRe: Direct3d Game programming error Pin
Member 1226818324-Feb-16 20:17
Member 1226818324-Feb-16 20:17 
GeneralRe: Direct3d Game programming error Pin
Richard MacCutchan24-Feb-16 21:40
mveRichard MacCutchan24-Feb-16 21:40 
GeneralRe: Direct3d Game programming error Pin
Member 1226818325-Feb-16 0:40
Member 1226818325-Feb-16 0:40 
GeneralRe: Direct3d Game programming error Pin
Richard MacCutchan25-Feb-16 1:01
mveRichard MacCutchan25-Feb-16 1:01 
GeneralRe: Direct3d Game programming error Pin
Member 1226818325-Feb-16 3:21
Member 1226818325-Feb-16 3:21 
GeneralRe: Direct3d Game programming error Pin
Richard MacCutchan25-Feb-16 4:18
mveRichard MacCutchan25-Feb-16 4:18 
GeneralRe: Direct3d Game programming error Pin
Member 1226818325-Feb-16 5:11
Member 1226818325-Feb-16 5:11 
GeneralRe: Direct3d Game programming error Pin
Richard MacCutchan25-Feb-16 5:22
mveRichard MacCutchan25-Feb-16 5:22 
GeneralRe: Direct3d Game programming error Pin
Member 1226818326-Feb-16 21:43
Member 1226818326-Feb-16 21:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.