0% found this document useful (0 votes)
48 views4 pages

CG Exp-1 Case Study2

The document discusses OpenGL fundamentals including primitives, commands, and the basic OpenGL operation pipeline. It then provides a program example in C using OpenGL commands to draw a red square primitive and outputs it to the screen.

Uploaded by

piyush
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views4 pages

CG Exp-1 Case Study2

The document discusses OpenGL fundamentals including primitives, commands, and the basic OpenGL operation pipeline. It then provides a program example in C using OpenGL commands to draw a red square primitive and outputs it to the screen.

Uploaded by

piyush
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Neel Sanjay Bhatt

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:

 "OpenGL Fundamentals" briefly explains basic OpenGL concepts, such as what a


graphic primitive is and how OpenGL implements a client-server execution model.

 "Basic OpenGL Operation" gives a high-level description of how OpenGL processes


data and produces a corresponding image in the frame buffer.

2.Primitives and Commands

 OpenGL draws primitives—points, line segments, or polygons—subject to several


selectable modes. You can control modes independently of each other; that is,
setting one mode doesn't affect whether other modes are set (although many
modes may interact to determine what eventually ends up in the frame buffer).
Primitives are specified, modes are set, and other OpenGL operations are described
by issuing commands in the form of function calls.

 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.

3.Basic OpenGL Operation


The processing stages in basic OpenGL operation are as follows:

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

• The evaluator stage of processing provides an efficient way to approximate curve


and surface geometry by evaluating polynomial commands of input values.
Per-vertex operations and primitive assembly

• OpenGL processes geometric primitivespoints, line segments, and polygonsall of


which are described by vertices. Vertices are transformed and lit, and primitives are
clipped to the viewport in preparation for rasterization.

Rasterization

• The rasterization stage produces a series of frame-buffer addresses and associated


values using a two-dimensional description of a point, line segment, or polygon.
Each fragment so produced is fed into the last stage, per-fragment operations.

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:

 Stored as texture memory, for use in the rasterization stage.

 Rasterized, with the resulting fragments merged into the framebuffer just
as if they were generated from geometric data.

4.Block Diagram of Open GL :-

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

// Draw a Red 1x1 Square centered at origin


glBegin(GL_QUADS); // Each set of 4 vertices form a quad
glColor3f(1.0f, 0.0f, 0.0f); // Red
glVertex2f(-0.5f, -0.5f); // x, y
glVertex2f( 0.5f, -0.5f);
glVertex2f( 0.5f, 0.5f);
glVertex2f(-0.5f, 0.5f);
glEnd();

glFlush(); // Render now


}

/* Main function: GLUT runs as a console application starting at main() */

int main(int argc, char** argv) {


glutInit(&argc, argv); // Initialize GLUT
glutCreateWindow("OpenGL Setup Test"); // Create a window with the given title
glutInitWindowSize(320, 320); // Set the window's initial width & height
glutInitWindowPosition(50, 50); // Position the window's initial top-left corner
glutDisplayFunc(display); // Register display callback handler for window re-paint
glutMainLoop(); // Enter the infinitely event-processing loop
return 0;
}

OUTPUT :-

CONCLUSION:
Hence, we have studied Basic Open GL Operations and performed a Program in C
language using Open GL library.

You might also like