Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: how would I restart a triangle strip?

Hybrid View

  1. #1
    Intern 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
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    474
    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
    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 Guru
    Join Date
    May 2009
    Posts
    4,948
    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
    Intern 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
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •