Jump to content
  • Advertisement
Sign in to follow this  
jboustan

Terran with Triangle Strips (opengl/c++)

This topic is 3560 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 guys this is my first post and it's because I'm having trouble rendering this terrain for a class program. I am using C++ and OpenGl. I have a 256 x 256 array of height values and the cross products for all normals, but when I render the terrain using triangle strips it comes out in what appears to be a wireframe model when it should be smooth. I'm using 2 if statements (int i,j) to loop all values of the height map and pass glVertex3f(i,j,height[j]). The code looks like this: glBegin(GL_TRIANGLE_STRIP); for(int i=0;i<256;i++) for(int j=0;j<256;j++) { p[0]=i;p[1]=j;p[2]=height[j]; a[0]=i+1;a[1]=j;a[2]=height[i+1][j]; b[0]=i;b[1]=j+1;b[2]=height[j+1]; v[0]=a[0]-p[0];v[1]=a[1]-p[1];v[2]=a[2]-p[2]; w[0]=b[0]-p[0];w[1]=b[1]-p[1];w[2]=b[2]-p[2]; nx=(v[1]*w[2])-(v[2]*w[1]); ny=(v[2]*w[0])-(v[0]*w[2]); nz=(v[0]*w[1])-(v[1]*w[0]); if(height[j]<0) height[j]=height[j]*-1; glNormal3f(nx,ny,nz); glColor3f(0.1*height[j],1.0,0.1*height[j]); glVertex3f(i,j,height[j]); } glEnd(); I guess we can ignore the normal vectors for now because I just need to get the terrain rendered correctly before I can even implement lighting effects. Anyone know what I'm doing wrong? Thanks for your time

Share this post


Link to post
Share on other sites
Advertisement
I didn't bother reading your code because they are unreadable. Try putting your code inside [ source ] [ /source ] tags.

You might have gotten your triangle faces culled. OpenGL, I believe, is using right-handed coordinate system. So, you have to specify your triangle points in counter-clockwise order. Or, you might have accidentally turned the wireframe rendering on.

Share this post


Link to post
Share on other sites
I is difficult to understand the code how it is, but I notice that you're only calling glVertex once per (i, j) coordinate. This will create something that looks a lot like rows of lines, but actually it's rows of very thin triangles. Triangle strips requires toggling between (i, j) and (i+1, j) vertices for each row of i.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!