Jump to content

  • Log In with Google      Sign In   
  • Create Account


DirectX 11 , D3DX11CompileFromFile() missing.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 RoundPotato   Members   -  Reputation: 79

Like
0Likes
Like

Posted 01 May 2013 - 09:35 AM

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;
}

 

 



Sponsor:

#2 Khatharr   Crossbones+   -  Reputation: 2614

Like
0Likes
Like

Posted 01 May 2013 - 09:41 AM

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.


void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

#3 RoundPotato   Members   -  Reputation: 79

Like
0Likes
Like

Posted 01 May 2013 - 09:55 AM

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, 01 May 2013 - 09:57 AM.


#4 Zaoshi Kaba   Crossbones+   -  Reputation: 2860

Like
0Likes
Like

Posted 01 May 2013 - 10:19 AM

For security reasons. It seems any external libraries aren't allowed, so you have to static link everything; HLSL compiler is external library.



#5 unbird   Crossbones+   -  Reputation: 4011

Like
1Likes
Like

Posted 01 May 2013 - 10:49 AM

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.

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

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

#6 RoundPotato   Members   -  Reputation: 79

Like
0Likes
Like

Posted 01 May 2013 - 11:08 AM

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.



#7 unbird   Crossbones+   -  Reputation: 4011

Like
1Likes
Like

Posted 01 May 2013 - 11:37 AM

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).

#8 RoundPotato   Members   -  Reputation: 79

Like
0Likes
Like

Posted 01 May 2013 - 02:31 PM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS