Drawing simple lines in DirectX10?

Started by
7 comments, last by ET3D 14 years, 3 months ago
Hi i have been searching around the Internet trying to find a answer to this simple question, all i can seem to find is people telling others to use IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_LINELIST ); and i did searches on that but cant understand its use, could anyone just give me a super quick example of drawing a line using this? i cant find a single example anywhere. thanks in advanced
Advertisement
What's the problem you're having?

Set the topology to D3D10_PRIMITIVE_TOPOLOGY_LINELIST

Draw a mesh with two verts. These verts will be the endpoints of your line.
Its not that im having a problem getting it to work, im just still incredibly new to Directx, and for a while i was using directx9 but im completely in the dark when using 10 :(. would i just use the directx device function draw to draw the mesh, its the simple things im having trouble with, like i have already made my own camera class, and loaded 3d models, but its hard to find a good example or any info on simple things..
So you currently have nothing drawing on-screen?

What are you having trouble with, specifically?

Here are the basic d3d10 tutorials:

http://msdn.microsoft.com/en-us/library/ee416410(VS.85).aspx
I currently just have it drawing a simple 3d model ( a space ship), the ship has a bounding box, which is represented by 4 sets of cords(x,and z, or in a 2d plane x and y), all im trying to do is draw a box to be able to see this box, all i need is a simple example of drawing one line and i can figure out the rest.
It's exactly the same as drawing a triangle mesh, except each primitive (line) is 2 verts instead of 3 (triangle). Just set the topology to a line list before drawing
Well the thing is, the only way i have seen how to draw something like a triangle is with vertex buffers, and effect systems, is there no simpler way? i mean i just want to get a my two verticies and tell it to put a line in between, i understand what your are saying, and how this is supposed to work,
Like what is with all this crap

SimpleVertex vertices[] =
{
D3DXVECTOR3( 0.0f, 0.5f, 0.5f ),
D3DXVECTOR3( 0.5f, -0.5f, 0.5f ),
D3DXVECTOR3( -0.5f, -0.5f, 0.5f ),
};
D3D10_BUFFER_DESC bd;
bd.Usage = D3D10_USAGE_DEFAULT;
bd.ByteWidth = sizeof( SimpleVertex ) * 3;
bd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = 0;
bd.MiscFlags = 0;
D3D10_SUBRESOURCE_DATA InitData;
InitData.pSysMem = vertices;
if( FAILED( g_pd3dDevice->CreateBuffer( &bd, &InitData, &g_pVertexBuffer ) ) )
return FALSE;

// Set vertex buffer
UINT stride = sizeof( SimpleVertex );
UINT offset = 0;
g_pd3dDevice->IASetVertexBuffers( 0, 1, &g_pVertexBuffer, &stride, &offset );

why is all this necessary? in DX9 you could just use draw primitives and what not?
I'm not sure exactly what you're comparing that code to, but maybe the biggest difference to you is that there's no more junky fixed-function pipeline stuff in D3D10. Everything is more programmable, so things are set up a little differently

Below I linked a decent rundown I found on the difference between using vertex buffers between D3D9 and D3D10. In reality the code is almost identical, looks like D3D10 needs a few extra lines of code here and there, but it's not that much.

APIs change - sorry ;) Part of programming is moving forward, it's all in the interest of progress!

http://members.gamedev.net/jhoxley/directx/DirectX10/VertexBuffersinDirect3D10.htm
If you just want to draw a 3D mesh as lines, like a bounding box, you can use a rasterizer state with FillMode set to D3D10_FILL_WIREFRAME.

This topic is closed to new replies.

Advertisement