diff --git a/u02/main.c b/u02/main.c index d89fef7..1e0237e 100644 --- a/u02/main.c +++ b/u02/main.c @@ -35,28 +35,28 @@ typedef struct { Triangle t2; } TriangleRect; -void createRect(GLfloat* vertexArray, GLfloat posx, GLfloat posy, GLfloat width, GLfloat height) { - vertexArray[0] = posx; - vertexArray[1] = posy; +void createRect(TriangleRect* rect, GLfloat posx, GLfloat posy, GLfloat width, GLfloat height) { + rect->t1.p1.x = posx; + rect->t1.p1.y = posy; - vertexArray[2] = posx + width; - vertexArray[3] = posy; + rect->t1.p2.x = posx + width; + rect->t1.p2.y = posy; - vertexArray[4] = posx; - vertexArray[5] = posy + height; + rect->t1.p3.x = posx; + rect->t1.p3.y = posy + height; - vertexArray[6] = posx + width; - vertexArray[7] = posy; + rect->t2.p1.x = posx + width; + rect->t2.p1.y = posy; - vertexArray[8] = posx + width; - vertexArray[9] = posy + height; + rect->t2.p2.x = posx + width; + rect->t2.p2.y = posy + height; - vertexArray[10] = posx; - vertexArray[11] = posy + height; + rect->t2.p3.x = posx; + rect->t2.p3.y = posy + height; } -void createCenterRect(GLfloat* vertexArray, GLfloat posx, GLfloat posy, GLfloat width, GLfloat height) { - createRect(vertexArray, posx - width / 2, posy - height / 2, width, height); +void createCenterRect(TriangleRect* rect, GLfloat posx, GLfloat posy, GLfloat width, GLfloat height) { + createRect(rect, posx - width / 2, posy - height / 2, width, height); } void init(void) { @@ -134,10 +134,10 @@ void init(void) { TriangleRect triangleVertices[4]; - createCenterRect((GLfloat*)&triangleVertices[0], -0.2f, 0.0f, 0.1f, 1.2f); - createCenterRect((GLfloat*)&triangleVertices[1], 0.2f, 0.0f, 0.1f, 1.2f); - createCenterRect((GLfloat*)&triangleVertices[2], 0.0f, 0.0f, 0.3f, 0.1f); - createCenterRect((GLfloat*)&triangleVertices[3], 0.0f, -0.8f, 0.5f, 0.1f); + createCenterRect(&triangleVertices[0], -0.2f, 0.0f, 0.1f, 1.2f); + createCenterRect(&triangleVertices[1], 0.2f, 0.0f, 0.1f, 1.2f); + createCenterRect(&triangleVertices[2], 0.0f, 0.0f, 0.3f, 0.1f); + createCenterRect(&triangleVertices[3], 0.0f, -0.8f, 0.5f, 0.1f); GLuint triangleVertexBufferObject; @@ -156,7 +156,7 @@ void init(void) { 2, GL_FLOAT, GL_FALSE, - 2 * sizeof(GLfloat), + sizeof(Point), 0 ); glEnableVertexAttribArray(0);