#### Archived

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

# Wait a minute...something's wrong(?)

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

## Recommended Posts

Ok, I've been trying to figure out the problem myself, but I'm not quite sure if I've deduced correctly. I'm creating a terrain viewer which uses an array of heigh values to generate triangle strips for 3D generating. Currently, it works except that you have parts of the map object disappear as the stupid thing rotates. You can find the executable at http://www.geocities.com/clearvus/terrain.zip That's all you need. Run it and please let me know if you get weird stuff showing up too. Right now, I'm running it on my laptop, and it's 3D card has been known to have some interesting qwirks Thanks! -=xelius=- Edited by - Xelius on 10/4/00 11:27:36 AM

##### Share on other sites
You using gl or d3d? And are you doing any manual culling?
If you''re using gl and are not culling, then I''d look to make sure your surface normals are correct, and that your depth buffering is set properly. I''m thinking you''ve flipped your surface normals around: check the winding of your triangle strips.

Morbo

##### Share on other sites
Sorry. I''m using D3D...I guess I should have said that. D''oh!
Okay, um, as far as the data goes in the triangle strip, I have an array of floats [20][20].
Then, I have a loop that goes through (where map is the array):

  for (y=0;y<19;y++){ for (x=0;x<20;x++) { strip[y][c++] = D3DVERTEX(D3DVECTOR((float)x-10,map[y][x],(float)y),D3DVECTOR(0.0f,1.0f,0.0f),0,0); strip[y][c++] = D3DVERTEX(D3DVECTOR((float)x-10,map[y+1][x],(float)y+1),D3DVECTOR(0.0f,1.0f,0.0f),0,0); } c = 0;}

Then it renders it using:

Device->DrawPrimitive(D3DPT_TRIANGLESTRIP ...blah blah blah)

If, in fact, my faces are defined incorrectly, I''m not sure how I would determine the correct way to define them. Any ideas? (I''m thinking maybe the face/vertex normals(?))

Thanks

##### Share on other sites
What do you have your far and near clipping planes set at? If your far clipping plane is set too close, it would clip the corners off. That''s probably not it though...

##### Share on other sites
Nope, that''s not it. It''s, as far as I can tell, 1 of two things:
1) Face normals are setup improperly
2) I need some sort of depth buffer...dunno. I''m not experienced enough in 3D Graphics to be able to tell.

-=xelius=-

##### Share on other sites
Hmm...no one else seems to want to help me out

*sigh*
Looks like network debugging...

Thanks again.

##### Share on other sites
Well, on my computer the app just shuts down as soon as I start it up. It creates a window, goes fullscreen, and closes. Well, are you using a Z-Buffer, or sorting the polygons at all? If you aren''t then as the thing rotates, the polygons behind will come in front of polygons nearer the viewer, because the drawing order has not changed to take z-position into account.

------------------------------
#pragma twice

##### Share on other sites
Hmmm..
Ok. I''ll check that out. Thank you!

-=xelius=-

##### Share on other sites
Well...

I am using OGL, but it aplies every where.

1- You need to do some z-buffering, in OGL it''s s simple as 1 function call. I dunno about d3d.

2- Check your near clipping plane and far plains, play with the values till it looks right.

##### Share on other sites
looks like a depth problem, cuz i draws over during 1/2 the rotation, thats when the vertecies ur starting with(For the render) are at the front, when they''re at the back, its drawing backto front and so it looks fine

the wymsical wyvern

##### Share on other sites
Are you using a Z-Buffer of not?

------------------------------
#pragma twice

##### Share on other sites
I''m not using a Z-Buffer, but my Device caps says that I have built in hidden surface removal. I thought that would achieve the same thing as Z-Buffering. I know you shouldn''t rely on the hardware, but this was just for learning how to use D3D. However, if it''s as people seem to be saying, I may need the Z-Buffer anyway. I did try to use a Z-Buffer at one point, but told me it couldn''t attach to the render target...*shrug and sigh* I take a look in the Docs to see if it explains why that might be.

Thanks

-=xelius=-

##### Share on other sites
Well, it turns out that the reason it couldn''t attach the Z-Buffer was because I had reversed the width and height...d''oh *smack on the head*. I uploaded the new version at http://www.geocities.com/clearvus/terrain.zip. Unfortunately, adding a Z-Buffer didn''t do anything. Any other ideas?

-=xelius=-

##### Share on other sites
Hidden surface removal and Z-Buffering are entirely different things, Hidden surface removal is removing triangles facing away from the viewer. Z-Buffering is a way of making pixels with the smallest Z-Value appear nearest.

