|
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.
Any help is appreciated.
Ref. article: Direct2D and GDI Interoperability Overview (Windows)[^]
Code block:
#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);
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();
target->BindDC(deviceContext, &rect);
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 } };
image->Save(L"C:\\temp\\output.png", &pngEncoderClsId);
Gdiplus::GdiplusShutdown(token);
}
|
|
|
|
|
You are trying to do this in a console application. I do not think that will work since you have no Window to draw on. You need to create a Windows app to do it.
|
|
|
|
|
Hi
I use the following link for starting an application with direct3d:
file:///D:/SoftwareProjects/Help/A%20Primer%20of%20DirectX%20Basics%20and%20the%20DirectX3D%20API%20-%20CodeProject.htm
I use this book too: Introduction to 3D Game Programming, written by Frank Luna
I use Microsoft Visual Studio 2012 C++ and Microsoft DirectX SDK (June 2010).
I have the following errors during debug of my application.
in the file DirectInput.cpp at the following lines:
HR(mKeyboard->Acquire());
HR(mMouse->Acquire());
The error is: one box appears with the following text:
Unexpected error encountered.
X Error
with buttons: YES/ NO
I don't know how to attach a screenshot of the error to the message.
Could you please help me to resolve the problem.
Also in DirectInput.h
I changed the declaration of the following:
extern DirectInput* gDInput;
in static DirectInput* gDInput;
Regards
|
|
|
|
|
Member 12268183 wrote: file:///D:/SoftwareProjects/Help/A%20Primer%20of%20DirectX%20Basics%20and%20the%20DirectX3D%20API%20-%20CodeProject.htm
You do realise we can't access your computer, right? A link to an HTML file stored on your computer is absolutely useless to us.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
You should ask your question on the forum at the end of the article. It's the best place to get help.
This space for rent
|
|
|
|
|
|
Changing a header file declaration usually ends in tears, unless you really understand the implications.
|
|
|
|
|
Member 12268183 wrote: I changed the declaration of the following:
extern DirectInput* gDInput;
in static DirectInput* gDInput; Do you think there might be a connection?
This space for rent
|
|
|
|
|
I don't know. If I put extern DirectInput* gDInput I receive the following error during the build process:
1> Generating Code...
1>CubeDemo.obj : error LNK2001: unresolved external symbol "class DirectInput * gDInput" (?gDInput@@3PAVDirectInput@@A)
1>SpriteDemo.obj : error LNK2001: unresolved external symbol "class DirectInput * gDInput" (?gDInput@@3PAVDirectInput@@A)
1>winmain.obj : error LNK2019: unresolved external symbol "class DirectInput * gDInput" (?gDInput@@3PAVDirectInput@@A) referenced in function "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::assign(char const *)" (?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@PBD@Z)
1>D:\SoftwareProjects\C++\book_ex1\Debug\book_ex1.exe : fatal error LNK1120: 1 unresolved externals
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
|
|
|
|
|
The linker is merely telling you that you forgot to provide a definition of the object that has been declared extern . You need to provide a line such as the following in one (and only one) of your source files:
DirectInput * gDInput =
|
|
|
|
|
Hi
I add extern DirectInput* gDInput; in DirectInput.h file. At the beginning of the file DirectInput.cpp I add DirectInput* gDInput = 0;
After the build process I received no errors. But during the debug process I still have the same error on the line in DirectInput.cpp:
HR(mKeyboard->Acquire());
One message box appears with the following message:
Unexpected error encountered: XFile with two buttons Yes/No
Regards
|
|
|
|
|
Then you need to use your debugger to find out why the error occurred. Randomly changing source code is not a very good way to try and resolve problems.
|
|
|
|
|
 I try to find the error using debug but till the moment it is not successful. The debuger is going in files as output.c, ullrem.asm, ulldiv.asm, vsprintf.c,
The debuger is passing through no source available point and continues till:
book_ex1.exe!DXTraceA(const char*strFile, unsigned long dwLine, HRESULT hr, const char*strMsg, int bPopMsgBox)Line 4828
Source file information:
Locating source for 'e:\temp\193462\obj.x86fre\misc\dxerr\objfre\i386\dxerra.cpp'. Checksum: Mo5 {62 b6 ef ba 67 f9 ac 6 4b 2 ec 8e 70 e7 46 a
The file 'e:\temp\193462\obj.x86fre\misc\dxerr\objfre\i386\dxerra.cpp' does not exist.
Looking in script documents for 'e:\temp\193462\obj.x86fre\misc\dxerr\objfre\i386\dxerra.cpp'...
Looking in the projects for 'e:\temp\193462\obj.x86fre\misc\dxerr\objfre\i386\dxerra.cpp'.
The file was not found in a project.
Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\crt\src\'...
Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\crt\src\vccorlib\'...
Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\src\mfc\'...
Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\src\atl\'... E}
Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\include'...
Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\src\mfc'...
Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\src\mfcm'...
Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\src\atl'...
|
|
|
|
|
You know where the exception occurs, add a breakpoint soemwhere before that point and run the program. When the breakpoint fires you can single step through the code and check all variables as you proceed, in order to find the offending value.
|
|
|
|
|
It is very difficult to find the error line because I look in Disassembly. I use step into and step out. Do you know better way to check errors in disassembly section.
|
|
|
|
|
Why are you looking in disassembly, when you have the source code?
|
|
|
|
|
Thank you very much for your help. Everythink is working well when I started the application without debuging.
|
|
|
|
|
|
Has anyone else found that a D3D9 full screen app (D3DCREATE_ADAPTERGROUP_DEVICE) that has worked well up to Win 8.1 fails with Windows 10 after the August update? d3d9->CreateDevice fails with D3DERR_INVALIDCALL. As I said... the code works with Win 8.1, Win 8, Win 7, Vista... and with original Windows 10 developer preview... but NOT after August update. Any tiny clue would be appreciated. I'd be happy to post present params, and other support code. Mainly, I'd like to know if anyone else has experienced this?
TwangGuru
www.twangguru.com
|
|
|
|
|
|
Thanks for your reply, but the answer is we're not "starting off". This is a product that has been sold for several years. There is no reason why a D3D9 application should not work on Windows 10... when the same application works fine in 8.1, etc. To redesign this product for D3D11 would take serious time, considering the development, testing and deployment cycles. This is NOT a simple D3D9 app... it's a complex application comprising 10000s of lines of codes and which is used in environment which demands high reliability. The port might be appropriate for a student project, but not the best path for this project.
TwangGuru
www.twangguru.com
|
|
|
|
|
How to paint right angle connecting line
it looks like as visio in mfc.
right angle connecting line
|
|
|
|
|
Use one of the GDI+[^] classes.
|
|
|
|
|
dx1 = u - x1 - x1^3
dx2 = -x2
how to make a diagram to analyze the bifurcation of the function
P.S. the x-axis of bifurcation is u
the y-axis of bifurcation is || X ||
{the amplitude (or norm) of the equilibrium point }
|
|
|
|