Sign in to follow this  
RoundPotato

DirectX 11 , D3DX11CompileFromFile() missing.

Recommended Posts

RoundPotato    126

Hello everyone,

 

I am a typical beginner on a typical DirectX11 following a typical outdated tutorial: http://www.directxtutorial.com/Lesson.aspx?lessonid=11-4-5.

Now, I can't follow that since I have no "D3DX11CompileFromFile()" function, which I assume is in a "d3dx11.h" header which I do not have according to the crying compiler (Previously I got around the "D3DXCOLOR(...)" function by using a float array instead).

 

It seems that stuff is deprecated or something ? If that's the case what would be the new way ?

 

Thank you.

 

My code:

#include <windows.h>
#include <windowsx.h>
#include <d3d11.h>

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

#define SCREEN_WIDTH 1366
#define SCREEN_HEIGHT 786

// COM pointers
ID3D11Device *dev;
ID3D11DeviceContext *devCon;
IDXGISwapChain *sc;
ID3D11RenderTargetView *backBuffer;

float color[4] = {0.0,0.2,0.4,1.0};

void renderFrame()
{
	devCon->ClearRenderTargetView(backBuffer,color);

	if(color[1] < 1 && color[2] < 1 && color[0] < 1)
	{
		color[0] += (rand()%100+1)*0.001;
		color[1] += (rand()%100+1)*0.001;
		color[2] += (rand()%100+1)*0.001;
	}
	else
	{
		color[0] -= (rand()%100+1)*0.001;
		color[1] -= (rand()%100+1)*0.001;
		color[2] -= (rand()%100+1)*0.001;
	}

	// swap buffers
	sc->Present(0,0);
}

void initD3D(HWND hWnd)
{
	DXGI_SWAP_CHAIN_DESC scd;
	ZeroMemory(&scd,sizeof(DXGI_SWAP_CHAIN_DESC));

	scd.BufferCount = 1;
	scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	scd.BufferDesc.Width = SCREEN_WIDTH;
	scd.BufferDesc.Height = SCREEN_HEIGHT;
	scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
	scd.OutputWindow = hWnd;
	scd.SampleDesc.Count = 4;
	scd.Windowed = FALSE;
	scd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;

	D3D11CreateDeviceAndSwapChain(NULL,D3D_DRIVER_TYPE_HARDWARE,NULL,NULL,NULL,NULL,D3D11_SDK_VERSION,&scd,&sc,&dev,NULL,&devCon);

	ID3D11Texture2D *t2D;
	sc->GetBuffer(0,__uuidof(ID3D11Texture2D),(LPVOID*)&t2D);
	dev->CreateRenderTargetView(t2D,NULL,&backBuffer);
	t2D->Release();
	devCon->OMSetRenderTargets(1,&backBuffer,NULL);

	/* crappy viewport
	D3D11_VIEWPORT vp;
	ZeroMemory(&vp,sizeof(D3D11_VIEWPORT));

	vp.TopLeftX = 0;
	vp.TopLeftY = 0;
	vp.Width = SCREEN_WIDTH;
	vp.Height = SCREEN_HEIGHT;
	devCon->RSSetViewports(1,&vp);
	*/
}

void cleanD3D()
{
	sc->SetFullscreenState(FALSE,NULL);

	dev->Release();
	devCon->Release();
	backBuffer->Release();
	sc->Release();
}

