I’m creating an app using VBO to render some objects with difficult color structure. I noticed, that VBO defines the color of the element equal to last vertex index in the element buffer. For example, when I use point array like this
double pointBuf[]={ -0.1d, 0.1d, 0,
0.1d, 0.1d, 0,
0.1d, -0.1d, 0};
color array:
double colorBuf[] = { 0d, 1d, 0d,
0d, 1d, 0d,
1d, 0d, 0d};
and element array:
int elementBuf[] = {0, 1, 2};
to draw a triangle, it will be red (as the last element in elementBuf is 2, in colorBuf it matches red).
In fact it can lead to additional memory usage to paint everything correctly.
Is there any other possible way to link colors with elements?
One thing you need to understand is, that a vertex is not just its position. A vertex (in OpenGL terms) is the whole vector of attributes
If you change any of these you end up with a completely different vertex. OpenGL’s data model has not been designed in a way that it were possible to place each of the attributes in a own array and address them with index vectors. Also this kind of data model would cause major difficulties in implement efficient caching, so would seriously degrade performance.
Also you tell you’re running out of memory. Most modern systems offer you several gigabytes of graphics client (i.e. CPU) memory and at least a few hundred megabytes of graphics server (i.e. GPU) memory. The amount of geometry data (i.e. vertices) you can put into GPU memory exceeds the realtime processing capabilities of GPUs; also that would be far more vertices than pixels available on your screen. So I’m positive that you’re unlikely to run into any memory problems, your bottleneck will be/is another one.