Computer Science Bacs2173 Graphics Programming
Computer Science Bacs2173 Graphics Programming
Question Marks
1.
2.
Total
Question 1
No Answers
a) By using computer graphics in movies could save the produce cost for the movie. This is
because the building damage and explosion scene can be replaced by the computer graphic,
so that the cost needed for the repairing the building or the cost for explosive material for
the scene will be reduced. Not only that, using computer graphic in movie could also save
time. This is because, when we are using computer graphic in movie production, The
makeup that need to be done by the actors can be done by replacing it with computer
graphics. Computer graphics can also provide the audience that watching the movie with a
better and more interesting experience by providing the audience with the effect that are
couldn’t be done in the real life, for example magic effect.
b) (i) The two fixed graphic pipeline components are clipper and primitive assembler and
rasterization. For the clipper and primitive assembler, the tasks that perform by the clipper
is to clip out or remove the vertices that are out of frustum. While primitive assembler are
performing a determination for the connectivity information which is the connection of each
vertex to make up a geometric primitive. Lastly for the task perform by the rasterization is
to convert the vertices to pixels and determines the fragments and pixel positions of the
primitive.
(ii) The programmable graphics pipeline is importance in computer graphics application. This
is because the two components in programmable graphic pipeline provide importance
process to the computer graphic. First is the programmable vertex processor, it is a unit
that runs computer graphic vertex programs by transforming the vertices and passing it to
the primitive assembly process. Vertex processor will perform coordinate transformations,
compute colour for each vertex, generation, and transformation of texture coordinates.
Next for the fragment processor, a unit that runs computer graphic fragment programs by
transforming the fragments and passing it to raster operation for updating pixels in the
frame buffer. It will perform the depth test, alpha test, and stencil test to update the pixels
prior to the final display. The depth test will remove the hidden surface. The alpha test will
change the color pixel based on texture, blending and translucency.
c) (i) The first mistake that made in Figure 1 is the output will only show 1 colour which is a
blue. This is because of it is using flat shading as the shade model which only allow the first
colour to show in the polygon. The second mistakes is the order of the glVertex2f. This is
because when it come to the connection of the 2nd and 3rd vertices its form a interior angle
which exceed 180 degree. A non-convex polygon form.
(ii) glShadeModel(GL_SMOOTH);
glBegin(GL_QUADS);
glColor3f(0.0, 0.0, 1.0);
glVertex2f(-0.5, 1.0);
glVertex2f(0.5, 1.0);
glColor3f(0.0, 1.0, 0.0);
glVertex2f(0.5, 0.0);
glVertex2f(-0.5, 0.0);
glEnd();
glBegin(GL_TRIANGLES);
glVertex2f(1.0, 0.0);
glVertex2f(0.0, -1.0);
glVertex2f(-1.0, 0.0);
glEnd();
With the code segment provided above, the mistakes in Question 1 c)(i) can be solved. By
comparing the code segment we could noticed the shade model for the new code segment
had change to smooth shading which allow the objects to be drawn in different colour. To
solve the problem of non-convex polygon, in the new code segment the construction of the
upper and lower part of the down directed arrow are separated in two different glBegin,
which construct a quad and triangle separately.
d)
Figure a Figure b
The order of transformations is important in OpenGL. With the diagrams provided we could
notice the triangle in both diagrams are located at the different position due to the different
of the order of transformation. For the first diagram (Figure a), the transformation done on
the triangle is translate then rotate, while for the second diagram (Figure b) done a
transformation of rotate then translate.
e) The first factor Jeffrey should consider is the scaling of the object in the projection, which
is because an orthographic projection preserved object size but perspective mimics scaling
of distance. The second factor that Jeffrey should consider is the viewing frustum. For
orthographic it viewing volume is rectangular but for perspective the viewing frustum is
like a truncated pyramid. The third factor to consider is what are the projection is applied
to. This is because if Jeffrey are going to use the projection for measurement like building
plan and manuals a Orthographic is suitable, but for depth viewing and sense of distance
such as VR and games a Perspective is more suitable. The last factor to consider is the
dimension of the projection. If he want a 2D projection which not realistic Orthographic
will be his choice, but if he need a realistic projection view which in a 3D Perspective will
be good for him.
Question 2
No Answers
a) (i) Flat shaded is the simplest way to shade the polygon, the pixels in the polygon are shaded
the same. But for Gouraud shaded is a colour computed for each vertex. Other than that, flat
shaded uses the normal associated with the first vertex of a single polygon for shading
calculation, but for Gouraud Shaded colour for pixels within the polygon are calculated by
linear interpolation from the vertices. Lastly for flat shaded, it is quick, but limited realism
for meshes, but for Gouraud Shaded, it is slower, smooth appearance across polygon.
(ii) Vertex shader will be use for the graphic application. It is chosen because it can process
faster and simpler than fragment shader. Since the graphic application is for mobile purpose
vertex shader is chosen. Not only that, vertex shaders can manipulate properties such as
position, colour and texture coordinate, but cannot create new vertices
b) (i) The first solution that could provided to Mr Chee is a point sampling. It could solve the
problem by use the value of the texel that is closet to the one computed by the bilinear
interpolation.
The first solution that could provide to Mr Chee is a linear filtering. It could help to solve
the problem by using a weighted average of a group of texels in the neighbourhood of the
texel determined by point sampling.
//INITIALIZE TEXTURE
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
HBITMAP hBMP = (HBITMAP)LoadImage(GetModuleHandle(NULL), filename,
IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE);
GetObject(hBMP, sizeof(BMP), &BMP);
//ASSIGN TEXTURE
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, BMP.bmWidth, BMP.bmHeight, 0,
GL_BGR_EXT, GL_UNSIGNED_BYTE, BMP.bmBits);
//Vertex Mapping
void draw2DSquare() {
glBegin(GL_QUAD);
glTexCoord2f(1.0, 0.0);
glVertex2f(-0.5, 0.5);
glTexCoord2f(1.0, 1.0);
glVertex2f(-0.5, -0.5);
glTexCoord2f(0.0, 1.0);
glVertex2f(0.5, -0.5);
glTexCoord2f(0.0, 0.0);
glVertex2f(0.5, 0.5);
glEnd();
}
//Display Function
void display() {
textures[0] = loadTexture("imageP.bmp");
draw2DSquare();
glDeleteTextures(1, &textures[0]);
}
c) (i)
Figure c
Explicit Representation is the most familiar form of curve in 2D. It is taking the equation y
= f(x) which we can express f as a polynomial function
Equation for explicit representation: y = f(x)
Figure d
(ii) The first factor that make spline so importance is they have a more compact representation
than a set of polygon. Not only that, spline also provide a smoother and more continuous
primitive than straight lines and planar polygons. Lastly spline could make an animation
and collision detection may become simpler, faster, and more accurate.
d) The shadow approach that being used in Figure 3 is projected shadow. The advantage of
the projected shadow is that it is very easy and fast. This is because it just needs a projection
matrix to squish geometry to plane. The disadvantage of projected shadow is that it is
difficult to make it work on non-planar surfaces. Besides, the projected shadow is an
unrealistic shadow