• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

DirectX Tutorial

Status
Not open for further replies.
Level 10
Joined
Sep 14, 2007
Messages
227
Oh thanks, by the way does directx9, directx10, directx11 programing basics all same? Because now I'm trying to learn directx9 and I wonder if i won't gona have some problems if I decide to use newer version of directx (for example directx11).
 
Level 15
Joined
Oct 18, 2008
Messages
1,588
Stick to DX10, since many video cards are not DX11 compatible yet, but afaik most of them are for DX10 by now. And I think the basics should be the same, but the site has tutorials from the basics, so you may just quickly read through the first few code examples and see if it's too different (I haven't spent too much time with DirectX so far).
 
Level 15
Joined
Oct 18, 2008
Messages
1,588
As far as I am aware, both Nvidia and AMD no longer make graphic cards that are not fully DX11.1 compatible...

That's true, but you know just as well as I do that it takes a few years for the currently used graphic cards to be replaced. Also, I'm not sure integrated GPUs (Intel Mobile HD 3000-4000 series) can handle DX11, so, even though these can handle moderate 3D (heavily depending on resolution), they may not be able to deal with DX11. Not sure about this though.

EDIT: Yep, these can't handle DX11, so if you are making something not so graphically intense (bear in mind that even a game like GW2 or Warframe can be played with an Intel HD Graphics 3000 series), then be considerate with notebook users and use DX10 for now :)
 
Last edited:
Level 10
Joined
Sep 14, 2007
Messages
227
I'm just wondering maybe I should try to learn directx10 or 11 instead of 9. Because I saw some functions kind different like creating buffer.
By the way I started only day ago direct x and I have few questions: for example then u creating vertex array smth like that. Does all game models vertices gona use this veriable?
CUSTOMVERTEX vertices[] =
{
{ -3.0f, -3.0f, 3.0f, 0.0f, 0.0f, 1.0f, }, // side 1
{ 3.0f, -3.0f, 3.0f, 0.0f, 0.0f, 1.0f, },
{ -3.0f, 3.0f, 3.0f, 0.0f, 0.0f, 1.0f, },
{ 3.0f, 3.0f, 3.0f, 0.0f, 0.0f, 1.0f, },

{ -3.0f, -3.0f, -3.0f, 0.0f, 0.0f, -1.0f, }, // side 2
{ -3.0f, 3.0f, -3.0f, 0.0f, 0.0f, -1.0f, },
{ 3.0f, -3.0f, -3.0f, 0.0f, 0.0f, -1.0f, },
{ 3.0f, 3.0f, -3.0f, 0.0f, 0.0f, -1.0f, },

{ -3.0f, 3.0f, -3.0f, 0.0f, 1.0f, 0.0f, }, // side 3
{ -3.0f, 3.0f, 3.0f, 0.0f, 1.0f, 0.0f, },
{ 3.0f, 3.0f, -3.0f, 0.0f, 1.0f, 0.0f, },
{ 3.0f, 3.0f, 3.0f, 0.0f, 1.0f, 0.0f, },

{ -3.0f, -3.0f, -3.0f, 0.0f, -1.0f, 0.0f, }, // side 4
{ 3.0f, -3.0f, -3.0f, 0.0f, -1.0f, 0.0f, },
{ -3.0f, -3.0f, 3.0f, 0.0f, -1.0f, 0.0f, },
{ 3.0f, -3.0f, 3.0f, 0.0f, -1.0f, 0.0f, },

{ 3.0f, -3.0f, -3.0f, 1.0f, 0.0f, 0.0f, }, // side 5
{ 3.0f, 3.0f, -3.0f, 1.0f, 0.0f, 0.0f, },
{ 3.0f, -3.0f, 3.0f, 1.0f, 0.0f, 0.0f, },
{ 3.0f, 3.0f, 3.0f, 1.0f, 0.0f, 0.0f, },

{ -3.0f, -3.0f, -3.0f, -1.0f, 0.0f, 0.0f, }, // side 6
{ -3.0f, -3.0f, 3.0f, -1.0f, 0.0f, 0.0f, },
{ -3.0f, 3.0f, -3.0f, -1.0f, 0.0f, 0.0f, },
{ -3.0f, 3.0f, 3.0f, -1.0f, 0.0f, 0.0f, },
};

And second question would be: then u are creating materials with lighting u need to create for each vertex 3 more, is it really necessary? Or mybe in directx10/11 its changed.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
I'm just wondering maybe I should try to learn directx10 or 11 instead of 9.
Direct3D 9 is old and obsolete. Once the Xbox One is out no one will write with it anymore since currently people only write support for it due to the Xbox 360 using a port of it. The Xbox One will probably use D3D 11.

Does all game models vertices gona use this veriable?
The game model meshes should be stored in buffers on the GPU. I think the vertex shader step is responsible for collecting together all the meshes into the scene geometry.


And second question would be: then u are creating materials with lighting u need to create for each vertex 3 more, is it really necessary? Or mybe in directx10/11 its changed.
It is only necessary if you want that level of flexibility. You could probably use a shader where they are all defined as constants across of vertices if that is what you wish.
 
Level 10
Joined
Sep 14, 2007
Messages
227
Yeah I tried that d3d11 its almost completly different from d3d9 and very complexed, especialy that shaders with HSLS code and never ending buffers and endless numbers of COM that is so hard to remember :/. Funiest part that in D3D9 I created cuber with simple lighting in smth like 8 hours, but with D3D11 I can't even go through simple triangle like few days.... Mybe I should try OpenGl I saw its quite newbie-friendly with new libraries. Any suggestions, I'm quite desperated now, feels like being moron that can;t get how d3d11 works :/. But after I saw Open gl/Glut its looks kind stupid for me then u able to create 3d window with like almost 40 lines, it doesn't feel like progaming.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
New versions of Direct3D/OpenGL revolve around arbitrary binary buffers, and shaders that interpret them and use them in any way you can imagine.

