OpenGL Vertex array not displaying properly

102 views Asked by At

I have an OpenGL Graphics assignment and well for some reason I'm trying to create a flat square on the X,Z plane (Y is just 1.0 for every vertices). I've tried making the problem smaller by just trying to create 2 flat vertices instead of four, and for some reason 2 of the vertices always seem to go wayyy into the negative y direction.

glMaterialfv(GL_FRONT, GL_DIFFUSE, drone_mat_diffuseBUILDING);
glEnableClientState(GL_VERTEX_ARRAY);
float buildingsize = 8 * floors + 4;
GLfloat quadV[300];

quadV[0] = -6.5;
printf("%.5f", quadV[0]);
quadV[1] = 1.0;
printf("%.5f", quadV[1]);
quadV[2] = 8.5;
printf("%.5f", quadV[2]);

quadV[3] = -6.5;
printf("%.5f", quadV[3]);
quadV[4] = 1.0;
printf("%.5f", quadV[4]);
quadV[5] = -7.5;
printf("%.5f", quadV[5]);


glVertexPointer(3, GL_FLOAT, 0, quadV);
glDrawArrays(GL_POLYGON, 0, buildingsize);
glDisableClientState(GL_VERTEX_ARRAY);here

Here's what it looks like when ran:

Snapshot

The red line should be a flat line on the X Z plane.

For further simplicty, I'm trying to convert this code:

    glBegin(GL_POLYGON);
glVertex3f(firstCubeXPOS - firstCubeXSCALE/2.0, 1.0, firstCubeZPOS + firstCubeZSCALE/2.0);
glVertex3f(firstCubeXPOS - firstCubeXSCALE / 2.0, 1.0, firstCubeZPOS - firstCubeZSCALE / 2.0);
glVertex3f(firstCubeXPOS + firstCubeXSCALE / 2.0, 1.0, firstCubeZPOS - firstCubeZSCALE / 2.0);
glVertex3f(firstCubeXPOS + firstCubeXSCALE / 2.0, 1.0, firstCubeZPOS + firstCubeZSCALE / 2.0);
glEnd();
glFlush();

Into a vertex array so I can add new elements / modify elements by each vertex. Because as of right now the code right above me shows what I need to see (2d square laying on the XZ plane).

0

There are 0 answers