• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Mohammed Abdulmonem

DX11
D3D11DeviceContext::DrawIndexed Does'nt Draw anything

8 posts in this topic

my program is Directx Program that draws a container cube within it smaller cubes....these smaller cubes fall by time i hope you understand what i mean...

The program isn't complete yet ...it should draws the container only ....but it draws nothing ...only the background color is visible... i only included what i think is needed ...

 

this is the routines that initialize the program

bool Game::init(HINSTANCE hinst,HWND _hw){
	Directx11 ::init(hinst , _hw);
	return LoadContent();
}

Directx11::init()

bool Directx11::init(HINSTANCE hinst,HWND hw){
	_hinst=hinst;_hwnd=hw;
	RECT rc;
	GetClientRect(_hwnd,&rc);
	height= rc.bottom - rc.top;
	width = rc.right - rc.left;
	UINT flags=0;
#ifdef _DEBUG
	flags |=D3D11_CREATE_DEVICE_DEBUG;
#endif
	HR(D3D11CreateDevice(0,_driverType,0,flags,0,0,D3D11_SDK_VERSION,&d3dDevice,&_featureLevel,&d3dDeviceContext));
	if (d3dDevice == 0 || d3dDeviceContext == 0)
		return 0;
	DXGI_SWAP_CHAIN_DESC sdesc;
	ZeroMemory(&sdesc,sizeof(DXGI_SWAP_CHAIN_DESC));
	sdesc.Windowed=true;
	sdesc.BufferCount=1;
	sdesc.BufferDesc.Format=DXGI_FORMAT_R8G8B8A8_UNORM;
	sdesc.BufferDesc.Height=height;
	sdesc.BufferDesc.Width=width;
	sdesc.BufferDesc.Scaling=DXGI_MODE_SCALING_UNSPECIFIED;
	sdesc.BufferDesc.ScanlineOrdering=DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
	sdesc.OutputWindow=_hwnd;
	sdesc.BufferDesc.RefreshRate.Denominator=1;
	sdesc.BufferDesc.RefreshRate.Numerator=60;
	sdesc.Flags=0;
	sdesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
	if (m4xMsaaEnable)
	{
		sdesc.SampleDesc.Count=4;
		sdesc.SampleDesc.Quality=m4xMsaaQuality-1;
	}
	else
	{
		sdesc.SampleDesc.Count=1;
		sdesc.SampleDesc.Quality=0;
	}
	IDXGIDevice *Device=0;
	HR(d3dDevice->QueryInterface(__uuidof(IDXGIDevice),reinterpret_cast <void**> (&Device)));
	IDXGIAdapter*Ad=0;
	HR(Device->GetParent(__uuidof(IDXGIAdapter),reinterpret_cast <void**> (&Ad)));
	IDXGIFactory* fac=0;
	HR(Ad->GetParent(__uuidof(IDXGIFactory),reinterpret_cast <void**> (&fac)));
	fac->CreateSwapChain(d3dDevice,&sdesc,&swapchain);
	ReleaseCOM(Device);
	ReleaseCOM(Ad);
	ReleaseCOM(fac);
	ID3D11Texture2D *back = 0;
	HR(swapchain->GetBuffer(0,__uuidof(ID3D11Texture2D),reinterpret_cast <void**> (&back)));
	HR(d3dDevice->CreateRenderTargetView(back,0,&RenderTarget));
	D3D11_TEXTURE2D_DESC Tdesc;
	ZeroMemory(&Tdesc,sizeof(D3D11_TEXTURE2D_DESC));
	Tdesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
	Tdesc.ArraySize = 1;
	Tdesc.Format= DXGI_FORMAT_D24_UNORM_S8_UINT;
	Tdesc.Height= height;
	Tdesc.Width = width;
	Tdesc.Usage = D3D11_USAGE_DEFAULT;
	Tdesc.MipLevels=1;
	if (m4xMsaaEnable)
	{
		Tdesc.SampleDesc.Count=4;
		Tdesc.SampleDesc.Quality=m4xMsaaQuality-1;
	}
	else
	{
		Tdesc.SampleDesc.Count=1;
		Tdesc.SampleDesc.Quality=0;
	}
	HR(d3dDevice->CreateTexture2D(&Tdesc,0,&depthview));
	HR(d3dDevice->CreateDepthStencilView(depthview,0,&depth));
	d3dDeviceContext->OMSetRenderTargets(1,&RenderTarget,depth);
	D3D11_VIEWPORT vp;
	vp.TopLeftX=0.0f;
	vp.TopLeftY=0.0f;
	vp.Width = static_cast <float> (width);
	vp.Height= static_cast <float> (height);
	vp.MinDepth = 0.0f;
	vp.MaxDepth = 1.0f;
	d3dDeviceContext -> RSSetViewports(1,&vp);
	return true;

LoadContent() Loads The Effect File No proplem in loading the effect file

 

this is the routine that creates the container and the smaller cubes meshes

bool Game::GeoBuild(){
	CreateInputLayout();
	CreateRasterizerState();
	CreateBox(30.0,30.0,30.0,Build);
	CreateBox(3.0,3.0,3.0,Piese);
	SetBuild(&B);

	build_vers_index = 0;
	build_vers_count= Build.vertices.size();
	build_ind_index= 0;
	build_ind_count=Build.indices.size();

	piese_vers_index = build_vers_count;
	piese_vers_count= Piese.vertices.size();
	piese_ind_index= build_ind_count;
	piese_ind_count=Piese.indices.size();

	UINT k=0;
	std::vector <Vertex> Vers(piese_vers_count + build_vers_count);
	for (UINT i = 0; i < build_vers_count; i++,k++)
	{
		XMStoreFloat4(&Build.vertices[i].Color,(XMVECTOR)Colors::Red);
		Vers[k]=Build.vertices[i];
	}
	for (UINT i = 0; i < piese_vers_count; i++ , k++)
	{
		XMStoreFloat4(&Piese.vertices[i].Color,(XMVECTOR)Colors::Green);
		Vers[k]=Piese.vertices[i];
	}
	

	D3D11_BUFFER_DESC desc;
	desc.BindFlags=D3D11_BIND_VERTEX_BUFFER;
	desc.ByteWidth=sizeof(Vertex) * (piese_vers_count + build_vers_count);
	desc.CPUAccessFlags=0;
	desc.MiscFlags=0;
	desc.Usage=D3D11_USAGE_IMMUTABLE;

	D3D11_SUBRESOURCE_DATA Data;
	ZeroMemory(&Data,sizeof(D3D11_SUBRESOURCE_DATA));
	Data.pSysMem=&Vers[0];

	HR(d3dDevice->CreateBuffer(&desc,&Data,&vertices));
	std::vector<UINT> inds(piese_ind_count + build_ind_count);
	k=0;
	for (UINT i = 0; i < build_ind_count; i++,k++)
	{
		inds[k]=Build.indices[i];
	}
	for (UINT i = 0; i < piese_ind_count; i++ , k++)
	{
		inds[k]=Piese.indices[i];
	}
	
	desc.BindFlags=D3D11_BIND_INDEX_BUFFER;
	desc.ByteWidth=sizeof(UINT) * inds.size();
	desc.CPUAccessFlags=0;
	desc.MiscFlags=0;
	desc.Usage=D3D11_USAGE_IMMUTABLE;
	ZeroMemory(&Data,sizeof(D3D11_SUBRESOURCE_DATA));
	Data.pSysMem=&inds[0];
	HR(d3dDevice->CreateBuffer(&desc,&Data,&indices));

	return true;
}

SetBuild() Prepare the matrices inside the container for the smaller cubes ....i didnt program it to draw the smaller cubes yet

 

and this the function that draws the scene

void Game::Render(){
	d3dDeviceContext->ClearRenderTargetView(RenderTarget,reinterpret_cast <const float*> (&Colors::LightSteelBlue));
	d3dDeviceContext->ClearDepthStencilView(depth,D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL,1.0f,0);

	d3dDeviceContext-> IASetInputLayout(_layout);
	d3dDeviceContext-> IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	d3dDeviceContext->IASetIndexBuffer(indices,DXGI_FORMAT_R32_UINT,0);
	UINT strides=sizeof(Vertex),off=0;
	d3dDeviceContext->IASetVertexBuffers(0,1,&vertices,&strides,&off);
	
	D3DX11_TECHNIQUE_DESC des;
	Tech->GetDesc(&des);Floor * Lookup;
	std::vector<XMFLOAT4X4> filled;
	XMMATRIX V=XMLoadFloat4x4(&View),P = XMLoadFloat4x4(&Proj);
	XMMATRIX vp = V * P;XMMATRIX wvp;XMFLOAT4X4 fwvp;
	for (UINT i = 0; i < des.Passes; i++)
	{
		d3dDeviceContext->RSSetState(BuildRast);
		wvp = XMLoadFloat4x4(&(B.Memory[0].Pieces[0])) * vp;
		XMStoreFloat4x4(&fwvp,wvp);
		HR(ShadeMat->SetMatrix(reinterpret_cast<float*> ( &wvp)));
		HR(Tech->GetPassByIndex(i)->Apply(0,d3dDeviceContext));
		d3dDeviceContext->DrawIndexed(build_ind_count,build_ind_index,build_vers_index);

		d3dDeviceContext->RSSetState(PieseRast);
		UINT r1=B.GetSize(),r2=filled.size();
		for (UINT j = 0; j < r1; j++)
		{
			Lookup = &B.Memory[j];
			for (UINT r = 0; r < Lookup->filledindeces.size(); r++)
			{
				filled.push_back(Lookup->Pieces[Lookup->filledindeces[r]]);
			}
		}
		for (UINT j = 0; j < r2; j++)
		{
			ShadeMat->SetMatrix( reinterpret_cast<const float*> (&filled[i]));
			Tech->GetPassByIndex(i)->Apply(0,d3dDeviceContext);
			d3dDeviceContext->DrawIndexed(piese_ind_count,piese_ind_index,piese_vers_index);
		}
	}
	HR(swapchain->Present(0,0));
}
0

Share this post


Link to post
Share on other sites

yes i am clearing the depth stencil buffer each frame is there any problem?...

my rasterizer state  is setted on CULL_MODE_FRONT .....because i want to see what in the container.....

i can't use PIX it always crashes even with the correctly working programs (i am using win7)..... i checked camera and matrices multiple Times and i even increased the Length of camera radius

but stills nothing ...

Thanks for your time

0

Share this post


Link to post
Share on other sites

You have some unusual code snippets. Are these what you intend?

UINT strides=sizeof(Vertex),off=0;
// did you mean
// UINT off = 0;
...
Tech->GetDesc(&des);Floor * Lookup; // "Floor * Lookup" does nothing

As Jason Z mentioned, have you checked that the geometry you create is within the view volume?

 

my rasterizer state  is setted on CULL_MODE_FRONT

 

Have you defined CULL_MODE_FRONT yourself, or do you intend D3D11_CULL_FRONT?

 

I would suggest you try rendering the cube normally - i.e., D3D11_CULL_BACK - and get that working.

0

Share this post


Link to post
Share on other sites


You have some unusual code snippets. Are these what you intend?
UINT strides=sizeof(Vertex),off=0;
// did you mean
// UINT off = 0;
...
Tech->GetDesc(&des);Floor * Lookup; // "Floor * Lookup" does nothing

As Jason Z mentioned, have you checked that the geometry you create is within the view volume?

yes i mean off =0, Lookup is variable to lookup the matrices of the smaller cubes there is no smaller cubes now so it should do nothing

 


Have you defined CULL_MODE_FRONT yourself, or do you intend D3D11_CULL_FRONT?
 
I would suggest you try rendering the cube normally - i.e., D3D11_CULL_BACK - and get that working.

 i set it to the default rasterizer state (RSSetState(0)) also changed the camera position to (0.0,0.0,0.0) and and the focus to (15.0,15.0,15.0) and radius to 50.0

is there anything else beside what jason said that can fail drawing ...i am new to this so there might be some deep details i missed...thanks

0

Share this post


Link to post
Share on other sites

Thanks Jason Z ..and Buckeye 

it is solved ....The Problem is simply 

in GeoBuild() (Mentioned in the Post )

std::vector<UINT> inds(piese_ind_count + build_ind_count); //cause of the bug
std::vector<UINT> inds                                     //works fine

i dont know why and how but i guess std::vector constructor fills its element by some values which corrupt the index buffer....

thanks all for your time

0

Share this post


Link to post
Share on other sites

Just  a follow up, if you pass an integer to the std::vector constructor, it will create a vector with that many elements in it that are default constructed if you don't pass a second value.  This is called the 'fill' constructor.  Since UINT doesn't have a default constructor mechanism, you end up with the contents of memory in your vector.

 

See #2 here: http://www.cplusplus.com/reference/vector/vector/vector/

Edited by Jason Z
1

Share this post


Link to post
Share on other sites

Since UINT doesn't have a default constructor mechanism, you end up with the contents of memory in your vector.

 

The parameter is declared as const value_type& val = value_type(), so it will perform zero initialization for built-in types:

int a; // garbage
int b = int(); // zero initialized
2

Share this post


Link to post
Share on other sites

 

Since UINT doesn't have a default constructor mechanism, you end up with the contents of memory in your vector.

 

The parameter is declared as const value_type& val = value_type(), so it will perform zero initialization for built-in types:

int a; // garbage
int b = int(); // zero initialized

Good call - I just tried it out and you are 100% correct.  I wonder how the OP was getting garbage in the vector then... I suppose if he has all 0's in the index buffer, and then pushes back all of his indices, it would look like a ton of senseless indices, but I don't know...

 

Thanks for the correction.

0

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  
Followers 0

  • Similar Content

    • By lonewolff
      Hi Guys,
      I am just wondering if it is possible to acquire the address of the backbuffer if an API (based on DX11) only exposes the 'device' and 'context' pointers?
      Any advice would be greatly appreciated
    • By MarcusAseth
      bool InitDirect3D::Init() { if (!D3DApp::Init()) { return false; } //Additional Initialization //Disable Alt+Enter Fullscreen Toggle shortkey IDXGIFactory* factory; CreateDXGIFactory(__uuidof(IDXGIFactory), reinterpret_cast<void**>(&factory)); factory->MakeWindowAssociation(mhWindow, DXGI_MWA_NO_WINDOW_CHANGES); factory->Release(); return true; }  
      As stated on the title and displayed on the code above, regardless of it Alt+Enter still takes effect...
      I recall something from the book during the swapChain creation, where in order to create it one has to use the same factory used to create the ID3D11Device, therefore I tested and indeed using that same factory indeed it work.
      How is that one particular factory related to my window and how come the MakeWindowAssociation won't take effect with a newly created factory?
      Also what's even the point of being able to create this Factories if they won't work,?(except from that one associated with the ID3D11Device) 
    • By ProfL
      Can anyone recommend a wrapper for Direct3D 11 that is similarly simple to use as SFML? I don't need all the image formats etc. BUT I want a simple way to open a window, allocate a texture, buffer, shader.
    • By lucky6969b
      Q1:
      Since there is no more fixed pipeline rendering in DX11, for every part of rendering in DX11, do I need to create a brand-new vertex shader and pixel shader... or at least I have to find one relevant online. If you work on skinned meshes and other effects originally worked in DX9 fixed pipeline, do I have to rework everything by now?
       
      Q2:
      For assimp, if it originally was designed for DX9, like it is coupled to a DX9 device for creating meshes and materials etc. Do I have to add in the DX11 device in the assimp, or can I just leave the assimp to remain in DX9 and after the meshes are loaded, I just convert the vertex buffers and index buffers into DX11 buffers?
      Thanks
      Jack
    • By MarcusAseth
      This header is mentioned in the book I'm reading but there is no documentation on msdn... Is it like an... outdated and abandoned header?
      If so, what's the current default/recomended library for handling errors with directX?
  • Popular Now