Skip to main content
gamedev.net
🔒 Locked

Problem with VBO's

Started by Renran 1 reply 750+ views
Original Post
Renran
Renran
Hello, I did make a terrain program without VBO's who is working fine. I used the same math to make the program with VBO's. And I have 2 problems with VBO's 1) Coming from a RAW heightmap file, when I make the terrain I only have grey colors in the range from 0 to 120 (more or less) Everything above 120 is black? 2) The VBO gives me also straight lines between the vertices who are disturbing the total image? My code: const GLuint SIZE_MAP = 257; // lenght and width of map GLfloat vertexData[257*257]; GLubyte colorData[257*257]; ............... // Making the VBO == is not optimised void VBO () { int RH, ZM, XM; GLubyte color; p=0; for (unsigned int x = 0 ; x < SIZE_MAP - m_iPrecision ; x += m_iPrecision) { for (unsigned int z = 0 ; z < SIZE_MAP - m_iPrecision ; z += m_iPrecision) { RH = ReadHeight (x, z); ZM = z + m_iPrecision; XM = x + m_iPrecision; // First triangle contra clock wise vertexData

=x; color = (GLubyte) RH; // read color = height colorData

= color; // define color p++; vertexData

=RH/10.0f; color = (GLubyte) RH; // read color = height colorData

= color; // define color p++; vertexData

=z; color = (GLubyte) RH; // read color = height colorData

= color; // define color p++; vertexData

=x; color = (GLubyte) RH; // read color = height colorData

= color; // define color p++; vertexData

=ReadHeight(x,ZM)/10.0f; color = (GLubyte) RH; // read color = height colorData

= color; // define color p++; vertexData

=ZM; color = (GLubyte) RH; // read color = height colorData

= color; // define color p++; vertexData

=XM; color = (GLubyte) RH; // read color = height colorData

= color; // define color p++; vertexData

=ReadHeight(XM,z)/10.0f; color = (GLubyte) RH; // read color = height colorData

= color; // define color p++; vertexData

=z; color = (GLubyte) RH; // read color = height colorData

= color; // define color p++; // Second triangle vertexData

=XM; color = (GLubyte) RH; // read color = height colorData

= color; // define color p++; vertexData

=ReadHeight (XM, ZM) / 10.0f; color = (GLubyte) RH; // read color = height colorData

= color; // define color p++; vertexData

=ZM; color = (GLubyte) RH; // read color = height colorData

= color; // define color p++; } } glGenBuffersARB(1, &colorBuffer); glBindBufferARB(GL_ARRAY_BUFFER_ARB, colorBuffer); glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(colorData), colorData, GL_STATIC_DRAW_ARB); glGenBuffersARB(1, &vertexBuffer); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertexBuffer); glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(vertexData), vertexData, GL_STATIC_DRAW_ARB); } // drawing the terrain void Terrain () { glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertexBuffer); glVertexPointer(3, GL_FLOAT, 0, 0); glBindBufferARB(GL_ARRAY_BUFFER_ARB, colorBuffer); glColorPointer(3, GL_BYTE, 0, 0); glDrawArrays(GL_TRIANGLE_STRIP, 0, p/4); glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); } What is wrong with my code? Greetings, Renran

V-man
V-man
glColorPointer(3, GL_BYTE, 0, 0); should be

glColorPointer(3, GL_USNIGNED_BYTE, 0, 0);

and for performance reason, I recommend adding alpha.
Also, since vertex and color is static, I suggest you interleave them.
Renran
Renran
Thank You V-Man.
I never thought of this.
Colors are OK now.

Thanks,

RenRan

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.