graphics-snippets

StackOverflow


OpenGL resources and reference

GLM

GLEW

GLFW

GLUT

GLUT, FreeGlut, GLFW, etc… Stackoverflow answers

Assimp

The Open-Asset-Importer-Lib
The Open-Asset-Importer-Lib - Viewer
irrXML 1.2 API documentation


Related and miscellaneous

Context

OpenGL Context
OpenGL and multithreading
Legacy OpenGL
Fixed Function Pipeline
Getting Started
Creating an OpenGL Context (WGL)

Shared context

What is shareable between OpenGL contexts and how to enable sharing

Debug context and Debug output

Debug Output

GitHub - graphics-snippets - C++ code snippets - Debug context and Debug output

Direct State Access

Direct State Access

Errors

error hex number
GL_INVALID_ENUM 0x0500 1280
GL_INVALID_VALUE 0x0501 1281
GL_INVALID_OPERATION 0x0502 1282
GL_STACK_OVERFLOW 0x0503 1283
GL_STACK_UNDERFLOW 0x0504 1284
GL_OUT_OF_MEMORY 0x0505 1285

Execution Model

https://stackoverflow.com/questions/59793047/what-is-proper-way-of-handling-data-in-compute-shader
When does OpenGL get finished with pointers in functions?

Extensions

EXT_shader_framebuffer_fetch
KHR_blend_equation_advanced

OpenGL extension availability on newer contexts

History

Why OpenGL uses column-major matrix order?

Light

Concentration of potentially active microfacets in a Normal Distribution Function

Multiple GPUs

Can I use different multiGPU in OpenGL?

Multiple monitors

OpenGL Context with Multiple Devices (Monitors)
What happens when rendering on monitors connected to different GPUs

iOS

OpenGL ES deprecated in iOS 12 and SKShader

Off screen

Minimal Windowless OpenGL Context Initialization
Windowless OpenGL
How to render offscreen on OpenGL?
How to use GLUT/OpenGL to render to a file?
PyOpenGL headless rendering
OpenGL render view without a visible window in python
Creating OpenGL context without window

It is not possible to create an OpenGL Context with an version above 1.0 without any window. But it is possible to use a completely hidden window for “offscreen” rendering. It is possible to create a initially hidden window with the GLFW library by setting the window hint VISIBLE to False.

Sadly it is not possible to create a initially hidden window with Pygame.
It is only possible to hide a window after it was created by pygame.display.iconify(). See also Hiding pygame display.

Performance

Opengl reduce usage of uniforms

Program pipelines

Program pipelines

Sampling

Rendering Pipeline — Performance — Scaling with regard to amount of pixels

Shader program

LearnOpenGL.com - Shaders
The Book of Shaders

Khronos wiki, Rendering Pipeline Overview
Khronos wiki, Shader Compilation
Khronos wiki, GLSL Object
Khronos wiki, Program Introspection
Khronos wiki, Example/GLSL Separate Program Multi Stage
Khronos wiki, Example/GLSL Separate Program Basics

SPIR-V compilation

SPIR-V compilation

Support

Can the OpenGL ‘deprecated’ functions possibly be unsupported?
Will Vulkan effectively “replace” OpenGL or not?
Introducing Zink, an OpenGL implementation on top of Vulkan

Transparent window background

How to make an OpenGL rendering context with transparent background?

three.js

How to move shader scripts in external files?

Threading

Multithreaded Rendering on OpenGL
Im trying to use OpenGL with the windows API on different threads

WebGL

WebGL - is there an alternative to embedding shaders in HTML?

WebGL - Geometry shader

Geometry shader in web
Does every variable have to be set for every vertex emitted in a geometry shader?

Windows

Copying pixel data directly from windows Device Context to an openGL rendering context
Switching from OpenGL to GDI

Drawing

Alpha Compositing, Blending and Premultiplied Alpha

Alpha Compositing, OpenGL Blending and Premultiplied Alpha Alpha Blending: To Pre or Not To Pre Alpha compositing
Blending

ModernGL depth-test ignoring vertices in the back (sometimes?)
Fragments with different depth are blended
Text2DEntity renders opaque and hides other entities behind it
OpenGL: Transparent texture issue

