[OpenGL] VBO, wyświetla tylko jeden trójkąt...
Ostatnio zmodyfikowano 2012-12-22 11:41
Mrusio Temat założony przez niniejszego użytkownika |
[OpenGL] VBO, wyświetla tylko jeden trójkąt... » 2012-12-21 20:01:09 Witam. Uczę się openGL. Używając Vertex Arrays zrobiłem planszę składającą się z kwadratów (2 trójkąty). Wszystko było ok, następnie spróbowałem zrobić to samo za pomocą VBO i plansza nie renderuje się poza jednym trójkątem... generowanie Vertex Array i VBO: void Program1::init_map() { float heightmap[ 100 ][ 100 ]; for( int i = 0; i < this->map_width; i++ ) { for( int j = 0; j < this->map_height; j++ ) { heightmap[ i ][ j ] = 0; } } this->vertices1 = new GLfloat[ this->map_width * this->map_height * 4 * 3 * 2 ]; this->texVertices = new GLfloat[ this->map_width * this->map_height * 4 * 2 * 2 ]; int n = 0; for( int i = 0; i < this->map_width - 1; i++ ) { for( int j = 0; j < this->map_height - 1; j++ ) { this->vertices1[ n ] = i + 1; n++; this->vertices1[ n ] = heightmap[ i + 1 ][ j + 1 ]; n++; this->vertices1[ n ] = j + 1; n++; this->vertices1[ n ] = i + 1; n++; this->vertices1[ n ] = heightmap[ i + 1 ][ j ]; n++; this->vertices1[ n ] = j; n++; this->vertices1[ n ] = i; n++; this->vertices1[ n ] = heightmap[ i ][ j + 1 ]; n++; this->vertices1[ n ] = j + 1; n++; this->vertices1[ n ] = i; n++; this->vertices1[ n ] = heightmap[ i ][ j + 1 ]; n++; this->vertices1[ n ] = j + 1; n++; this->vertices1[ n ] = i + 1; n++; this->vertices1[ n ] = heightmap[ i + 1 ][ j ]; n++; this->vertices1[ n ] = j; n++; this->vertices1[ n ] = i; n++; this->vertices1[ n ] = heightmap[ i ][ j ]; n++; this->vertices1[ n ] = j; n++; } } n = 0; for( int i = 0; i < this->map_width; i++ ) { for( int j = 0; j < this->map_height; j++ ) { this->texVertices[ n ] = 1; n++; this->texVertices[ n ] = 1; n++; this->texVertices[ n ] = 1; n++; this->texVertices[ n ] = 0; n++; this->texVertices[ n ] = 0; n++; this->texVertices[ n ] = 1; n++; this->texVertices[ n ] = 0; n++; this->texVertices[ n ] = 1; n++; this->texVertices[ n ] = 1; n++; this->texVertices[ n ] = 0; n++; this->texVertices[ n ] = 0; n++; this->texVertices[ n ] = 0; n++; } } glGenBuffers( 1, & vboId ); glBindBuffer( GL_ARRAY_BUFFER, vboId ); glBufferData( GL_ARRAY_BUFFER, sizeof( this->vertices1 ) + sizeof( this->texVertices ), 0, GL_STATIC_DRAW ); glBufferSubData( GL_ARRAY_BUFFER, 0, sizeof( this->vertices1 ), this->vertices1 ); glBufferSubData( GL_ARRAY_BUFFER, sizeof( this->vertices1 ), sizeof( this->texVertices ), this->texVertices ); glBindBuffer( GL_ARRAY_BUFFER, 0 ); }
Renderowanie: void Program1::draw_map() { int ile_punktow = 3; int size = this->map_width * this->map_height * ile_punktow; glBindTexture( GL_TEXTURE_2D, core->textures[ "trawa" ] ); glEnableClientState( GL_TEXTURE_COORD_ARRAY ); glEnableClientState( GL_VERTEX_ARRAY ); glBindBuffer( GL_ARRAY_BUFFER, vboId ); glVertexPointer( 3, GL_FLOAT, 0, 0 ); glTexCoordPointer( 2, GL_FLOAT, 0,( void * )( sizeof( this->vertices1 ) ) ); glDrawArrays( GL_TRIANGLES, 0, size ); glDisableClientState( GL_VERTEX_ARRAY ); glDisableClientState( GL_TEXTURE_COORD_ARRAY ); glBindBuffer( GL_ARRAY_BUFFER, 0 ); }
Zamiast całej planszy otrzymuję: (W dodatku tekstura jest jakaś rozmazana) Co robię źle? |
|
Mrusio Temat założony przez niniejszego użytkownika |
» 2012-12-22 11:41:20 ok, znalazłem problem: this->vertices1 = new GLfloat[ this->map_width * this->map_height * 4 * 3 * 2 ]; this->texVertices = new GLfloat[ this->map_width * this->map_height * 4 * 2 * 2 ];
zapomniałem, że sizeof() nie zwraca rozmiaru danych zawartych w pamięci wskazywanej przez wskaźnik ;) |
|
« 1 » |