Archived

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

Difficulties just rendering a triangle!!

This topic is 5519 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

i'm going through some learning materials on D3D with DX8, and i set up a cube and rendered it successfully (yea!). However, i lost the source files. Now i'm going through it again, and adding a few layers of abstraction (working my way eventually towards a game engine). Now all i get is a garbled looking mosh when i go to render the cube. So, i rechecked everything (over and over - 2 hours at least)... no dice. So, i only indicate one primitive to DrawIndexedPrimitive(), and nothing shows up. In fact, unless i draw like 5 primitives, nothing appears. i try to set up a different object (just a triangle), give it its own index buffer, etc., with the same coordinates, tell it to draw - nothing appears. Totally frustrating and cursing at Microsoft by this point (even though i'm sure it's not their fault), i say to myself, "Ok, let's just shoot for a triangle from my cube verticies." So i comment out the DrawIndexedPrimitive() and go with DrawPrimitive(), telling it to draw one primitive. Aha! Something appears, but it is badly distorted. When i go with 2, it gets worse. Not to make an overly long post, but here's the situation: The first triangle rendered is as follows: First point: -1.0f, 1.0f, -1.0f Second point: 1.0f, 1.0f, -1.0f Third point: 1.0f, 0.0f, -1.0f The normal i give it is 0.0f, 0.0f, -1.0f i would think this would be a right triangle that is squared up to the camera. Instead, it looks like it is slanted backwards. Further, when i try two: (Next triangle) First point: -1.0f, 1.0f, -1.0f Second point: 1.0f, 0.0f, -1.0f Third point: -1.0f, 0.0f, -1.0f the triangles end up perpendicular to each other (i.e. one cuts through the middle of the other at a right angle). No output traces from DX either, at any time. i know i haven't posted any source code, but can someone offer some advice? i'm a long way from a cube, and a short distance from throwing in the towel altogether and going over to OpenGL. "You call him Dr. Grip, doll!" [edited by - the_grip on November 6, 2002 10:59:55 AM]

Share this post


Link to post
Share on other sites
It''s not so bad!
I''ve only been doing this a while, but I think I''ve got the hang of it:
Make sure you set up vertex shaders (default probably)
Tell it not to bother with anything clever to start off with
Look at the trace window (I assume that this works in
Borland etc - it certainly does in VisualC++6.0) - D3D
gives loads of help.
If you want materials, you''ll have to define normals yourself - it''s a moderately expensive operation and DX won''t do it
every frame.
Good luck!
Incidently - I had some problems that sounded vaguely similar by
forgetting to do BeginScene() and EndScene() and Clear() calls. Could this be something to do with it?

Share this post


Link to post
Share on other sites
quote:
Original post by the_grip
...and cursing at Microsoft by this point...


You cannot blame Microsoft in this case. DX8 is stable as a rock. Actually, I''ve never seen it crash my PC or do other strange things that were not my own fault.
I''m up to the point where I just test things in fullscreen mode, just because it will not crash or hang. In the worst case, your object will not show up or something like that.
Hats off to Microsoft on this one!

OK now you may flame me

Share this post


Link to post
Share on other sites
Thanks for the reply!

i do call clear, beginscene, and endscene, and i use lighting as well as a material, and calculate the normal myself, and do create vertex shaders (at least i should - i''m not at home, so can someone post the code again for the default? i''ll recognize it if i did it).

My thing is i can get distorted images (at least distorted from what i intend), so it is rendering something, just not correctly. i''ve poured over and over the index buffers, verticies, and normals, and i still can figure out what''s wrong.

"You call him Dr. Grip, doll!"

Share this post


Link to post
Share on other sites
I think I know what''s missing in your code...
I''ve had the same problem and after checking the
code at least 5 hours I just figured out that
something was missing. Try adding the following
code:

D3DXMATRIX matProj;
D3DXMatrixPerspectiveFovRH( &matProj, 0.8f, 640.0f/480.0f, 1.0f, 200.0f );
g_D3Ddevice->SetTransform( D3DTS_PROJECTION, &matProj );

And you have to set the View position and angle as well
or else you will just see nothing...

Hope this helps you...

Kamikaze

Share this post


Link to post
Share on other sites