------------------------------
#pragma twice

##### Share on other sites
When I run your program, I get "Error in attaching Z-Buffer". Are you enumerating the available Z-Buffer pixel formats?

------------------------------
#pragma twice

##### Share on other sites
Are you using IDirect3DDevice7::SetRenderState(D3DRENDERSTATE_ZENABLE, D3DZB_TRUE) to enable the Z-Buffer before you call DrawPrimitive?

------------------------------
#pragma twice

##### Share on other sites
I've uploaded a new version of the program. It has Z-Buffering, and the Z-buffer is from a list that's enumerated. I've found that attaching the z-buffer after creating the D3D Device works much better :-) Now, I also set the D3DRENDERSTATE_ZENABLE to D3DZB_TRUE. I still get the weird phasing out however. I added functionality to change between point lists, line lists, and triangle strips. To switch to point lists, press the left arrow. To switch to lines, press the down arrow, and right arrow for triangle strips. It seems to me that I may just have the faces defined incorrectly. The problem is, however, since I was just loading 'em using a loop I'll have to do some explicit checks to make sure the points in the triangle strip are defined correctly...I think.

Tell me what you think. Thanks for your help.

-=xelius=-

Edited by - Xelius on October 10, 2000 11:24:22 AM

##### Share on other sites
Hmm, it still shuts down the minute it starts up. I don''t know why.

------------------------------
#pragma twice

##### Share on other sites
I''ll make it generate a log of what happens when you start it up. It''ll be good information for both parties, I think.

-=xelius=-

##### Share on other sites
okee dokey...
It creates a file now, called debug.log
This will give you some more information as to why it didn''t work. If you can''t figure out what the hell I meant from that, post it up here and I''ll take a look.

Thanks.

-=xelius=-

##### Share on other sites
--------CDirectX Object created
Beginning initialization...
Could not create Direct3DDevice7
Destroying data
CDirectX Object destroyed

Is what I get. What does your IDirect3D7::CreateDevice call look like? Which IID are you using? Are you using IID_IDirect3DTnLHALDevice or IID_IDirect3DHALDevice? Or are you enumerating?

------------------------------
#pragma twice

##### Share on other sites
That's odd. Hmm, I have a new version which I will post with in 10 minutes of 7PM eastern time (NY). First, I create the D3D object:

hr = lpDD7->QueryInterface(IID_IDirect3D7, (void **)&lpD3D7);

Then, I just make a call to lpD3D7->CreateDevice, as follows:

hr = lpD3D7->CreateDevice(IID_IDirect3DHALDevice,Target,&Device);

It works fine on my laptop and my desktop machine. My desktop is using a Diamond Viper 770, and my laptop has an ATI Rage Mobility. It's quite odd that it doesn't work.

The new version includes:
- Actual attaching of a Z-Buffer (the previous version apparently didn't really attach it, because when I tried to clear the buffer it failed, and said I had no buffer attached.)
- Z-Buffer clearing, which gets rid of all the funny artifacts that were occuring when I had attached the Z-Buffer previous (and apparently correctly) to creating the D3D Device.

Also, after talking to a friend of mine at school today, we came to the conclusion that something is wrong with the buffering. After looking at it, it appears that because I'm only rotating with the View Matrix the points that closer force themselves to stay that way by overwriting the polys that "should" be closer. Hopefully you'll see what I mean if you can actually run the bloody thing!

Thank's again for your help. It's greatly appreciated.

-=xelius=-

Edited by - Xelius on October 12, 2000 7:05:25 PM

##### Share on other sites
In your new version, I get:
--------CDirectX Object created
Beginning initialization...
Could not attach Z-Buffer to Render target
Could not attach surface
Failed to attach to surface
Destroying data
CDirectX Object destroyed

Are you enumerating Z-Buffer formats or just choosing one that works?

##### Share on other sites
I''m enumerating, but I''m not sure if I''m doing it right. I''m just enumerating till I find a format that''s a Z-buffer. I presume that''s what you mean by saying "just choosing one that works". I''ll take a look in the DX docs to see if their''s any further info, and then I''ll post again when I make a change.

-=xelius=-

##### Share on other sites
Okay, I updated the program one more time. I fixed the weird depth problem. It seems that I was defining my viewport wrong (0 to 60 zdepth) and that was forcing everything to the front. So, I changed it from 0 to 1 and it works fine. However, I would still like to find out why it doesn''t work on your computer. Please download the new version and see if it works better. Thanks.

-=xelius=-