Sign in to follow this  
relpats_eht

Fixing triangle strip output

Recommended Posts

Im working on a height map render using draw arrays and triangle strips. Im starting out just by making all the output work by brute force (no geoMipmapping or culling yet), but I cant seem to get the triangle strips quite right. I always end up with a long triange from one edge to the other per each colum (or row depending how you look at it) here is the code that renders the vertices
int index = 0;
for(int w=0; w<(width-1); w++){
    for(int h=0; h<(height-1); h++){
        if(w==0){
            mapData[index] = w - (width/2.0f);
            mapData[index+1] = (buffer[int(w+(h*width))]/255.0f)*50.0f;
            mapData[index+2] = h - (height/2.0f);
                
            mapData[index+3] = (w+1) - (width/2.0f);
            mapData[index+4] = (buffer[int((w+1)+(h*width))]/255.0f)*50.0f;
            mapData[index+5] = h - (height/2.0f);
                
            index+=6;
        }
            
        mapData[index] = (w+1) - (width/2.0f);
        mapData[index+1] = (buffer[int((w+1)+((h+1)*width))]/255.0f)*50.0f;
        mapData[index+2] = (h+1) - (height/2.0f);

        mapData[index+3] = w - (width/2.0f);
        mapData[index+4] = (buffer[int(w+((h+1)*width))]/255.0f)*50.0f;
        mapData[index+5] = (h+1) - (height/2.0f);
                
        index+=6;
    }
}


and here is the code that outputs the terrain
for(int i=0; i<(height-1); i++){
    glDrawArrays(GL_TRIANGLE_STRIP, ((2*height)+2)*i, (2*height)+2);
}
(yeah, I know the codes awful, but its only temporary untill I move on to better rendering techniques) Would anyone be so kind as to point out what I need to change in order to remove the extra triangles? Screen Shot

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this