Hi all,
The drawing doesn’t get any easier than ‘doing’ a height-field.
I’ve got close, but still missing the last piece of the pussle.
The data is 12001200 vertices in a … 12001200 plain grid with height-values at the position.y.
My graphics-card has a limit of ~1 mill vertices (and do indices), so I’ve had to split the 1.4mill vertices. After trying different possibilities I’ve chosen to use glDrawElementsBaseVertex with GL_TRIANGLE_STRIP and to cut up the drawing into 4 calls.
To judge by the visual output it looks as if not all vertices in each call are drawn to the screen.
The calls splits as four broad bands (300*1200) vertices that conveniently are drawn as 300 GL_TRIANGLE_STRIPs. Approximately 1/4’th of the vertices seems to be drawn, but what DOES get drawn is ok and all positioned properly: I get a partly painted square with wide empty gaps in.
Doing only one call (1/4’th of 1.4 mill) does not affect the amount of vertices being drawn.
Kind of stupid question: but that leaves the problem at the VAO/VBO’s, doesn’t it?
Unless anyone can find the bug in the code:
Load and fill arrays:
const GLuint SRTM_SIZE = 1201;
Vertex3 Vertices[ SRTM_SIZE * SRTM_SIZE ] ;
static GLfloat vPosArray[ SRTM_SIZE * SRTM_SIZE ][4] ;
static GLfloat vNormArray[ SRTM_SIZE * SRTM_SIZE ][4] ;
static GLint Load_1201_HGT(){
//load file,
for (GLuint i = 0; i < SRTM_SIZE; ++i)
{
for (GLuint j = 0; j < SRTM_SIZE; ++j)
{
..... read value "q"
GLfloat p = (GLfloat) q/90 ;
Vertex3 myVert;
myVert.position.x = (GLfloat) j ;
myVert.position.y = (GLfloat) p ;
myVert.position.z = (GLfloat) i ;//
Vertices[i * SRTM_SIZE + j] = myVert ;
vPosArray[ i * SRTM_SIZE + j ][ 0 ] = (GLfloat) j ;
vPosArray[ i * SRTM_SIZE + j ][ 1 ] = p ;
vPosArray[ i * SRTM_SIZE + j ][ 2 ] = (GLfloat) i ;
vPosArray[ i * SRTM_SIZE + j ][ 3 ] = 1.0f ;
............
.......... calculate normals
vNormArray[ i * SRTM_SIZE + j ][ 0 ] = norm.x ;// swap x and z ????
vNormArray[ i * SRTM_SIZE + j ][ 1 ] = norm.y ;
vNormArray[ i * SRTM_SIZE + j ][ 2 ] = norm.z ;
vNormArray[ i * SRTM_SIZE + j ][ 3 ] = 1.0f ;
building indices:
const GLuint marker = 10000000 ;
const GLuint indicesCount = 2*299*SRTM_SIZE + 299 ;
static GLuint Indices[indicesCount] ;
void long4Indices(){
GLuint counter = 0 ;
GLuint lon = 0 ;
GLuint lat = 0 ;
//due to the 'symmetry' the lat = 1201 is skipped
for( lat = 0; lat < 300 - 1 ; lat++ ) // lat iterates 299 times, but involves 2 lines (including +extra)
{// two rows are traversed
for( lon = 0; lon < SRTM_SIZE ; lon++ ) // lon iterates 1201 times
{
Indices[ counter ] = (GLuint) lon + lat * SRTM_SIZE ;
Indices[ counter + 1 ] = (GLuint) lon + (lat + 1) * SRTM_SIZE ;
counter += 2 ;
}
Indices[ counter ] = marker ;
counter ++ ;
}
printf("is indices : %i equal to counter : %i
", indicesCount , counter ) ; // yes
}
GLuint vao;
GLuint vertexBufferObject ;
GLuint indexBufferObject ;
static void initProgram()
{
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
//--- SRTM_SIZE * SRTM_SIZE vector of four floats (position or normals)
size_t normalOffset = sizeof(float) * 4 * SRTM_SIZE * SRTM_SIZE;
glGenBuffers(1, &vertexBufferObject);
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject);
glBufferData(GL_ARRAY_BUFFER, normalOffset + normalOffset , NULL , GL_STATIC_DRAW);
glBufferSubData( GL_ARRAY_BUFFER , 0 , normalOffset , vPosArray ) ;
glBufferSubData( GL_ARRAY_BUFFER , normalOffset , normalOffset , vNormArray ) ;
glEnableVertexAttribArray(0); // positions
glEnableVertexAttribArray(1); // normals
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, (const GLvoid *)0 ) ;
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, (const GLvoid *)normalOffset ) ;
glGenBuffers(1, &indexBufferObject);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferObject);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indicesCount , Indices , GL_STATIC_DRAW);
glEnable( GL_PRIMITIVE_RESTART ) ;
glPrimitiveRestartIndex( marker ) ;
}//------------------------------------------------------------------------------
DISPLAY:
....
glDrawElementsBaseVertex( GL_TRIANGLE_STRIP, indicesCount , GL_UNSIGNED_INT , (const GLvoid *)0 , 0 ); //
glDrawElementsBaseVertex( GL_TRIANGLE_STRIP, indicesCount , GL_UNSIGNED_INT , (const GLvoid *)0 , 300*1201 );
glDrawElementsBaseVertex( GL_TRIANGLE_STRIP, indicesCount , GL_UNSIGNED_INT , (const GLvoid *)0 , 2*300*1201 );
glDrawElementsBaseVertex( GL_TRIANGLE_STRIP, indicesCount , GL_UNSIGNED_INT , (const GLvoid *)0 , 3*300*1201 );
....