Question: 4 . [ 2 0 points ] As discussed in the class, the following code sends the position and color of three vertices ( forming

4.[20 points] As discussed in the class, the following code sends the position and color of three vertices (forming a triangle) to the GPU and sets up attributes 0(position) and 1(color).
```
void SendData()
{
GLfloat vertsPos[]=
1
+0.0f,+0.0f,+0.0f,
+1.0f,+1.0f,+0.0f,
-1.0f,+1.0f,+0.0f
};
glGenBuffers(1, &vpbufferiD);
glBindBuffer(GL_ARRAY_BUFFER, vpbufferID);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertsPos), vertsPos, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
GLfloat vertsCol[]=
1
+1.0f,+0.0f,+0.0f,
+0.0f,+0.0f,+1.0f,
+0.0f,+1.0f,+0.0f
};
glGenBuffers(1, &vcbufferlD);
glBindBuffer(GL_ARRAY_BUFFER, vcbufferID);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertsCol), vertsCol, GL_STATIC_DRAW);
glEnableVertexAttribArray(1);
}
```
The Display function (below) will then draw a triangle with the provided position and color on the screen.
```
void Display()
{
glBindBuffer(GL_ARRAY_BUFFER, vpbufferID);
glVertexAltribPointer(0,3, GL_FLOAT, GL_FALSE, 0,0);
glBindBuffer(GL_ARRAY_BUFFER, vcbufferID);
glVertexAttribPointer(1,3, GL_FLOAT, GL_FALSE, 0,0);
gIDrawArrays(GL_TRIANGLES, 0,6);
}
``` Now let's say we change the Display code as follows. Note that the only difference is that the glBindBuffer functions are removed.
```
void Display()
{
gIVertexAltribPointer(0,3, GL_FLOAT, GL_FALSE, 0,0);
glVertexAttribPointer(1,3, GL_FLOAT, GL_FALSE, 0,0);
glDrawArrays(GL_TRIANGLES, 0,6);
}
```
a)[10 points] Explain what happens in this case. Which arrays will be assigned to attributes 0(position) and 1(color)?
b)[10 points] Draw the outcome inside the orange box. Make sure you indicate the color of each vertex.
4 . [ 2 0 points ] As discussed in the class, the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!