OpenGL chapter 1

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Vertices almost always include...

... positional data

OpenGL rendering pipeline

A sequence of processing stages for converting data your application provides to OpenGL into a final rendered image.

i

Glint, GLsizei — 32bit integer

You get more portability in GLSL by

Not using the most recent version number

GLSL

OpenGL Shading Language

glDrawArrays()

OpenGL drawing command that requests geometric primitives be rendered

Often times a typical Init() will ...

Specify position information for primitives and specify shades we will use in the program.

GLUT

The OpenGL utility toolkit. It's popular as a cross-platform toolkit for opening windows, managing input, etc.

rendering

The process by which a computer creates an image from models

Fragment discard

When a fragment shader determines that a fragment shouldn't be drawn.

Current

When any operation relevant to the bound object (like the vertex array we're working with) will affect its state from that point in in the program's execution.

Allocation scheme in OpenGL

binding an object, which is done by a collection o functions in OpenGL with the form glBind*

glBufferData(target)

may be either GL_ARRAY_BUFFER for vertex attribute data, GL_ELEMENT_ARRAY_BUFFER for index data, GL_PIXEL_UNPACK_BUFFER for pixel data being passed into OpenGL, GL_PIXEL_PACK_BUFFER for pixel data being retrieved from OpenGL, GL_COPY_READ_BUFFER and GL_COPY_WRITE_BUFFER for data copied between buffers, GL_TEXTURE_BUFFER for texture data stored as a texture buffer, GL_TRANSFORM_FEEDBACK_BUFFER for results from executing a transform feedback shader, or GL_UNIFORM_BUFFER for uniform variable values.

When you bind an object for the first time...

... OpenGL will internally allocate the memory it needs and make that object current.

When we bind a buffer...

... We need to specify which type to use

OpenGL requires that all data be stored in

... buffer objects (chunks of memory managed by the OpenGL server)

Using OpenGL defined data types throughout your application avoids ...

... mismatched types when porting your code between different implementations.

Once you have allocated names for your buffers,

... you bring them into existence by calling glBindBuffer()

After the first call to any glBind*() function...

.... the newly created object will be initialized to its default state and will usually require some additional initialization to make it useful

3 steps of display()

1. Clear the window by calling glClear(). 2.Issue the openGL calls required to render your object. 3. Request that the image is presented to the screen.

Basic structure of most OpenGL programs

1. Initialize the state associated with how objects should be rendered. 2. Specify those objects to be rendered

Generally speaking, you will bind an object in two situations:

1. Initially when you create and initialize the data it will hold 2. Every time you want to use it and it's not currently bound.

Major operations an OpenGL application performs to render an image

1. Specify the data for constructing shapes from OpenGL's geometric primitives. 2. Execute various shaders to perform calculations on the input primitives to determine their position, color and other rendering attributes. 3. Convert the mathematical description of the input primitives into their fragments associated with locations on the screen. This process is called rasterization. 4. Finally, execute a fragment shader for each of the fragments generated by rasterization, which will determine the fragment's final color and position. 5. Possibly perform additional per-fragment operations such as determining if the object that the fragment was generated from is visible, or blending the fragment's color with the current color in that screen location.

shader stages

1. Vertex shaders — process vertex data 2. Fragment shaders — operate on fragments generated by the rasterizer

LoadShaders()

A helper routine written to simplify the process of preparing shaders for the GPU.

glGenVertexArrays()

Allocates a vertex-array object. Returns n currently unused named for use as vertex-array objects in the array. The names returned are marked as used for the purpose of allocating additional buffer objects, and initialized with values representing the default state of the collection of uninitialized vertex arrays.

glBufferData()

Allocates storage for holding the vertex data and copying the data from arrays in the applicAtion to the OpenGL server's memory.

Geometry shading

Allows additional processing of individual geometric primitives (including creating new ones) before rasterization. This stage is optional.

glutMainLoop()

An infinite loop that works with the window and operating systems to process user input and other operations.

A GL_INVALID_OPERATION error is generated if ...

Array is not a value previously returned from glGenVertexArrays(), or if it is a value that has been released by glDeleteVertexArrays()

Display()

Calls the OpenGL functions that request something to be rendered. It is usually done in 3 simple steps

OpenGL is implemented as a

Client-server system, with you as an implementer being the client and the OpenGL implementation being the server

glutInitWindowSize()

Configures the size of the window. You can also query the size of the display to dynamically size the window to fit your screen.

glutInitDisplayMode()

Configures the type of window we want to use with our application. There are other features than just RGBA background such as depth buffers.

Rasterization

Converting the mathematical descriptions of the input primitives into fragments and associating those fragments with a location on screen.

Main()

Creates a window, calls init, and enters the event loop.

glutCreateWindow()

Creates the window for display. Only after the window is created can you execute OpenGL functions.

glDeleteBuffers()

Deletes n buffer objects, named by elements in the array buffers. The freed buffer objects may now be reused. If a buffer object is deleted while bound, all bindings to that object are reset to the default buffer object, as if glBindBuffer() has been called with zero as the specified buffer object. Attempts to delete nonexistent buffer objects or the buffer object named zero are ignored without error.

glDeleteVertexArray()

Deletes the n vertex-arrays objects specified in arrays, enabling the names for reuse as vertex arrays later. If a bound vertex array is deleted, the binding for that vertex array become zero (as if you had called glBindBuffer() with a value of zero) and the default vertex array becomes the current one. Unused names in arrays are released, but no changes to the current vertex array state are made.

Fragment shader

Determines the fragment's final color and location.

glBindBuffer()

Does three things 1. When using buffer of an unsigned integer other than zero for the first time, a new buffer object is created an assigned that name. 2. When binding to a previously created buffer object, that buffer object becomes the active buffer object. 3. When binding to a buffer value of zero, OpenGL stops using buffer objects for that target.

Per fragment operations

During this stage a fragment's visibility is determined using depth testing. If a fragment makes it through the enabled tests, it may be written directly to the framebuffer.

glBufferData(data)

Either a pointer to client memory that is used to initialize the buffer object or NULL. If a valid pointer is passed, size units of storage are copied from the client to the server. If NULL is passed, size units do storage are reserved for use but are left uninitialized.

Vertex Shading

For each vertex that is issued by the drawing command, a vertex shader will be called to process the data associated with that vertex. Shaders can be very simple — just copying data to pass through the shading stage (known as pass-through shaders) Shaders can be very complex — Performing many calculations (usually using transformational matrixes) to determine the the vertex's color using lighting computations.

The pixels in your screen are stored in a ———, which is a chunk of memory that the graphics hardware manages and feeds to the display.

Framebuffer

b

GLByte — 8bit integer

When storing vertex data in a buffer, we use ——- to specify the data

GL_ARRAY_BUFFER

8 types of buffer objects

GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER GL_PIXEL_PACK_BUFFER GL_PIXEL_UNPACK_BUFFER GL_COPY_READ_BUFFER GL_COPY_WRITE_BUFFER GL_TRANSFORM_FEEDBACK_BUFFER GL_UNIFORM_BUFFER

glBufferData() will generate a ___________ error if usage is not one of the permitted values

GL_INVALID_VALUE

glBufferData() will generate a ___________ error ur the requested size exceeds what the server will be able to allocate.

GL_OUT_OF_MEMORY

d

GLdouble, GLclampd — 64bit floating point

f

GLfloat, GLclampf — 32bit floating point

s

GLshort — 16bit integer

ub

GLubyte — 8bit unsigned integer

us

GLushort — 16bjt unsigned integer

Points

Geometric primitives that are specified by their vertices

ui

Gluint, GLenum, GLbitfield — 32bit unsigned integer

Clipping

Handles vertices outside the viewport by modifying the primitives.

init()

Initializes all the relevant OpenGL data we can use for rendering.

glutInit()

Initializes the GLUT library. It processes the command line arguments provided to the program and removes and that control joe GLUT might operate. This needs to be the first GLUT function that your application calls.

Typically most applications will have

Multiple vertex shaders, but only one can be active at any one time.

Open GL is implemented in the Window X system as a

Network, with clients and servers executing on different machines.

GLEW

OpenGL extension wrangler

Primitive assembly

Organizes the vertices into their associated geometric primitives in preparation for clipping and rasterization.

A name is a little like a ...

Pointer-type variable in C in that until you allocate some memory and have the name reference it, the name isn't much help.

glBufferData()

Populates the buffer objects with your data

glBufferData(usage)

Provides a hint as to how the data will be read and written after allocation. Valid values: GL_STREAM_COPY GL_STREAM_READ GL_STREAM_DRAW GL_STATIC_DRAW GL_STATIC_READ GL_STATIC_COPY GL_DYNAMIC_READ GL_DYNAMIC_DRAW GL_DYNAMIC_COPY

normalized device coordinates

Range of coordinates to draw geometric primitives

OpenGL is a ______ system

Rasterization-based

Vertex and fragment shaders are

Required in every OpenGL program

glIsVertexArray

Returns GL_TRUE if array is the name of a vertex-array object that was previously generated with glGenVertexArrays(), but has not been subsequently deleted. Returns GL_FALSE if array is zero or a nonzero value that is not the name of a vertex-array object.

glIsBuffer()

Returns TRUE if buffer is the name of a buffer object that has been bound, but not subsequently deleted. RETURNS FALSE if buffer is zero or if buffer is a nonzero value that is not the name of a buffer object.

glGenBuffers()

Returns n currently unused names for buffer objects in the array buffers. The names returned in buffers do not have to be a contiguous set of integers. The names returned are marked as used for the purposes of allocating additional buffer objects, but only acquire a valid state once they have been bound. Zero is a reserved buffer object name and is never returned as a buffer object by this function.

Display callback

Set up by glutDisplayFunc(), it is the routine GLUT will call when it thinks the contents of the window need to be updated.

glutDisplayFunc()

Sets up display callback. It uses a number of callback functions for processing things like user input, window resizing, etc.

Binding an object is like...

Setting a track switch at a railroad yard. Once a track switch has been set, all trains go down that track.

The sequence of initializing a vertex-buffed object

Similar in flow to that of creating a vertex-array object, with an added step to actually populate the buffer with data.

glewInit()

Simplified dealing with accessing functions and other programming phenomena.

glutInitContextVersion(), glutInitContextProfile()

Specifies the OpenGL internal data structure for keeping track of state settings and operations that we want to use. This is called context. Profile selection determines if you're using the latest features in OpenGL

#version 430 core

Specifies which version of GLSL we want to use

LoadShaders()

Takes an array of ShaderInfo structures.

glBufferData(size)

The amount of storage required for storing the respective data. This value is generally the number of elements in the data multiplied by their respective storage size.

Shader plumbing

The final part of init(). This is where you associate the data in your application with variables in shader programs.

Rasterization

The rasterizer generates fragments, with fragments being candidate pixels for the viewport.

ray tracing

The technique for adding light and shadows to a 3-D image (beyond the scope of this book)

glBindVertexArray()

This call does three things. 1. When using the value array that is other than zero and was returned from glGenVertexArrays(), a new vertex-array object is created and assigned to that name. 2. When binding to a previously created vertex-array object, that vertex array object becomes active, which additionally affects the vertex array state stored in the object. 3. When binding to an array value of zero OpenGL stops using application-allocated vertex-array objects and returns to the default state for vertex arrays.

Init()

This routine is used to set up data for use later in the program. This may be vertex information for later use when rendering primitives or for texture mapping.

Drawing

Transferring vertex data to the OpenGL server

Vector

Two floating point values are passed as a one dimensional array instead of two separate parameters.

Tessellation shading

Uses patches to describe an object's shape. The tessellation stage can involve two shaders to manipulate the patch data and generate a final shape.

Fragment shading

Using a shader to determine final color of the fragment and sometimes it's depth value. They often employ texture mapping to augment colors.

Stages of OpenGL rendering pipeline

Vertex data — vertex shader — tessellation control shader — tessellation evaluation shader — geometry shader — primitive setup — clipping — rasterization — fragment shaders — final product

Difference in vertex shading and fragment shading

Vertex shading (including tessellation and geometry shading) determines where on the screen a primitive is, while fragment shading uses that information to determine what color the fragment should be.

Blending

When enabled, the fragments color will be combined with the pixel's current color to generate a new color that is written into the framebuffer.

The values in the vertices array you'll note they're all in the range

[-1, 1]

After we generate a vertex-array object name, we bind it with our call to...

bglBindVertexArray()

All functions in OpenGL begin with

gl

Once you're competed with a vertex-array object, you can delete it with...

glDeleteVertexArray()

Shaders

small scripts that let you configure the how the graphics hardware is set up for rendering

After initializing the buffer-vertex object, we need to

transfer the vertex data from our objects into the buffer object.


Set pelajaran terkait

Sociology Chapter 4: Socialization

View Set

Chapter 9 Extension - Law of Sines and Law of Cosines

View Set

BIOL 220 Exam 2 Homework - Connect

View Set

"What is a Nonprofit Organization?"

View Set

NCIV - Comprehensive Exam Questions

View Set

Duties of the Principal and Agent

View Set