LRESULT CALLBACK WndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
	switch(msg)
	{
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	}

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

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lCmdLIne,int nCmdShow)
{
	WNDCLASSEX wc;
	ZeroMemory(&wc,sizeof(WNDCLASSEX));

	wc.cbSize = sizeof(WNDCLASSEX);
	wc.hInstance = hInstance;
	wc.lpfnWndProc = WndProc;
	wc.style = CS_HREDRAW | CS_VREDRAW;
	//wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
	wc.hCursor = LoadCursor(NULL,IDC_ARROW);
	wc.lpszClassName = L"WindowClass1";

	RegisterClassEx(&wc);

	RECT wRect = {0,0,SCREEN_WIDTH,SCREEN_HEIGHT};
	AdjustWindowRect(&wRect,WS_OVERLAPPEDWINDOW,FALSE);
	HWND hWnd = CreateWindowEx(NULL,L"WindowClass1",L"BUCH MEGA WINDOW",WS_OVERLAPPEDWINDOW,0,0,wRect.right - wRect.left,wRect.bottom - wRect.top,NULL,NULL,hInstance,NULL);
	ShowWindow(hWnd,SW_SHOWMAXIMIZED);

	initD3D(hWnd);

	MSG msg = {0};

	while(true)
	{
		if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
			if(msg.message == WM_QUIT) break;
		}
		else
		{
			renderFrame();
			// 50 FPS  (1000/20)
			Sleep(20);
		}
	}

	cleanD3D();

	return msg.wParam;
}

 

 

Share this post


Link to post
Share on other sites
RoundPotato    126

http://msdn.microsoft.com/en-us/library/windows/desktop/ff476261%28v=vs.85%29.aspx

 

Microsoft's latest ridiculous madness is always on display at MSDN.

 

I'd appreciate if anyone could explain the situation rather than a raw link.

 

I'm not sure if I'm on the right track but I see:

Note  The D3DX (D3DX 9, D3DX 10, and D3DX 11) utility library is deprecated for Windows 8 and is not supported for Windows Store apps.

Note  Instead of using this function, we recommend that you compile offline by using the Fxc.exe command-line compiler or use one of the HLSL compile APIs, like the D3DCompileFromFile API.

 

So I think "Okay, I should use D3DCompileFromFile then". I go over to that functions' link and see:

Note  You can use this API to develop your Windows Store apps, but you can't use it in apps that you submit to the Windows Store.

 

Why ? Is this wrong ? There must be a reason or something.

Edited by RoundPotato

Share this post


Link to post
Share on other sites
unbird    8336
To clarify: You cannot compile shaders at runtime in a Windows Store app, though maybe statically linking works, can't confirm that. On a Windows Desktop D3DCompile works fine.

But you can load compiled shaders (binaries). You can also compile your shaders to binaries with the command line tool, e.g.

[tt]fxc.exe /E PS /T ps_4_0 /Fo ps.fxo ps.hlsl[/tt]

will compile the file ps.hlsl containing the pixel shader with entry PS() to the binary ps.fxo

Share this post


Link to post
Share on other sites
RoundPotato    126

I'm not entirely sure what you mean, but I suppose "pre-compiling" by adding includes to command line compiler makes one big self-contained chunk which is "secure" as opposed to including the same files externally ?

 

I'm not even sure what a "Windows Store app" is to be honest.

 

Well, I suppose "D3DCompileFromFile" should work and I should continue my little broadening on what is actually going on to draw anything on the screen.

Thanks for the help.

Share this post


Link to post
Share on other sites
unbird    8336
Ok, forget about Windows Store then, it doesn't really concern you.wink.png
 
I'd like to recommend alternative tutorials. DirectXTutorial has nice explanations, but it gets commercial at one point and lacks one crucial point almost completely: Error checking.

BraynzarSoft DX11 Tutorial
RasterTek DX11 Tutorial
And of course Luna!(Book source code, not a tutorial).

Share this post


Link to post
Share on other sites
RoundPotato    126

Ok, forget about Windows Store then, it doesn't really concern you.wink.png
 
I'd like to recommend alternative tutorials. DirectXTutorial has nice explanations, but it gets commercial at one point and lacks one crucial point almost completely: Error checking.

BraynzarSoft DX11 Tutorial
RasterTek DX11 Tutorial
And of course Luna!(Book source code, not a tutorial).

 

Many thanks for the links, it's relevant seeing as I'm on the last chapter of the free tutorials.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this