Results 1 to 6 of 6

Thread: how would I restart a triangle strip?

  1. #1
    Member Newbie
    Join Date
    Aug 2013
    Posts
    32

    how would I restart a triangle strip?

    I'm using a VBO to store my terrain data and displaying it using triangle strips. The problem I have it that it seems to be drawing extra triangles connecting each row to the next column down. I think a easy solution would be to just have it restart the triangle strip at each of the columns.

    This is how I fill my VBOs data for displaying. heights is just a vector<vector<float>> that holds columns and rows of heights that I load from a grayscale image. I would just need a way to restart a triangle strip after each time the second for loop finishes.
    Code :
    for(int z = 0; z < heights.size()-1; z++)
    	{
    		for(int x = 0; x < heights[0].size()-1; x++)
    		{
    			vec.push_back(x * tileSize);
    			vec.push_back(heights[x][z] * maxHeight);
    			vec.push_back(z * tileSize);
     
    			vec.push_back(x * tileSize);
    			vec.push_back(heights[x][z+1] * maxHeight);
    			vec.push_back(z+1 * tileSize);
    		}
                //add a new triangle strip here
    	}

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,112
    Quote Originally Posted by Exempt View Post
    I'm using a VBO to store my terrain data and displaying it using triangle strips. The problem I have it that it seems to be drawing extra triangles connecting each row to the next column down. I think a easy solution would be to just have it restart the triangle strip at each of the columns.
    With glDrawArrays(), you'd need one call for each row. With glDrawElements(), you can either use GL_TRIANGLES rather than GL_TRIANGLE_STRIP, or use glPrimitiveRestartIndex() (requires OpenGL 3.1).

  3. #3
    Senior Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    268
    Quote Originally Posted by GClements View Post
    or use glPrimitiveRestartIndex() (requires OpenGL 3.1).
    Please do use the functionality, but do not use the function. Setting index to non-default is a bad idea. Just glEnable(GL_PRIMITIVE_RESTART) or better glEnable(GL_PRIMITIVE_RESTRAT_FIXED_INDEX) (if you have it).

  4. #4
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,678
    Setting index to non-default is a bad idea.
    Says who? Do you have any evidence for this? On what hardware is it "a bad idea?"

  5. #5
    Member Newbie
    Join Date
    Aug 2013
    Posts
    32
    I ended up using glDrawElements and a index... seems like a better idea in the end to me.

  6. #6
    Senior Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    268
    Quote Originally Posted by Alfonse Reinheart View Post
    Says who? Do you have any evidence for this? On what hardware is it "a bad idea?"
    Anecdotal. But i know of at least one GL implementation that does not support the feature 'natively'.
    Shouldn't really be much of surprise given how DX specified restart index.

Similar Threads

  1. Triangle Strip - Per Triangle color
    By Aliii in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 09-27-2013, 10:14 AM
  2. VBO Triangle Strip
    By Jeffg in forum OpenGL: Basic Coding
    Replies: 14
    Last Post: 01-08-2011, 10:01 AM
  3. Help with Triangle strip
    By Jeffg in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-30-2010, 09:52 AM
  4. triangle strip with a LINE triangle display error
    By Samme in forum OpenGL: Windows
    Replies: 22
    Last Post: 11-20-2008, 07:50 PM
  5. Triangle Strip
    By Cosmosis in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 03-12-2007, 02:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean