Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 24 Mar 2010
Offline Last Active Jul 20 2016 07:32 AM

#5301352 No Raw Input Key Up If I Press The Key Fast Enough?

Posted by on 19 July 2016 - 06:32 AM

I have managed to reproduce it in notepad. It doesn't happen when typing (probably because notepad uses the repeat events, which do not seem to be firing?), but the problem is visible with the alt key. Key down on alt will display underlines under the shortcut keys for the menu items, and key up will then highlight the first menu item (File). When I tap quickly tap alt, the shortcut underlines are displayed, but the menu item is never highlighted.


The fact that there are no repeat events seems strange. Are those generated by Windows, or the keyboard driver?

#5183047 Reflection problem in C#

Posted by on 25 September 2014 - 08:53 PM

You could use generic methods for arithmetic operators such as those provided by MiscUtil (http://www.yoda.arachsys.com/csharp/miscutil/usage/genericoperators.html), invoking, for example, Multiply<T>(T, T) through reflection.


However, that seems a bit overkill. Is there any reason you can't just cast the stat value from object to float when you're performing the arithmetic?

#5120941 Terrain rendering problem

Posted by on 03 January 2014 - 11:47 AM

Also, before that line there's a "Access violation reading location 0xFEEEFEEE", which would mean that something is referencing memory that has already been freed.



#5076267 C++ DX API, help me get it?

Posted by on 08 July 2013 - 09:01 PM

Allow me to pick off part of #6:


D3D11CreateDeviceAndSwapChain has two parameters that accept pointers to D3D_FEATURE_LEVEL. The first one is a pointer because it is actually looking for an array of D3D_FEATURE_LEVEL (and the parameter following that one is the number of elements in the array). The second one is a pointer because it is an output parameter to where the feature level that was actually selected can be stored.





Also, I expect that a lot of the reasons for the API being structured how it is are due to http://en.wikipedia.org/wiki/Component_Object_Model

#5075717 I can't see anything?

Posted by on 06 July 2013 - 08:24 AM

In your input layout, you specified DXGI_FORMAT_R32G32B32A32_FLOAT for position, but your triangle has 3 floats for position, not 4. Try changing it to DXGI_FORMAT_R32G32B32_FLOAT instead.

#5067834 Simple splash screen?

Posted by on 06 June 2013 - 10:38 AM

I believe Layered Windows are one (somewhat involved) way to do this.

#5042128 D2D + D3D11 help me to make them work together

Posted by on 11 March 2013 - 06:25 PM

Ok, so two things:


First, it looks like you are using a font that you don't have. Cambria is a serif font, but the font in your screenshot is sans-serif, so I think it is failing to find the font you specified and uses a fallback instead.



Second, everything looks correct when I draw text with my code (see attachment). How are you sizing your window and backbuffer? If you're passing the same dimensions to CreateWindow and D3D11CreateDeviceAndSwapChain, that could be the problem because CreateWindow includes the size of the border in the dimensions. So then you end up with a window that is smaller than your backbuffer, and everything gets scaled and looks horrible.


You should use AdjustWindowRect to take the size of the border into account, passing the same style used to create the window (ex. WS_OVERLAPPEDWINDOW). Then when calling CreateWindow, you should pass rect.right - rect.left as the width, and rect.bottom - rect.top as the height, because AdjustWindowRect might make the left and top values negative. Relevant snippet from my code above:


RECT r = {0, 0, 800, 600};
AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW, false);