Blending doesn’t work properly when Depth Test is enabled, because the fragments behind already drawn objects are discarded by depth test before they can be blended. You must draw the primitives in the correct order from back to front to make it work properly. See also OpenGL depth sorting and OpenGL: Transparent texture issue.

Blending may not work as you expect when the Depth Test is enabled. The depth test discards the fragments before they can be blended. If depth test and blending are enabled, a fragment that is not discarded during the depth test will be blended. So it depends on the order in which the objects are drawn.
To achieve correct blending of objects with different depths, draw all objects in order from back to front (depth sorting). Since the objects are drawn from back to front, the depth test is not needed at all.

Premultiplied Alpha - WebGL

premultipliedAlpha: false, UNPACK_PREMULTIPLIED_ALPHA_WEBGL!

generating text texture in webgl: Alpha is opaque
WebGL: Beveled smooth anti-aliased circles using GL_POINT?

Buffer

Buffer Object (Immutable Storage / Mutable Storage)

Is it possible to in-place resize VBOs?

Depth buffer

How can I improve the performance of my custom OpenGL ES 2.0 depth texture generation?
How to render depth linearly in modern OpenGL with gl_FragCoord.z in fragment shader?
Pack depth information in a RGBA texture using mediump precison

Is it possible to depth test against a depth texture I am also sampling, in the same draw call?

OpenGL depth test doesn’t work on some computers

In addition to activating the Depth Test (glEnable(GL_DEPTH_TEST)), it is important that the current framebuffer has a depth buffer.
The default framebuffer is created at the time the OpenGL Context is constructed. Thecreation of the OpenGL context depends on the OS and windowing library (e.g. GLFW, SDL, SFML). Whether a depth buffer is created by default often depends on the system. In general, window libraries provide additional options for explicitly specifying a depth buffer when generating the OpenGL window:

For instance:

Frame Buffer

Framebuffer Object
Framebuffer Object Extension Examples
Multisampling

Multiple output buffers with the default framebuffer

OpenGL 4.6 API Compatibility Profile Specification - 17.4.1 Selecting Buffers for Writing, page 631:

If the default framebuffer is affected, then each of the constants must be one of the values listed in table 17.6 or the special value BACK. When BACK is used, n must be 1 and color values are written into the left buffer for single-buffered contexts, or into the back left buffer for double-buffered contexts. If a framebuffer object is affected, then each of the constants must be one of the values listed in table 17.5. In both cases, the draw buffers being defined correspond in order to the respective fragment colors. The draw buffer for fragment colors beyond n is set to NONE.

[Khronos reference page - glCheckFramebufferStatus][https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glCheckFramebufferStatus.xhtml]:

GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE is returned if the value of GL_RENDERBUFFER_SAMPLES is not the same for all attached renderbuffers; if the value of GL_TEXTURE_SAMPLES is the not same for all attached textures; or, if the attached images are a mix of renderbuffers and textures, the value of GL_RENDERBUFFER_SAMPLES does not match the value of GL_TEXTURE_SAMPLES.

Concept: what is the use of glDrawBuffer and glDrawBuffers?
opengl es 2.0 android c++ glGetTexImage alternative

Uniform Buffer Object UBO and Shader storage buffer SSBO

Should I ever use a vec3 inside of a uniform buffer or shader storage buffer object?
Passing a list of values to fragment shader
Can I put a R8G8B8A8 in a UBO, and use it as a vec4?
Can I make a GLSL struct have std140 layout?
GLSL: Are writes to Shader Storage Buffers discarded (or undone) by a later discard statement?

Vertex buffer

What is the proper way to modify OpenGL vertex buffer?

Draw calls

Overhead of glDrawArrays vs. glMultiDrawArrays

Error

Errors during creation of OpenGL objects

Fragment shader

EXT_shader_framebuffer_fetch - gl_LastFragData
Is there a way in Opengl es 2.0 fragment shader, to get a previews fragment color

#extension GL_EXT_shader_framebuffer_fetch : require

Geometry shader

OpenGL Shadow Map Mobile Version Doesn’t work

Gooey

