Hi guys,
I’m pretty new to coding in OpenGL, and I’ve run into a bit of an issue. Right now I’m programming a game that will draw a row of boxes, the vertices of which are determined randomly and stored in an array. The vertices are then to be passed to a drawing function two at a time to draw the boxes. However, the way the code is written right now, only the first and the last elements of the array are being passed to the drawing function. Here’s the code in question, and I’ll supply a sample output below that
void drawBox(int x1, int x2, int y1, int y2)
{
glBegin(GL_POLYGON);
glVertex2f(x1, y1);
glVertex2f(x1, y2);
glVertex2f(x2, y2);
glVertex2f(x2, y1);
glEnd();
}
void drawRow1(void)
{
int i = 0;
int length;
row1.y[0] = 600;
row1.y[1] = 580;initialize();
genLength(&length); \This function generates a length for the array
genXValue(row1.x, length); \This populates the array with values
sort(row1.x, length); \places the values in order from least to greatestfor (i = 0; i < length -1; i++)
{
drawBox(row1.x[i], row1.x[i+1], row1.y[0], row1.y[1]);}
printf(“value of length: %d
“, length);
for (i = 0; i <length; i++) {
printf(” %d”, row1.x[i]);
}
}
And here’s what sample run through looks like:
value of length: 4
values in array: 29 48 236 585
So, as you can see, the array held 4 values, so there should be 2 blocks drawn. However, the drawing function only used the values of 29 and 585 to draw the vertices. Any ideas why that’s happening?