Opengl presentation


Published on

opengl presentation course in ITI

1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Opengl presentation

  1. 1. OpenGL
  2. 2. OpenglOpenGL has been around for over 16 years. Itsdevelopment is overseen by the Khronos group.OpenGL has undergone some radical changes in its mostrecent release.
  3. 3. OpenGL Architectureinternal state machineIn programmable it is up to theprogrammer to not only pass inthe correct information (forexample the color of the vertex)but also apply this informationto the vertex in the shader.
  4. 4. What is opengl?
  5. 5. Pipeline
  6. 6. Fixed-Function vs. Programmability
  7. 7. Related LibrariesGLUT (OpenGL Utility Toolkit)SDL
  8. 8. GLUTOpenGL Utility Toolkitwindowing, menus, or input
  9. 9. SDLThe Simple Direct Media Layeraudio, input, 2D graphics, and many other things
  10. 10. WGLprevent multiple OpenGL applications from interfering witheach other. This is done through the use of a renderingcontextOnly one rendering context per thread.HGLRC wglCreateContext(HDC hDC);BOOL wglDeleteContext(HGLRC hRC);BOOL wglMakeCurrent(HDC hDC, HGLRC hRC);
  11. 11. WGLHGLRC wglGetCurrentContext();HDC wglGetCurrentDC();
  12. 12. Pixel Formatstypedef 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; BYTEcAccumAlphaBits; BYTE cDepthBits;BYTE cStencilBits; BYTE cAuxBuffers; BYTE iLayerType;BYTE bReserved;DWORD dwLayerMask; DWORD dwVisibleMask; DWORD dwDamageMask;} PIXELFORMATDESCRIPTOR;
  13. 13. 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
  14. 14. Setting the Pixel Formatint ChoosePixelFormat(HDC hdc, CONSTPIXELFORMATDESCRIPTOR *ppfd); (modify pixelformat to match supported and return id for pixel format)BOOL SetPixelFormat(HDC hdc, int pixelFormat, constPIXELFORMATDESCRIPTOR *ppfd);
  15. 15. State Functions
  16. 16. void glGetBooleanv(GLenum pname, GLboolean*params); void glGetDoublev(GLenum pname, GLdouble*params); void glGetFloatv(GLenum pname, GLfloat*params); void glGetIntegerv(GLenum pname, GLint*params);
  17. 17. Enabling and Disabling Statesvoid glEnable(GLenum cap);void glDisable(GLenum cap);GLboolean glIsEnabled(GLenum cap);
  18. 18. Querying String Valuesconst GLubyte *glGetString(GLenum name);GL_VENDOR , GL_RENDERER , GL_VERSION ,GL_EXTENSIONS
  19. 19. Finding ErrorsGLenum glGetError();
  20. 20. Colors in OpenGLvoid glColor (T components);void glColorv(T components);
  21. 21. Primitives
  22. 22. Handling PrimitivesImmediate ModeVertex Arrays
  23. 23. Immediate Modevoid glBegin(GLenum mode);glBegin()glEnd()GL_INVALID_OPERATIONvoid glVertex{234}{dfis}();void glVertex{234}{dfis}v();
  24. 24. Demo 1
  25. 25. Vertex Arraysvoid glEnableClientState(GLenum cap);void glDisableClientState(GLenum cap);gl*Pointer()void glVertexPointer(GLint size, GLenum type, GLsizeistride, 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
  26. 26. Vertex Arraysvoid glColorPointer(GLint size, GLenum type, GLsizeistride, const GLvoid *array);void glEdgeFlagPointer(GLsizei stride, const GLboolean*array); Array of Booleanvoid glNormalPointer(GLenum type, GLsizei stride, constGLvoid *array); normals always (x,y,z) so no need for thesize.void glTexCoordPointer(GLint size, GLenum type, GLsizeistride, const GLvoid *array); size = number of coordinateper vertex
  27. 27. Rendering Uesing Vertex Arraysvoid glDrawArrays(GLenum mode, GLint first, GLsizeicount);void glDrawElements(GLenum mode, GLsizei count,GLenum type, const GLvoid *indices); [count is thenumber of indices that you want to render ]void glDrawRangeElements(GLenum mode, GLuint start,GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
  28. 28. Demo vertix_with_indcies
  29. 29. Rendering Uesing Vertex Arraysvoid glMultiDrawArrays(GLenum mode, GLint *first,GLsizei *count, GLsizei primcount)
  30. 30. 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.
  31. 31. Generating a Namevoid glGenBuffers(GLsizei n, GLuint *buffers);void glDeleteBuffers(GLsizei n, const GLuint *buffers);
  32. 32. Binding the BufferBinding a buffer makes it current; all buffer-related OpenGL callsand 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_BUFFERGL_ARRAY_BUFFER for vertices data andGL_ELEMENT_ARRAY_BUFFER for indices data.if buffer is zero, the call will unbind any currently bound buffer.
  33. 33. Filling the Buffervoid glBufferData(GLenum target, GLsizeiptr size, constGLvoid *data, GLenum usage);usage is a hint to OpenGL telling it how you intend to usethis 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_COPYCalling glBufferData() on a buffer object that alreadycontains data will cause the old data to be destroyed andreplaced with the new data
  34. 34. Rendering with Buffers and Vertex ArraysWhen rendering with VBOs you use gl*Pointer() functionsas an offset.
  35. 35. Demo simple point
  36. 36. Modifying Point Sizevoid glPointSize(GLfloat size)If point anti-aliasing is disabled then the point size isrounded to the nearest integer never zero.