HWND hWnd = CreateWindow(
	r.right - r.left,
	r.bottom - r.top,




Attached Thumbnails

  • text.png

#5041811 D2D + D3D11 help me to make them work together

Posted by on 11 March 2013 - 06:11 AM

Are you drawing text directly to the backbuffer with D2D? If so, its not using the depth buffer. You could try drawing the text last, or drawing the text to a texture first, and then drawing a quad using that texture.

#5040365 Model perspective issue in XNA

Posted by on 07 March 2013 - 07:11 AM

My guess is that the vertex windings are backwards, so it's being drawn inside-out. You can test that with the following line.

GraphicsDevice.RasterizerState = RasterizerState.CullClockwise;


The default behavior is to cull counter-clockwise.

#5039276 D2D + D3D11 help me to make them work together

Posted by on 04 March 2013 - 07:18 PM

As far as rendering the text to a texture, you use QueryInterface<T> as mentioned above to get an IDXGISurface1 pointer, and then pass that to ID2D1Factory::CreateDxgiSurfaceRenderTarget. Then you can just use that render target like the render target in my example above.

Example of render target creation:

// create the D3D11 texture

D3D11_TEXTURE2D_DESC texDesc = {};
texDesc.ArraySize = 1;
texDesc.Usage = D3D11_USAGE_DEFAULT;
texDesc.Width = 512;
texDesc.Height = 512;
texDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
texDesc.SampleDesc.Count = 1;
texDesc.MipLevels = 1;
ID3D11Texture2D *texture;
device->CreateTexture2D(&texDesc, NULL, &texture);

// create D2D render target using texture

ID2D1RenderTarget *renderTarget;
IDXGISurface1* dxgiSurface;
D2D1_RENDER_TARGET_PROPERTIES props = D2D1::RenderTargetProperties(
factory->CreateDxgiSurfaceRenderTarget(dxgiSurface, &props, &renderTarget);



For determining where the previous text ended on the screen...I think IDWriteFactory::CreateTextLayout and IDWriteTextLayout::GetMetrics might help. It looks like it can take care of wrapping text for you as well.

#5038418 D2D + D3D11 help me to make them work together

Posted by on 02 March 2013 - 08:17 AM

Actually, if you are on Windows 8 it was possible before the update. The update (http://support.microsoft.com/kb/2670838) was only for allowing it to work on Windows 7 as well.


Here is a sample for D3D-D2D interop on Windows 8. I didn't get a chance to look at it, but it might be useful.



Also, here's a quick example I threw together, using D2D to draw text to the backbuffer. It should also be possible to create a texture in D3D11, and then write to it with D2D. (I think you would use QueryInterface to get the IDXGISurface1 pointer from the texture, and then pass that to CreateDxgiSurfaceRenderTarget, but I'm not sure)


#include <Windows.h>
#include <d3d11.h>
#include <d2d1_1.h>
#include <dwrite_1.h>

#pragma comment(lib, "d2d1.lib")
#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "dwrite.lib")

	if (msg == WM_CLOSE)
	return DefWindowProc(hWnd, msg, wParam, lParam);

int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
	// create the window

	WNDCLASSEX wcex = { sizeof(WNDCLASSEX) };
	wcex.style = CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc = WndProc;
	wcex.cbClsExtra = 0;
	wcex.cbWndExtra = sizeof(LONG_PTR);
	wcex.hInstance = hInstance;
	wcex.hbrBackground = NULL;
	wcex.lpszMenuName  = NULL;
	wcex.hCursor  = LoadCursor(NULL, IDI_APPLICATION);
	wcex.lpszClassName = "Vector";
	ATOM a = RegisterClassEx(&wcex);

	RECT r = {0, 0, 800, 600};
	AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW, false);

	HWND hWnd = CreateWindow(
		r.right - r.left,
		r.bottom - r.top,

	// create the D3D device and swap chain


	DXGI_SWAP_CHAIN_DESC swapChainDesc = { };
	swapChainDesc.BufferCount = 1;
	swapChainDesc.BufferDesc.Width = 800;
	swapChainDesc.BufferDesc.Height = 600;
	swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
	swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
	swapChainDesc.OutputWindow = hWnd;
	swapChainDesc.SampleDesc.Count = 1;
	swapChainDesc.SampleDesc.Quality = 0;
	swapChainDesc.Windowed = true;

	IDXGISwapChain *swapChain;
	ID3D11Device *device;
	ID3D11DeviceContext *context;

	HRESULT hr = D3D11CreateDeviceAndSwapChain(

	// set up the D3D render target view to the back buffer

	ID3D11Texture2D *backBuffer;
	ID3D11RenderTargetView *backBufferView;
	swapChain->GetBuffer(0, IID_PPV_ARGS(&backBuffer));
	device->CreateRenderTargetView(backBuffer, NULL, &backBufferView);
	context->OMSetRenderTargets(1, &backBufferView, NULL);

	// create the D2D factory

	ID2D1Factory *factory;
	options.debugLevel = D2D1_DEBUG_LEVEL_INFORMATION;
	D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, options, &factory);

	// set up the D2D render target using the back buffer

	IDXGISurface *dxgiBackbuffer;
	swapChain->GetBuffer(0, IID_PPV_ARGS(&dxgiBackbuffer));
	ID2D1RenderTarget *d2dRenderTarget;
	D2D1_RENDER_TARGET_PROPERTIES props = D2D1::RenderTargetProperties(
	factory->CreateDxgiSurfaceRenderTarget(dxgiBackbuffer, props, &d2dRenderTarget);

	// create the DWrite factory

	IDWriteFactory1 *writeFactory;
	DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(writeFactory), (IUnknown**)(&writeFactory));

	// create the DRwite text format

	IDWriteTextFormat *textFormat;

	// create a brush

	ID2D1SolidColorBrush *whiteBrush;
	d2dRenderTarget->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::White), &whiteBrush);

	// draw the text
	const WCHAR *text = L"Hello World";
	d2dRenderTarget->DrawTextA(text, wcslen(text), textFormat, D2D1::RectF(0, 0, 800, 600), whiteBrush);

	ShowWindow(hWnd, true);

	MSG msg = {0};
	while (WM_QUIT != msg.message)
		if (PeekMessage( &msg, NULL, 0, 0, PM_REMOVE))
			TranslateMessage( &msg );
			DispatchMessage( &msg );
			swapChain->Present(0, 0);

#5038203 D2D + D3D11 help me to make them work together

Posted by on 01 March 2013 - 06:12 PM

I don't have a good resource available to explain this, but I just thought I'd let you know that Microsoft released a platform update on 2/26/2013 that makes a lot of the things in that article unnecessary. It's now possible to use D3D11 and D2D together directly, without having to create a D3D10.1 device and worry about synchronizing the resources.


If you've installed the update, you should be able to just create a D3D11 texture, get an IDXGISurface1 pointer from it, and then pass that to CreateDxgiSurfaceRenderTarget to create a D2D render target.

#5022503 Problem with my sky dome - big hole in the top!

Posted by on 17 January 2013 - 06:54 AM

It would probably be easier to identify the issue if you could post a screenshot of the problem.

#5010437 Could someone give me feedback on my algorithm?

Posted by on 13 December 2012 - 08:13 PM

Well then at least remove the "!" by switching the colors around Posted Image

rects[k]->set_fill_color((k+k/8)%2 ? Color::white : Color::red);

#4991149 High-poly model XNA 10 FPS !

Posted by on 17 October 2012 - 10:15 AM

Ok but how do i do that? how do I set only 300 caller per frame?

I'm not familiar with SketchUp, but it should have a way to combine the separate pieces.