Archived

This topic is now archived and is closed to further replies.

D3D DrawPrimitive doubt

This topic is 6390 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all. I''m new in D3D so maybe I go to ask a silly question but here is: I''m programming a Quake3 BSP viewer with DirectX7. In q3a some polygons have got more than 3 vertices so how can I draw, for example, a quad with DrawPrimitive function?...With OpenGL is very easy: glBegin(GL_QUADS); glVertex3f(x1, y1, z1); .... glVertex3f(x4, y4, z4); glEnd(); ..but what must I do to make the same stuff with D3D?? Thanks a lot.

Share this post


Link to post
Share on other sites
Here you have a function to create a cube:
Modify it to create floors, roofs and walls.

void CreateCube(D3DVERTEX *Vertex, float xpos, float ypos, float zpos)
{
D3DVERTEX CubeVertices[24] =
{
// Vertex Normals Texture coordinates
// Front face
{ -1+xpos, -1+ypos, -1+zpos, 0, 0, -1, 0, 1 }, // left bottom
{ -1+xpos, 1+ypos, -1+zpos, 0, 0, -1, 0, 0 }, // left top
{ 1+xpos, -1+ypos, -1+zpos, 0, 0, -1, 1, 1 }, // right bottom (!)
{ 1+xpos, 1+ypos, -1+zpos, 0, 0, -1, 1, 0 }, // right top

// Back face
{ 1+xpos, -1+ypos, 1+zpos, 0, 0, 1, 0, 1 },
{ 1+xpos, 1+ypos, 1+zpos, 0, 0, 1, 0, 0 },
{ -1+xpos, -1+ypos, 1+zpos, 0, 0, 1, 1, 1 },
{ -1+xpos, 1+ypos, 1+zpos, 0, 0, 1, 1, 0 },

// Left face
{ -1+xpos, -1+ypos, 1+zpos, -1, 0, 0, 0, 1 },
{ -1+xpos, 1+ypos, 1+zpos, -1, 0, 0, 0, 0 },
{ -1+xpos, -1+ypos, -1+zpos, -1, 0, 0, 1, 1 },
{ -1+xpos, 1+ypos, -1+zpos, -1, 0, 0, 1, 0 },

// Right face
{ 1+xpos, -1+ypos, -1+zpos, 1, 0, 0, 0, 1 },
{ 1+xpos, 1+ypos, -1+zpos, 1, 0, 0, 0, 0 },
{ 1+xpos, -1+ypos, 1+zpos, 1, 0, 0, 1, 1 },
{ 1+xpos, 1+ypos, 1+zpos, 1, 0, 0, 1, 0 },

// Top face
{ -1+xpos, 1+ypos, -1+zpos, 0, 1, 0, 0, 1 },
{ -1+xpos, 1+ypos, 1+zpos, 0, 1, 0, 0, 0 },
{ 1+xpos, 1+ypos, -1+zpos, 0, 1, 0, 1, 1 },
{ 1+xpos, 1+ypos, 1+zpos, 0, 1, 0, 1, 0 },

// Bottom face
{ -1+xpos, -1+ypos, 1+zpos, 0, -1, 0, 0, 1 },
{ -1+xpos, -1+ypos, -1+zpos, 0, -1, 0, 0, 0 },
{ 1+xpos, -1+ypos, 1+zpos, 0, -1, 0, 1, 1 },
{ 1+xpos, -1+ypos, -1+zpos, 0, -1, 0, 1, 0 },
};

memcpy(Vertex, CubeVertices, sizeof(D3DVERTEX)*24);
}



Gandalf the White

Share this post


Link to post
Share on other sites
in the draw primitive function you can define how many vertices the primitive might have:

D3DDevice->DrawPrimitive( D3DPT_TRIANGLELIST, D3DFVF_VERTEX,
Projectile[num].Mesh+3*loop, 3,
NULL ); ^
that''s the line
the only thing you''ve to watch is to have them in the correct order, otherwise it won''t draw correctly:

v0-----v1
/ / /
/ / /
v2-----v3

always think in triangles, defined in clockwise direction. Hope this is of help,,

NoNseNSe

Share this post


Link to post
Share on other sites
I would preprocess those primitives into triangles because you need to limit the number of drawprimitive calls.


MCSE, MCSD, Sun Certified Java Programmer
Pimp Daddy ;)

Share this post


Link to post
Share on other sites
how do you read quake3 bsp files? how are you figuring this out?

ryoder: was it hard passing those mcse and mcsd exams? did you take classes or read books or what?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
To pass micro soft test you need to read books and memorize facts that at a later date you will forget and have to pick the friggen book up again. If you want to learn anything, install it and play with it.

Experience is the real teacher.

Share this post


Link to post
Share on other sites
It''s not as easy as you think ''reading'' a Q3 .bsp. The .bsp format is quiet complicated, but you''ll find plenty of tutorials on that (I''m sure there are some here on thins site, otherwise search for ''+bsp +quake* +file +format'', this should explain the basics). So have fun!

Share this post


Link to post
Share on other sites