Implementing a gooey effect with a shader (Processing 3)

Glow

How to add glowing effect to a line for OpenGL?
How to get a “Glow” shader effect in OpenGL ES 2.0?

GLSL

Do conditional statements slow down shaders?
Why won’t my GLSL program link when one shader is optimized and the other is not?
Is it ok to declare an oversized output array in fragment shader and leave some indices unused?

Height map and height map normals

OpenGL - How to calculate normals in a terrain height grid?

Image format

How can I use ARGB color in opengl/SDL?

Invocations

Frequency of shader invocations in rendering commands

Lines

Is it really so difficult to draw smooth lines in Unity?

Line stipple

glLineStipple deprecated in OpenGL 3.1
Three.js uniform dashed line relative to camera
Dashed line in OpenGL3?
OpenGL ES - Dashed Lines
Drawing rectangle with dashed boundary in openGL android
Draw a simple dotted line or dashed line in OpenGL GLES20 android using fragment shader and GL_LINE_STRIP

Line thickness

OpenGL Line Width
GLSL Geometry shader to replace glLineWidth
OpenGL 3.2 Core Profile glLineWidth

Matrix and matrix transformation

Transformation order reversed in glMatrix?
Algorithm for finding Eigenvectors given Eigenvalues of a 3x3 matrix in C#

Mip mapping

How to access automatic mipmap level in GLSL fragment shader texture?
How to perform Mipmapping in WebGL?
Does it make sense to use own mipmap creation algorithm for OpenGL textures?

Multi Sampling

How multi sampling works for Integer textures

Morphing

how should i handle (morphing) 4D objects in opengl?

Multi Indexing

Rendering meshes with multiple indices
Why does OpenGL not support multiple index buffering?

Noise

Random / noise functions for GLSL

Normal matrix - transpose inverse

Why transforming normals with the transpose of the inverse of the modelview matrix?

Outline

Silhouette-Outlined shader
OpenGL - object outline
Scalable outline for any shape with THREE.js

Projection

What exactly are eye space coordinates?
Get Projection and View Matrix from Camera Matrix
Projection matrices: What should depth map to?
Transformation of 3D objects related to vanishing points and horizon line

Quaternion

Using Quaternions for OpenGL Rotations

Ray tracing

Reflection and refraction impossible without recursive ray tracing?
How to handle incorrect index calculation for discretized ray tracing?
Ray Tracer Shadow Problems

Scissor

Scissor Test

Screen space ambient occlusion - SSAO

Antialiasing during depth post-processing for SSAO

Screen Space Local Reflections SSLR

Incorrect tracing with SSLR (Screen Space Local Reflections)
How to scale environment map perspective according to the position of the main camera

Shader

Passing a list of values to fragment shader

Silhouette detection

How to draw inside the black edges in iOS SDK with OpenGL ES?

Stencil

Drawing Filled, Concave Polygons Using the Stencil Buffer

opengl create a depth_stencil texture for reading
OpenGL 16 bit stencil buffers?
Strange bugs occur while using stencil testing
How to use stencil buffer to achieve hierarchical clipping

Tangent space

In a TBN Matrix are the normal, tangent, and bitangent vectors always perpendicular?

Text rendering

What is state-of-the-art for text rendering in OpenGL as of version 4.1?

Texture

Correspondance between texture units and sampler uniforms in opengl
How do opengl texture coordinates work?
Difference between U V and S T texture coordinates
What is, in simple terms, textureGrad()?
OpenGL vertex shader for pinhole camera model
Does it make sense to use own mipmap creation algorithm for OpenGL textures?
Is glTexStorage2D imperative when auto generating mipmaps
How to get texture data using textureID’s in openGL
Will any of the following texture lookups cause undefined behavior, non-uniform flow, or both?

Transparency

Weighted Blended Order-Independent Transparency rendering issues
OpenGL: Transparent texture issue

Triangle strips

How are tripled sequence in IBO working?

Vertex specification

glVertexAttribPointer and glVertexAttribFormat: What’s the difference?
OpenGL: Vertex attribute arrays per primitive?
Drawing multiple triangles in OpenGL

Zoom

How to fix zoom towards mouse routine?