Jump to content

  • Log In with Google      Sign In   
  • Create Account


BattleMetalChris

Member Since 06 Mar 2009
Offline Last Active May 16 2013 05:43 AM
-----

Topics I've Started

SampleLevel not returning alpha component

07 April 2012 - 03:31 AM

I'm sampling a texture in a Geometry shader. As you can't use Sample() in a GS, I'm using SampleLevel() and specifying the mip level (0 as I need to sample it at full resolution).

It's not picking up the alpha component of the texture though - the statement
float4 sample1 = Image.SampleLevel(samPoint, sampleCoords[0], 0, 0);
although the RGB components are correct, the alpha component is always 1.

The texture is a 32-bit .bmp with which I have created using another application I've written. I've checked the texture using the DirectX texture tool and the alpha channel is definitely present in the .bmp file.

I've also checked in my code in the debugger and also checked the format of the texture resource in pix and the texture is definitely being loaded as an R8G8B8A8_UNORM.



EDIT:
Actually, looking at the resource in Pix, the alpha channel is completely white, so it looks like the problem is to do with loading the texture rather than sampling it. Is there anything special I need to specify when I load the texture so it'll pick up the alpha channel from a 32 bit .bmp file?

This how I load my texture:
ID3D10ShaderResourceView* texView = 0;
HRESULT hr = D3DX10CreateShaderResourceViewFromFile(m_device, fileName.c_str(), loadInfo, 0, &texView, 0);

Using strings in HLSL

28 March 2012 - 07:08 PM

I'm making a shader that will draw a line of text to the screen using a bitmap containing all the characters needed (this is mainly because I can't get DrawText() to work at all.)

The way I am intending to implement it is that I've used a little tool I've written to encode the bounding box coords in uv-space of each character into the pixels in the top few lines of the bitmap. I then pass the bitmap and my line of text into the shader - for each character in the text string, the geometry shader draws a quad and uses the ascii value of the character to lookup into the texture and get the uv coords for that character.

Now I've come to write the .fx file I've come up against a problem I'd expected to be trivial; How can I pass a string into the shader and then access it?

The HLSL reference says that there is a string type, but that 'There are no operations or states that accept strings, but effects can query string parameters and annotations.' Does this mean I can pass one in, but can't read it? Or define one within the shader, but can't pass one in? The (untested) code I have to pass the string into the shader is:
m_textStringVar->SetRawValue((void*)text.data(), 0, text.length() * sizeof(char));
where 'text' is a std::string and m_textStringVar is an ID3D10EffectStringVariable*

Alternative to singleton

15 March 2012 - 10:07 AM

After reading this thread, I started considering the singletons I use in my own project (my own DX10 renderer)

I currently have a few manager classes, (mainly for loading, storing and distributing resources) implemented using the Curiously Recurring Template pattern. This was done to stop me having to pass them in as a reference to everything that might need a resource; if anything needs a resource, it can just ask for one by calling a static function which then calls the non-static one in the instance and the manager takes care of creation, reference counting and destruction.

This struck me as nicely elegant and stripped out lots of cases where I was passing 2 or 3 references in, every time I created something like a game entity (MeshManager, TextureManager, InputManager etc), but reading up I've been seeing that this might not be as good an idea as I thought.

Why is reference passing 'better', and is there a better way of doing it than just putting references in the constructor arguments of the objects that need to use them? Or is it ok to continue as I am?

Why does my win32 application terminate early?

12 March 2012 - 03:20 PM

This is driving me insane.

I've had some time off my main project, - my own DX10 rendering system comprising some 20,000 lines of code - and have this week come back to it.

I've found it's (for no reason I can work out) terminating around 15 seconds into execution. With some murderous application of comment tags, I've stripped the entire thing back to just window creation and message loop in one main.cpp file (I've commented out all the preprocessor lines in there too) and it's STILL doing it.

It's not a quit message - I've placed breakpoints after the message loop terminates and it never reaches them.

For what it's worth, this is the current program as it's currently set to compile, in it's entirety:



#include <windows.h>



LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);


int g_clientWidth = 800;
int g_clientHeight = 600;


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int showCmd)
{
		
	WNDCLASS wc;

	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hbrBackground = (HBRUSH)::GetStockObject(BLACK_BRUSH);
	wc.hCursor = ::LoadCursor(0, IDC_ARROW);
	wc.hIcon = ::LoadIcon(0, IDI_APPLICATION);
	wc.hInstance = hInstance;
	wc.lpfnWndProc = WinProc;
	wc.lpszClassName = "Poo\n";
	wc.lpszMenuName = NULL;
	wc.style = CS_HREDRAW | CS_VREDRAW;

	RegisterClass(&wc);

	HWND hWnd = 0;
	hWnd = ::CreateWindow(wc.lpszClassName, "Caption", WS_POPUP, 0, 0, g_clientWidth, g_clientHeight, NULL, NULL, hInstance, 0);
	ShowWindow(hWnd, showCmd);
	UpdateWindow(hWnd);

	
	MSG msg;
	ZeroMemory(&msg, sizeof(MSG));

	while (msg.message != WM_QUIT)
	{
		if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
		{
			// game loop
		
		}
	}
	MessageBox(0, "Finished", "FPS", MB_OK);
	return 0;
}



LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
		
	case WM_KEYDOWN:
		switch (LOWORD(wParam))
		{
		case VK_ESCAPE:
			
			DestroyWindow(hWnd);
			return 0;
			
		}
		break;

	}
	return DefWindowProc(hWnd, msg, wParam, lParam);
}



Does anyone have ANY idea how I might go about getting to the bottom of this? Various attempts at googling just find tutorials about terminating an application, not ways of stopping it terminating.

Win32 scrollbars

09 March 2012 - 08:01 PM

I have a dialog window which I create from a resource. It has a couple of scrollbar controls on it (not the default vertical/horizontal scrollbars on a window, these have been manually placed)

I set their max range and position when I create the dialog, and they display fine, with the thumb at 'zero' and of an appropriate size for the range and page size I specify. The problem I'm having is that when I drag the thumb into a new position, as soon as I let go they 'pop' back to their original place. From reading the documentation, I was under the impression that they automatically update the thumb's position variable when they are dragged, so I just need to call GetScrollInfo and extract the thumb position. The position of mine is always zero however.

Is there a 'just been dragged' message I need to capture to update the scrollbar's position variable myself?

PARTNERS