Jump to content

  • Log In with Google      Sign In   
  • Create Account

Dimension10

Member Since 27 Jan 2011
Offline Last Active Jul 20 2013 08:49 PM

Topics I've Started

Invalid arguments when creating texture.

18 July 2013 - 10:01 AM

I'm trying to create a texture for screen capture so I can grab the 1x1 mipmap to get the average color of the screen.

 

However, when I try to create the texture, it tells me I'm passing an invalid parameter (See error handling below), and I can't quite figure out what I'm missing here.

 

For those who know, it should be quick to spot.

	//Create Texture
	D3D10_TEXTURE2D_DESC	tBufferDesc;
	ID3D10Texture2D			*tBuffer = NULL;
	DXGI_SAMPLE_DESC		iBufferSamples = {1,0};
	tBufferDesc.Width		=	iScreenSizeX;
	tBufferDesc.Height		=	iScreenSizeY;
	tBufferDesc.MipLevels	        =	0;
	tBufferDesc.ArraySize	        =	1;
	tBufferDesc.Format		=	DXGI_FORMAT_R8G8B8A8_UINT;
	tBufferDesc.SampleDesc	        =	iBufferSamples;
	tBufferDesc.Usage		=	D3D10_USAGE_DEFAULT;
	tBufferDesc.BindFlags	        =	D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_RENDER_TARGET;
	tBufferDesc.CPUAccessFlags      =       D3D10_CPU_ACCESS_READ;
	tBufferDesc.MiscFlags	        =	D3D10_RESOURCE_MISC_GENERATE_MIPS;
	
	HRESULT tBufferResult = pDevice->CreateTexture2D(&tBufferDesc, NULL , &tBuffer);
	switch(tBufferResult)
	{
	case E_FAIL:
		::MessageBoxA(NULL, "Attempted to create a device with the debug layer enabled and the layer is not installed.", "E_FAIL", NULL);
		return E_FAIL;
	case D3D10_ERROR_FILE_NOT_FOUND:
		::MessageBoxA(NULL, "The file was not found.", "D3D10_ERROR_FILE_NOT_FOUND", NULL);
		return E_FAIL;
	case D3D10_ERROR_TOO_MANY_UNIQUE_STATE_OBJECTS:
		::MessageBoxA(NULL, "There are too many unique instances of a particular type of state object.", "D3D10_ERROR_TOO_MANY_UNIQUE_STATE_OBJECTS", NULL);
		return E_FAIL;
	case E_INVALIDARG:
		::MessageBoxA(NULL, "An invalid parameter was passed to the returning function.", "E_INVALIDARG", NULL);
		return E_FAIL;
	case E_OUTOFMEMORY:
		::MessageBoxA(NULL, "Direct3D could not allocate sufficient memory to complete the call.", "E_OUTOFMEMORY", NULL);
		return E_FAIL;
	case S_FALSE:
		::MessageBoxA(NULL, "Alternate success value, indicating a successful but nonstandard completion (the precise meaning depends on context).", "S_FALSE", NULL);
		return E_FAIL;
	case S_OK:
		::MessageBoxA(NULL, "No error occurred.", "S_OK", NULL);
		break;

	}

Does the Windows 7 interface (GDI?) utilize the framebuffer?

16 July 2013 - 06:27 PM

Right now, I'm working on a method for quickly grabbing the average screen color and spewing it out to my arduino to control my room's RGB strips.

 

 

I've been using mostly device contexts like GetDC(NULL) and then using StretchBlt to "stretch" it down to one pixel. But that seems like a ludicrous number of calls in total. I see about 15 fps and 6% cpu usage. (When grabbing one pixel, it's probably 100+ fps with <1% usage.)

 

 

 

 

But, I've heard there's a way to directly access the GPU's framebuffer. In which case, if GDI uses the framebuffer, I could grab the frame and have the GPU do the averaging massively parallel via CUDA, then send the returned color directly to the Arduino.

 

But that would depend strictly on if the windows GUI uses the framebuffer. (And perhaps how much initialization it would take to access it.)

 


Using INI files

13 June 2013 - 10:42 PM

So I'm working with DirectX, and I'm wanting to have most of my main configuration constants stored in an .ini file.

 

I used this method originally:

http://www.codeproject.com/Articles/10809/A-Small-Class-to-Read-INI-File

 

I combined the two classes into a single class with a single header and .cpp file, with a couple of my own tweaks. Worked like a charm! It's nice beting able to choose file/section/key/value, and declare each file as its own object.

 

 

However, when trying to implement this into windows programs, it seems to work differently.

 

 

In the case here:

 

GetPrivateProfileString(szSection, szKey, szDefault, szResult, 255, m_szFileName); 

 

I get errors because it's trying to pass char* pointers, but I guess the winAPI version looks for an LPCTSTR instead. 

 

So if I change all char* to LPCTSTR, then memset and memcpy have issues, since they are looking for a char*

 

 

 

 

 

All that aside, is there an easy method for working with .ini files? I know they're considered outdated, but it's used heavily in the Unreal Engines, and I prefer that method of configuration over using the registry as M$ recommends.


Using the message loop in another source file?

08 June 2013 - 02:14 PM

So after learning a bit about DirectX, I understand that most of what goes on happens inside the message loop.

 

 

Is there any way to take everything inside the message loop and reference it to another file? I would rather not have all my game code crumpled up into one source file.

 

 

I tried creating a function, void Game(), which is called within the message loop. I declared it in a header file, and defined it in another source file that had the same #includes as the main source file. However, any of the creation, drawing, and present commands are unrecognized. I'm guessing it's referencing something within WinMain().

 

But the only immediate way I could see this being resolved is by including the main source file, which is a horrible idea. Either that, or inputting all the necessary functions as parameters.  (Which would either be tons of parameters, or a really large struct.)

 

But I see games and tutorials that are able to use a simple Game() function...

 

 

 

 

So if not, how can I do all my drawing somewhere BESIDES the main source? I would rather put the initialization as far behind me as possible.


Just getting my hands dirty. Questions for starting out.

07 June 2013 - 01:56 PM

Hello all. I just now joined this site, and I had a few questions before I start getting my hands too dirty in game development.

 

(You can just skip over Goal and Knowledge. They're just there to give context.)

 

///////////////////////////////////////////////////////////////

Goal:

 

-I would like to design custom 3D engines, as well as GUI's to make game development more of a GUI experience. I used .werkkzeug for quite some time, and have become rather fond of the interface.

 

To me, creating my own sets of graphics methods is more interesting than the actual game development.

 

Knowledge:

 

-I know a lot of the concepts already, such as rasterization, shaders, normal mapping, tesselation, deferred rendering, etc. I'm especially interested in Voxel-based Global Illumination. What I lack is the actual implementation.

 

-I've been spending the summer learning C++, including object-oriented programming.

 

-I have some math under my belt: Differential/Integral/Mulltivariable Calculus, Linear Algebra, and two semesters of Differential Equations.

///////////////////////////////////////////////////////////////////////////////////////////

 

 

Okay, so here are my questions:

 

1) Which would you recommend: DirectX or OpenGL? Which is generally easier to work with, and what are the differences?

 

2) I notice that DX projects have some brutal initialization. It looks like 20+ headers and sources just to make a window. I understand some of the stages, but is this normally all done manually, or is it more common to start off with a framework, and add in what you need?


PARTNERS