If you want an easy start, you can go with the old APIs (also known as immediate mode), but once you will want to go a little advanced, you will have to discard nearly all of what you learned and re-learn how to do it all with buffers and shaders.

As to creating a window and an OpenGL context, there are libraries that help you handle that, such as freeglut, SFML, SDL, GLFW, and so on, but if you are thinking that's the interesting part, you are missing the point.
Of course you can go and handle all of it by yourself with the OS API (e.g. Win32 API), but it's boring and irrelevant to the fun stuff, which is showing things on the screen!

Don't despair. When you first start out, there are many things you need to learn at the same time (mainly buffers, shaders, and how to connect them together), so it's a bit hard, but once you start getting the hang of it, you will see the amazing freedom they give you.

If you think this is too much of an undertaking, and prefer to just show things on the screen without all the hassle, you can use a 2D (SDL, SFML, others) or 3D (Ogre3D, Irrlicht, others) library of course, or go to the full blown solutions (Unity, UDK, others).
 
Level 10
Joined
Sep 14, 2007
Messages
227
Hi I got a little problem, I want to update buffer, but can't find how. There is a function. I marked in Dark Green code that should be in other function (like creating new model), but just for faster testing I putted it in initializer, so how should I update buffer with this new three vertices (m_vertices[3],m_vertices[4],m_vertices[5]) and indices. :vw_wtf: Because I want to create function that ables to create model during rendering (like in pc gaming spawning monsters or just appearing terrain).


I saw few functions like CopyResource (don't know how to implant it) also memcpy (doesn't work).

Code:
void ModelClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceContext)
{
	m_indexCount = 3;
	m_vertexCount = 3;

	m_vertices[0].position = D3DXVECTOR3(-1.0f, -1.0f, 0.0f);
	m_vertices[0].color = D3DXVECTOR4(1.0f, 1.0f, 0.0f, 0.0f);

	m_vertices[1].position = D3DXVECTOR3(1.0f, -1.0f, 0.0f);
	m_vertices[1].color = D3DXVECTOR4(1.0f, 1.0f, 0.0f, 0.0f);

	m_vertices[2].position = D3DXVECTOR3(1.0f, 1.0f, 0.0f);
	m_vertices[2].color = D3DXVECTOR4(1.0f, 1.0f, 0.0f, 0.0f);

	m_indices [0] = 0;
	m_indices [1] = 2;
	m_indices [2] = 1;


	//Create vertex buffer
	m_vertexBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
	m_vertexBufferDesc.ByteWidth = sizeof(VertexType) * m_vertexCount;
	m_vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	m_vertexBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
	m_vertexBufferDesc.MiscFlags = 0;
	m_vertexBufferDesc.StructureByteStride = 0;

	//Creates a pointer to vertex array
	D3D11_SUBRESOURCE_DATA vertexData;
	vertexData.pSysMem = m_vertices;
	vertexData.SysMemPitch = 0;
	vertexData.SysMemSlicePitch = 0;

	device->CreateBuffer(&m_vertexBufferDesc, &vertexData, &m_vertexBuffer);


	//Create index buffer
	m_indexBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
	m_indexBufferDesc.ByteWidth = sizeof(unsigned long) * m_indexCount;
	m_indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
	m_indexBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
	m_indexBufferDesc.MiscFlags = 0;
	m_indexBufferDesc.StructureByteStride = 0;

	//Creates a pointer to index array
	D3D11_SUBRESOURCE_DATA indexData;
	indexData.pSysMem = m_indices;
	indexData.SysMemPitch = 0;
	indexData.SysMemSlicePitch = 0;

	device->CreateBuffer(&m_indexBufferDesc, &indexData, &m_indexBuffer);
	
	[COLOR="DarkGreen"]m_indexCount = 6;
	m_vertexCount = 6;

	m_vertices[3].position = D3DXVECTOR3(-5.0f, -1.0f, 0.0f);
	m_vertices[3].color = D3DXVECTOR4(1.0f, 1.0f, 0.0f, 0.0f);

	m_vertices[4].position = D3DXVECTOR3(-3.0f, -1.0f, 0.0f);
	m_vertices[4].color = D3DXVECTOR4(1.0f, 1.0f, 0.0f, 0.0f);

	m_vertices[5].position = D3DXVECTOR3(-3.0f, 1.0f, 0.0f);
	m_vertices[5].color = D3DXVECTOR4(1.0f, 1.0f, 0.0f, 0.0f);

	m_indices [3] = 4;
	m_indices [4] = 3;
	m_indices [5] = 5;[/COLOR]
	return;
}

By the way I got one more question about buffers, then I create them for exmaple CreateBuffer() its means they are created in GPU or in CPU?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
By the way I got one more question about buffers, then I create them for exmaple CreateBuffer() its means they are created in GPU or in CPU?

I am a bit rusty but I believe it can make them on both. Depending on buffer type it will be optimized differently. GPU only buffers (write to with CPU once, never read or only ever used in the GPU (internal buffers)) are the fastest. Ones which you need to read data from with the CPU often are the slowest. This only applies for platforms with dedicated memory pools for the GPU and CPU, on the Xbox 360 and Xbox One all buffers are allocated in the same memory pool and can be accessed by both the CPU and GPU highly efficiently (only standard thread safe practices required).
 
Status
Not open for further replies.
Top