CG Exp-1 Case Study2
CG Exp-1 Case Study2
Roll No:-07
SE computer A
EXPERIMENT NO.1
CASE STUDY 2
Aim:To study and apply basic OpenGl function to draw basic primitives
1. Introduction to OpenGL
As a software interface for graphics hardware, OpenGL's main purpose is to render two-
and three-dimensional objects into a frame buffer. These objects are described as
sequences of vertices (which define geometric objects) or pixels (which define images).
OpenGL performs several processing steps on this data to convert it to pixels to form the
final desired image in the frame buffer.
This chapter presents a global view of how OpenGL works; it contains the following major
sections:
Primitives are defined by a group of one or more vertices. A vertex defines a point,
an endpoint of a line, or a corner of a polygon where two edges meet. Data
(consisting of vertex coordinates, colors, normals, texture coordinates, and edge
flags) is associated with a vertex, and each vertex and its associated data are
processed independently, in order, and in the same way. The only exception to this
rule is if the group of vertices must be clipped so that a particular primitive fits
within a specified region; in this case, vertex data may be modified and new vertices
created. The type of clipping depends on which primitive the group of vertices
represents.
Display list
• Rather than having all commands proceed immediately through the pipeline, you
can choose to accumulate some of them in a display list for processing later.
Evaluator
Rasterization
Per-fragment operations
• These are the final operations performed on the data before it is stored as pixels in
the framebuffer.
• Per-fragment operations include conditional updates to the framebuffer based on
incoming and previously stored z values (for z buffering) and blending of incoming
pixel colors with stored colors, as well as masking and other logical operations on
pixel values.
• Data can be input in the form of pixels rather than vertices. Data in the form of
pixels, such as might describe an image for use in texture mapping, skips the first
stage of processing described above and instead is processed as pixels, in the pixel
operations stage. Following pixel operations, the pixel data is either:
Rasterized, with the resulting fragments merged into the framebuffer just
as if they were generated from geometric data.
The following diagram illustrates how OpenGL processes data. As shown, commands enter
from the left and proceed through a processing pipeline. Some commands specify
geometric objects to be drawn, and others control how the objects are handled during
various processing stages.
5. Program using OpenGL Commands to draw Basic primitive along with output :-
#include <windows.h>
#include <GL/glut.h>
void display() {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set background color to black and opaque
glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer
OUTPUT :-
CONCLUSION:
Hence, we have studied Basic Open GL Operations and performed a Program in C
language using Open GL library.