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

OpenGL - Assignment

OpenGL is a cross-language, cross-platform API used to interact with a GPU for hardware-accelerated 2D and 3D graphics rendering. It is typically used with C/C++. The code sample draws a red triangle using OpenGL by defining vertex and fragment shaders, initializing buffers with vertex positions, and drawing arrays of triangles. Ray tracing simulates paths of light and encounters with objects to render realistic images, while rasterization converts vector images to raster pixels for display. Ray tracing produces more realistic images with effects like reflections and shadows but is more computationally expensive.

Uploaded by

adnan khan
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)
146 views4 pages

OpenGL - Assignment

OpenGL is a cross-language, cross-platform API used to interact with a GPU for hardware-accelerated 2D and 3D graphics rendering. It is typically used with C/C++. The code sample draws a red triangle using OpenGL by defining vertex and fragment shaders, initializing buffers with vertex positions, and drawing arrays of triangles. Ray tracing simulates paths of light and encounters with objects to render realistic images, while rasterization converts vector images to raster pixels for display. Ray tracing produces more realistic images with effects like reflections and shadows but is more computationally expensive.

Uploaded by

adnan khan
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

ASSIGNMENT #2

Q#1: Explore OpenGL. How to use it along with C language? Write a program to
draw a triangle using OpenGL and share screenshot and code?
Answer: Open GL
Open Graphics Library (OpenGL) is a cross-language, cross-platform application
programming interface (API) for rendering 2D and 3D vector graphics. The API is
typically used to interact with a graphics processing unit (GPU), to achieve
hardware-accelerated rendering.
Using It with C Language:
OpenGL is a C library, not a C++ one. The only thing why almost all programs use
C++ for OpenGL is there is a higher and simpler level manipulating it through
some wrappers, libraries or frameworks
Draw Triangle Code:
// Triangle.js
// Vertex shader program
var VSHADER_SOURCE =
'attribute vec4 a_Position;\n' +
'void main() {\n' +
' gl_Position = a_Position;\n' +
'}\n';

// Fragment shader program


var FSHADER_SOURCE =
'void main() {\n' +
' gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n' +
'}\n';
function main() {

// Get the rendering context for WebGL


var gl = getWebGLContext(canvas);

// Initialize shaders
if (!initShaders(gl, VSHADER_SOURCE, FSHADER_SOURCE)) {

// Set the positions of vertices


var n = initVertexBuffers(gl);

// Set the color for clearing <canvas>

// Draw a triangle
gl.drawArrays (gl.TRIANGLES, 0, n);
}

function initVertexBuffers(gl) {
var vertices = new Float32Array([
0.0, 0.5, -0.5, -0.5, 0.5, -0.5
]);
var n = 3; // The number of vertices
return n;
}
Output:

Q#2: Compare different graphic libraries?


Answer: Difference between Direct3D and OpenGL Graphic Libraries:
The most obvious difference is that DirectX is more than just a graphics API.
DirectX contains tools to deal with sound, input, networking, and multimedia. On
the other hand, OpenGL is strictly a graphics API. So the comparison is
really between OpenGL and Direct3D.
Q#3: Watch a video about ray tracing technique used in modern graphic cards vs
rasterization and write what you understand? Compare both of them?
Answer: My Opinion and Comparison:
Ray tracing is a rendering technique for generating an image by tracing
the path of light as pixels in an image plane and simulating the effects of
its encounters with virtual objects. On the other hand rasterization is the task of
taking an image described in a vector graphics format (shapes) and converting it
into a raster image a series of pixels, dots or lines, which, when displayed
together, create the image which was represented via shapes.

-------END------

You might also like