OpenGL interview questions and answers
Q1. What are the advantages of Open GL over other API’s?
The advantages of OpenGL over other API’s are listed below:
- For drawing calls and state changes, OpenGL has lower CPU overhead than the other API’s.
- There is more detailed documentation for OpenGL while other API’s don’t have such detailed documentation.
- OpenGL is more functional than any other API.
- OpenGL is portable.
- It is a cross-platform API, i.e. it can be used on various platforms such as- windows, WindowsMac, and some handheld devices.
- It is more extensible, i.e. new hardware features are exposed quickly.
- It has a stable interface until some bigger changes are made.
Q2. Explain rendering pipeline with reference to OpenGL.
While rendering objects, OpenGL makes use of a sequence of steps and this sequence of steps is known as rendering pipeline. Firstly, the rendering pipeline prepares the vertex array data and then renders it. A vertex shader acts upon each data and then the processed is turned into an output vertex. Now, these outputs are shifted to different locations. Primitive assembly is made. Now, the scan conversion and primitive parameter interpolation generate a number of fragments. Now, the fragment shader processes each fragment and numbers of outputs are generated. Various tests are conducted in the per-sample processing and hence the final output is obtained.
Q3. What do you mean by the term Rasterization? How is it different from vector graphics?
The process, in which a primitive individual is broken down into discrete elements called fragments, is known as Rasterization. These fragments are based on the sample coverage of the primitive. It is a process with the help of which a primitive is converted into a two-dimensional image. When rasterizing a primitive, it consists of two parts:
- Determine which square in the integer grid window has been occupied by the primitive.
- Assigning a color and depth value to each occupied grid.
It is a process in which the occupied pixels by the primitives are identified and the output variable of the vertex shader is interpolated for each covered pixel.
Q4. Name the major stages of vertex transformation with reference to OpenGL.
In vertex transformation, the vertices are transformed to their final clip space position in the vertex shader. The various major stages of vertex transformation are:
- Getting to the eye coordinates- the vertex provided to the GL is considered to be in the object space.
- Getting to clip coordinate- when the vertex is transformed by the projection matrix, then we get the clip matrix.
- Getting to normalized device coordinates- when each component is multiplied by 1/w, then we get the normalized device coordinates. It is mainly inside the clipping planes.
- Getting to window space- this is the final stage of transformation pipeline. Everything out of the range is clipped away.
Suggested Read Neo4j interview questions
Q5. What do you understand by color perception in OpenGL?
Drawing color pictures in a window on the screen is the main goal and application of OpenGL. Every calculation done in OpenGL is done to determine the final color of every pixel that is to be drawn in the window. We all know that light is composed of various photons and each photon travels along its own path and vibrates along its own frequency. When certain cells in the retina of human eye get excited after being struck by the photon, then it perceives color. This process is known as color perception. Similarly, if we talk about the computer screen, each pixel emits the different amount of red, green, and blue light on the screen. Since the color maps are controlled by the window system, so it becomes a bit difficult to do this with the help of OpenGL commands.