Difficulties just rendering a triangle!!

Started by
4 comments, last by the_grip 21 years, 5 months ago
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]
"You call him Dr. Grip, doll!"
Advertisement
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?
What''s an ICQ no.?
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
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!"
"You call him Dr. Grip, doll!"
quote:You cannot blame Microsoft in this case


Hence i said it was not their fault

Anyways, anyone have anymore tips?

"You call him Dr. Grip, doll!"
"You call him Dr. Grip, doll!"
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

This topic is closed to new replies.

Advertisement