Trying to render a heightmap as a VBO, no error just not showing up.

Edit: I'm trying to use opengl 2.1 to avoid shaders for now.

I can render a simple triangle without issue as a vbo but when I made this function and try to render a height map it doesn't display anything. I'm guess it's something to do with trying to fill the data with a vector<float> but not to sure.

It's probably something simple but I'm pretty new to opengl and 3d programming in general -.-, thanks for any help.

I load a bmp image (gray scale) and just fill a vector<float> like so..

I can render a simple triangle without issue as a vbo but when I made this function and try to render a height map it doesn't display anything. I'm guess it's something to do with trying to fill the data with a vector<float> but not to sure.

heightMap.size() is the number of floats in the vector, but the second argument to glBufferData() is the number of bytes, so you're only uploading a quarter of the data.

Originally Posted by Exempt

I changes the load height map function to load a 4th vertex and use triangle strips to render it... seems to work better but I still have no Z or height value...

Originally Posted by Exempt

Code :

Uint8 r, g, b;
...
vec.push_back((float)(r / 255) * maxHeight);

As r and 255 are both integers, the division will yield an integer, so the value of r/255 will be either zero (if r<255) or one (if r==255). You need to convert at least one of the operands to the division to a float, e.g.

Code :

vec.push_back((r / 255.0f) * maxHeight);

Converting the result of the division to a float won't work; you're just converting 0 to 0.0f every time.

Essentially, glDrawArrays() is equivalent to glDrawElements() with an index array of [0,1,2,3,...]. glDrawArrays() is seldom useful when drawing triangles or quads, as you end up needing to duplicate vertices, which is more expensive than duplicating indices. It is useful with points (which have no topology) and sometimes with line strips/loops, but less useful with general wireframe meshes.

If I wanted to create a real index like 0, 1, 2, 3, 2, 1 to reuse vertice correctly I'd also have to remove the duplicated vertex from my data right?

I think I may go ahead and bump up to opengl 3.3 soon so I can use the primitive restart method but that's for triangle strips and I'm not sure why I need a index for triangle strips since really I just need the first 2 point and then just one point to continue the strip after that... I've read its faster with way but primative restart requires a index which seems pointless to me for triangle strips...

I'd try to test this but I've got no access to my pc atm so I'm just thinking out loud here..