I have an Nx4 array of vertices that I’d like to plot using glVertexArray and glDrawArray. as a 2D scatter plot. I currently initialize the array like so:
GLint data[4][MAX_N_POINT];
for (int j=0; j<MAX_N_POINT; j++)
{
data[j][0] = 200 + rand()%20 - 10; // X Dimension
data[j][1] = 400 + rand()%20 - 10; // Y Dimension
data[j][2] = 600 + rand()%20 - 10; // Z Dimension
data[j][3] = 1; // W Dimension
}
Then I draw the 2d scatter with:
glVertexPointer(4, GL_INT, 0, data);
glDrawArrays(GL_POINTS, 0, nPlot);
Which shows up correctly as this:

note: the colored squares in the background are so I can easily judge if the points are falling in the correct location
However as I’m only want a 2d plot I’d like to skip over the 2 unused dimensions. I tried telling glVertexPointer that my vertices only have 2 points and then setting the stride between vertices as 2 as well but that doesn’t seem to be working as I thought it should.
glVertexPointer(2, GL_INT, 2, data2);
glDrawArrays(GL_POINTS, 0, nPlot);
However when I plot this I get a very different result with points showing up at XxY, YxZ, ZxW:

Have I misunderstood the proper function of the stride variable? If not how can I properly set the stride so the bottom plot resembles the top plot?
The stride is not the “gap” between vectors, the stride is the distance between vector start locations. So in your case your vectors are “sizeof(int)*4” apart, which is the stride distance to use: