Tuesday, July 12, 2022

Implementation: Multi Colored Cube

Overview 
In SingleColoredCube we saw that VBOs were used to draw the single colored cube using Position data. In this post we  will discuss how to draw a Multi Colored cube using VBOs with Position and Color data having unique color on each face. It looks as shown at the bottom. It looks elongated because aspect ratio is not applied.

Details

System  class diagram
Every 3D object such as MutiColoredCube derives from BaseGeometry class. It overrides mesh with an instance of CubeMesh to generate geometry.
MultiColoredCube
MutiColoredCube is derived from BaseGeometry class. It assembles vertex data generated by mesh in VBO buffers. Later  sent to GPU using shader programs.
Methods
NameDescription
InitThis method overrides the base class Init method. It creates the mesh object. Generates the vertices data consisting of Position and color in non indexed mode. and later sets them up in VBO buffers. 
vertexShaderSourceThis method overrides the base class vertexShaderSource method. It returns the vertex shader code to render the cube object.
fragmentShaderSourceThis method overrides the base class fragmentShaderSource method. It returns the fragment shader code to render the cube object.

Output


No comments:

Post a Comment