Jump to content

  • Log In with Google      Sign In   
  • Create Account

New to Direct X needs some help please


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
8 replies to this topic

#1 noodleBowl   Members   -  Reputation: 184

Like
0Likes
Like

Posted 08 September 2013 - 08:39 PM

Hey everyone!

 

I'm new to direct X and needs some help. I have a few questions based around some code I wrote to draw triangles to make up multiple quads.

 

Here is the code for the render and some inits on direct X

http://pastebin.com/QFXgvAW3

 

I was wondering if anyone can tell me:

 

1. If I turn off culling mode it draws my 4 triangles (2 quads). Why does this work only if culling mode is off? Am I doing something wrong?

2. If I load a texture will I be able to draw the texture properly? I mean will the texture be handled correctly by the triangles?

3. Is this the right way to draw quads? Should I call draw using trianglelist based on a vertexBuffer that has all my vertexes I need or something else? In the end I would like to use the quads as sprites for a 2d game.

 



Sponsor:

#2 Tom KQT   Members   -  Reputation: 1590

Like
0Likes
Like

Posted 09 September 2013 - 12:43 AM

1. That seems like wrong winding order. The default culling mode is D3DCULL_CCW, which means that Direct3D takes triangles with counter-clockwise winding order (the order of verticles) as front facing and renders them. Your verticles are ordered in the other way. To render them you don't have to set D3DCULL_NONE, you can either set D3DCULL_CW or swap any two verticles in each triangle.

2. Not directly, because all your texture coordinates (u, v) are zero at this moment. Your verticles are ready for it, you just have to fill proper values. The proper values of (u, v) for the verticles in each quad are: topLeft - topRight - bottomLeft - bottomRight  (0, 0) - (1, 0) - (0, 1) - (1, 1)

3. This is a right way, but you also can use index buffers. In your case you need 6 verticles for each quad, while 2 are doubled. With indices, you would need just 4 vertices for each quad, plus 6 indices. Try to find something about index buffers in the documentation.


Edited by Tom KQT, 09 September 2013 - 12:44 AM.


#3 Norman Barrows   Crossbones+   -  Reputation: 2138

Like
0Likes
Like

Posted 09 September 2013 - 11:31 AM


1. If I turn off culling mode it draws my 4 triangles (2 quads). Why does this work only if culling mode is off? Am I doing something wrong?

 

your triangles are facing the wrong way.  triangles have a "front" and a "back",  defined by winding order.  vertices are listed in counter clockwise order when viewed from the "front" of the triangle.   when cull is on, it  it only draws triangles facing the camera.

 


2. If I load a texture will I be able to draw the texture properly? I mean will the texture be handled correctly by the triangles?

 

once you setup the pipeline for texturing (if you haven't) and your U,V coords, it should work.

 


3. Is this the right way to draw quads? Should I call draw using trianglelist based on a vertexBuffer that has all my vertexes I need or something else? In the end I would like to use the quads as sprites for a 2d game.

 

indexed is faster - therefore usually preferred, although a bit more complex.

 

but for 2d, i would think you'd want to be using the ID3DXSprite interface.  it handles all the quad drawing for you. you just specify a texture, a center, a scale, and an optional transform (for rotated sprites, etc).


Norm Barrows

Rockland Software Productions

"Building PC games since 1988"

 

rocklandsoftware.net

 


#4 noodleBowl   Members   -  Reputation: 184

Like
0Likes
Like

Posted 09 September 2013 - 11:58 AM

Thanks a lot guys, this is really helpful!

Does the sprite interface have limitations compared to using quads and making a sprite batcher? Eg performance or dynamic lighting / vertex and pixel shaders

Also, if I had a texture atlas would I just change the u and v variables of my vertexs accordingly to get the image I want?

#5 noodleBowl   Members   -  Reputation: 184

Like
0Likes
Like

Posted 09 September 2013 - 07:13 PM

Also I am having trouble with the textures. I'm just trying to draw a single quad made from 2 triangles with a texture on top. But the texture is distorted instead of displaying a circle like it should. It is just displaying a thick black line in the middle like if the circle was being folded in two.

 

What am I doing wrong? Here all of my code

http://pastebin.com/c4sFHpTK

 

Here is also the image I'm trying to display

imgTest.png



#6 Tom KQT   Members   -  Reputation: 1590

Like
0Likes
Like

Posted 10 September 2013 - 12:35 AM

Hm, the texture coordinates of the first quad look fine to me. Are you drawing the first quad (verts[0] to verts[5])? The second quad doesn't have texcoords yet.

Please check this and then maybe post a screenshot?

Btw, are the vertex colors working? You have different colors in verticles, does it render the colors properly? (Just to make sure that your vertex definition is compatible with the FVF, I'm not familiar with FVF very much.)



#7 noodleBowl   Members   -  Reputation: 184

Like
0Likes
Like

Posted 10 September 2013 - 06:26 PM

I have no idea why, but if you add D3DFVF_DIFFUSE to the const DWORD D3DFVF_TLVERTEX It works. DirectX is a finicky thing isn't it? Any explanation?



#8 Tom KQT   Members   -  Reputation: 1590

Like
0Likes
Like

Posted 11 September 2013 - 12:24 AM

How was D3DFVF_TLVERTEX defined in your code before? That's not a standard DirectX constant or macro and using Google I found just these definitions:

#define D3DFVF_TLVERTEX D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1 

So I assumed it had color (diffuse). If it didn't then it's absolutely clear why it didn't work, because you have also a color value in your vertex definition and I guess it was between the position and texture coordinates (you didn't include declaration of the TLVERTEX struct in your code) - so Direct3D probably took the bits belonging to color and used them as if they represented texture coordinates.

 

But if you already had D3DFVF_DIFFUSE in the FVF definition, then it doesn't make sense :D



#9 noodleBowl   Members   -  Reputation: 184

Like
0Likes
Like

Posted 14 September 2013 - 08:50 AM

Interesting, thank you so much for the explanation!






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