opengl presentation
DESCRIPTION
opengl presentation course in ITITRANSCRIPT
![Page 1: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/1.jpg)
OpenGL
![Page 2: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/2.jpg)
Opengl
OpenGL has been around for over 16 years. Its development is overseen by the Khronos group.
OpenGL has undergone some radical changes in its most recent release.
![Page 3: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/3.jpg)
OpenGL Architecture
internal state machine
In programmable it is up to the programmer to not only pass in the correct information (for example the color of the vertex) but also apply this information to the vertex in the shader.
![Page 4: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/4.jpg)
What is opengl?
![Page 5: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/5.jpg)
Pipeline
![Page 6: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/6.jpg)
Fixed-Function vs. Programmability
![Page 7: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/7.jpg)
Related Libraries
GLUT (OpenGL Utility Toolkit)
SDL
![Page 8: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/8.jpg)
GLUT
OpenGL Utility Toolkit
windowing, menus, or input
![Page 9: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/9.jpg)
SDL
The Simple Direct Media Layer
audio, input, 2D graphics, and many other things
![Page 10: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/10.jpg)
WGL
prevent multiple OpenGL applications from interfering with each other. This is done through the use of a rendering context
Only one rendering context per thread.
HGLRC wglCreateContext(HDC hDC);
BOOL wglDeleteContext(HGLRC hRC);
BOOL wglMakeCurrent(HDC hDC, HGLRC hRC);
![Page 11: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/11.jpg)
WGL
HGLRC wglGetCurrentContext();
HDC wglGetCurrentDC();
![Page 12: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/12.jpg)
Pixel Formats
typedef struct tagPIXELFORMATDESCRIPTOR {
WORD nSize;WORD nVersion;DWORD dwFlags;BYTE iPixelType;BYTE cColorBits;BYTE cRedBits;BYTE cRedShift;BYTE cGreenBits;BYTE cGreenShift; BYTE cBlueBits;BYTE cBlueShift;BYTE cAlphaBits;BYTE cAlphaShift; BYTE cAccumBits;BYTE cAccumRedBits; BYTE cAccumGreenBits; BYTE cAccumBlueBits; BYTE cAccumAlphaBits; BYTE cDepthBits;BYTE cStencilBits; BYTE cAuxBuffers; BYTE iLayerType;BYTE bReserved;DWORD dwLayerMask; DWORD dwVisibleMask; DWORD dwDamageMask;
} PIXELFORMATDESCRIPTOR;
![Page 13: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/13.jpg)
Pixel Formats
nSize
dwFlags
iPixelType PFD_TYPE_RGBA. RGBA pixels. Each pixel has four components in this order: red, green, blue, and alpha.
PFD_TYPE_COLORINDEX. Paletted mode. Each pixel uses a color-index value.
• cColorBits the bits per pixel
![Page 14: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/14.jpg)
Setting the Pixel Format
int ChoosePixelFormat(HDC hdc, CONST PIXELFORMATDESCRIPTOR *ppfd); (modify pixel format to match supported and return id for pixel format)
BOOL SetPixelFormat(HDC hdc, int pixelFormat, const PIXELFORMATDESCRIPTOR *ppfd);
![Page 15: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/15.jpg)
State Functions
![Page 16: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/16.jpg)
void glGetBooleanv(GLenum pname, GLboolean *params); void glGetDoublev(GLenum pname, GLdouble *params); void glGetFloatv(GLenum pname, GLfloat *params); void glGetIntegerv(GLenum pname, GLint *params);
![Page 17: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/17.jpg)
Enabling and Disabling States
void glEnable(GLenum cap);
void glDisable(GLenum cap);
GLboolean glIsEnabled(GLenum cap);
![Page 18: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/18.jpg)
Querying String Values
const GLubyte *glGetString(GLenum name);
GL_VENDOR , GL_RENDERER , GL_VERSION , GL_EXTENSIONS
![Page 19: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/19.jpg)
Finding Errors
GLenum glGetError();
![Page 20: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/20.jpg)
Colors in OpenGL
void glColor (T components);
void glColorv(T components);
![Page 21: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/21.jpg)
Primitives
![Page 22: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/22.jpg)
Handling Primitives
Immediate Mode
Vertex Arrays
![Page 23: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/23.jpg)
Immediate Mode
void glBegin(GLenum mode);
glBegin()
glEnd()
GL_INVALID_OPERATION
void glVertex{234}{dfis}();
void glVertex{234}{dfis}v();
![Page 24: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/24.jpg)
Demo 1
![Page 25: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/25.jpg)
Vertex Arrays
void glEnableClientState(GLenum cap);
void glDisableClientState(GLenum cap);
gl*Pointer()
void glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *array);
size must be 2, 3, or 4 and
Type can be set to GL_SHORT, GL_INT, GL_FLOAT, or GL_DOUBLE.
Stride padding in bytes between each vertex
![Page 26: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/26.jpg)
Vertex Arrays
void glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *array);
void glEdgeFlagPointer(GLsizei stride, const GLboolean *array);
Array of Boolean
void glNormalPointer(GLenum type, GLsizei stride, const GLvoid *array); normals always (x,y,z) so no need for the size.
void glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *array); size = number of coordinate per vertex
![Page 27: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/27.jpg)
Rendering Uesing Vertex Arrays
void glDrawArrays(GLenum mode, GLint first, GLsizei count);
void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); [count is the number of indices that you want to render ]
void glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid * indices);
![Page 28: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/28.jpg)
Demo vertix_with_indcies
![Page 29: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/29.jpg)
Rendering Uesing Vertex Arrays
void glMultiDrawArrays(GLenum mode, GLint *first, GLsizei *count, GLsizei primcount)
![Page 30: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/30.jpg)
Vertex Buffer Objects
(VRAM) instead of (RAM)
To use a VBO, you need to perform the following steps:
1. Generate a name for the buffer.
2. Bind (activate) the buffer.
3. Store data in the buffer.
4. Use the buffer to render the data. 5. Destroy the buffer.
5. Destroy the buffer.
![Page 31: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/31.jpg)
Generating a Name
void glGenBuffers(GLsizei n, GLuint *buffers);
void glDeleteBuffers(GLsizei n, const GLuint *buffers);
![Page 32: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/32.jpg)
Binding the Buffer
Binding a buffer makes it current; all buffer-related OpenGL calls and rendering will operate on the currently bound buffer.
void glBindBuffer(GLenum target, GLuint buffer);
target can be GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER, GL_PIXEL_PACK_BUFFER, or GL_PIXEL_UNPACK_BUFFER
GL_ARRAY_BUFFER for vertices data and GL_ELEMENT_ARRAY_BUFFER for indices data.
if buffer is zero, the call will unbind any currently bound buffer.
![Page 33: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/33.jpg)
Filling the Buffer
void glBufferData(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage);
usage is a hint to OpenGL telling it how you intend to use this buffer. It can be GL_STREAM_DRAW, GL_STREAM_READ, GL_STREAM_COPY, GL_STATIC_DRAW, GL_STATIC_READ, GL_STATIC_COPY, GL_DYNAMIC_DRAW, GL_DYNAMIC_READ, or GL_DYNAMIC_COPY
Calling glBufferData() on a buffer object that already contains data will cause the old data to be destroyed and replaced with the new data
![Page 34: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/34.jpg)
Rendering with Buffers and Vertex Arrays
When rendering with VBOs you use gl*Pointer() functions as an offset.
![Page 35: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/35.jpg)
Demo simple point
![Page 36: Opengl presentation](https://reader030.vdocuments.us/reader030/viewer/2022012403/54b4da454a7959ce608b45a4/html5/thumbnails/36.jpg)
Modifying Point Size
void glPointSize(GLfloat size)
If point anti-aliasing is disabled then the point size is rounded to the nearest integer never zero.