Questions tagged [opengl]

OpenGL (Open Graphics Library) is a graphics standard and API which is platform-independent and available for desktop, workstation and mobile devices. It is designed to provide hardware-accelerated rendering, and hence gives greatly improved performance over traditional software rendering. OpenGL is used for applications like CAD software and computer games. The OpenGL standard, as well as OpenGL ES, is controlled by the Khronos group.

Filter by
Sorted by
Tagged with
67
votes
6answers
45k views

How can I debug GLSL shaders?

When writing non-trivial shaders (just as when writing any other piece of non-trivial code), people make mistakes.[citation needed] However, I can't just debug it like any other code - you can't just ...
62
votes
9answers
42k views

Should new graphics programmers be learning Vulkan instead of OpenGL?

From the wiki: "the Vulkan API was initially referred to as the 'next generation OpenGL initiative' by Khrono", and that it is "a grounds-up redesign effort to unify OpenGL and OpenGL ES into one ...
26
votes
1answer
8k views

What does "st" mean in the context of OpenGL?

I've seen the term st come up a few times when looking at other OpenGL fragment shaders. However, I don't know what it stands for or what it's used for. Here's an ...
23
votes
2answers
15k views

What is fwidth and how does it work?

The OpenGL documentation states that fwidth returns the sum of the absolute value of derivatives in x and y. What does this mean in less mathematical terms, and is ...
22
votes
2answers
27k views

GLSL. Can someone explain why gl_FragCoord.xy / screenSize is performed and for what reason?

I'm new to shaders and know that you can color pixels with gl_FragColor but sometimes there is this thing: ...
17
votes
3answers
6k views

How can I debug what is being rendered to a Frame Buffer Object in OpenGL?

I have a point cloud that is being rendered to the screen. Each point has its position and color as well as an ID. I was asked to render the IDs for each point to a texture so I created a FBO and ...
17
votes
1answer
2k views

Is there any way to generate primitives in a geometry shader without any input geometry?

A few years ago I tried to implement this GPU Gem in OpenGL to generate 3D procedural terrain using Marching Cubes. The article suggests to implement Marching Cubes in a geometry shader to maximum ...
16
votes
2answers
13k views

GL_STATIC_DRAW vs GL_DYNAMIC_DRAW vs GL_STREAM_DRAW: does it matter?

In OpenGL the buffer object functions (glBufferData, glBufferSubData, and probably a few others) have a parameter ...
16
votes
2answers
12k views

How to implement a trackball in OpenGL?

After so much reading about transformations it is time to implement a trackball for my app. I understand I have to create a vector from the origin to where the mouse is clicked and then another from ...
15
votes
1answer
4k views

What does "makeContextCurrent" do exactly?

I am pretty confused about that function. GLFW Context reference says as follow: This function makes the OpenGL or OpenGL ES context of the specified window current on the calling thread. A ...
14
votes
3answers
5k views

What are some methods to render transparency in OpenGL

Alpha blending can be turned on to make surfaces transparent, like so: ...
14
votes
1answer
2k views

OpenGL compatibility, naming conventions and ARB vs EXT

I thought I had formed a general understanding of how OpenGL naming conventions and extensions worked, until I stumbled upon a case that confused me. Here's my understanding so far: No suffix -- e.g....
13
votes
2answers
9k views

Cause of shadow acne

I know how shadow mapping works but I am not getting the cause of shadow acne! Can anyone tell me cause of shadow acne in a simple way and how is it related to depth map resolution?
13
votes
1answer
2k views

When to disable perspective correct interpolation ( noperspective )

In GLSL, perspective correct interpolation of vertex attributes is the default setting - one can disable it for specific vertex attributes by using the noperspective qualifier. Other than in post-...
13
votes
1answer
3k views

Synchronizing successive OpenGL Compute Shader invocations

I have a couple of compute shaders that need to be executed in a certain order and whose outputs depend on previous inputs. Ideally, I'll never need to copy a buffer client-side and do all of my work ...
13
votes
1answer
4k views

Do I need to rebind uniforms or attributes when changing shader programs?

Rendering the scene usually involves more than one shader program which, in my case, all use the same attributes and share at least some of the uniforms. To have them working properly, I currently ...
13
votes
1answer
5k views

Loop performance in a shader

I am wondering what's the best way to integrate a dynamic loop function in a shader? First, it seems that dynamic arrays are not possible. So, is it better to create a maximum size array and only ...
12
votes
2answers
8k views

OpenGL - Detection of edges

I'd like to load arbitrary meshes and draw thick black lines along the edges to get a toon-shading like look. I managed to draw a black silhouette around the objects by using the stencil buffer. You ...
12
votes
2answers
3k views

Derivative maps vs. Tangent Space Normal maps

I discovered that some engines use derivative maps instead of tangent space normal maps. After some reading, it seems to be a really awesome way to replace tangent space normals but are there some ...
11
votes
2answers
748 views

Is it possible to find out how many fragments made it through the stencil test?

I have an OpenGL application which uses stencil tests quite extensively to render irregular shapes (a bit like a simple 2-D CSG). If I could find out how many fragments passed the stencil test and ...
11
votes
1answer
709 views

Is modifying a texture (painting on it) considered a "state change"?

The convention in graphics is that performing fewer state changes is better than performing more state changes (switching shaders, binding buffers, binding textures, etc.). For textures, it is faster ...
11
votes
1answer
970 views

Why do adjacent triangles never overlap when rasterized?

Apologies for the following noob question, it's just I can't find a satisfactory answer anywhere... When I render a simple axis-aligned quad made up of two triangles, I don't understand why there's ...
11
votes
2answers
37k views

Is there any reason to prefer Direct3D over OpenGL?

So I was reading this, I sort of got the reason why there are a lot more games on Microsoft windows than on any other OS. The main issue presented was that Direct3D is preferred over OpenGL. What I ...
11
votes
1answer
15k views

OpenGL GLSL - Sobel Edge Detection Filter

With respect to this topic I've successfully implemented the Sobel Edge Detection filter in GLSL. Here is the fragment shader code of the filter: ...
10
votes
3answers
4k views

How to do texturing with OpenGL direct state access?

How do you use textures with direct state access in OpenGL? I have the following in my code, which seems to work: ...
10
votes
4answers
2k views

Does it matter whether I learn OpenGL or Direct3D?

Are the differences between these two APIs minor implementation details that mean once I have learned one I can use it for everything? Or are there reasons for learning one rather than the other if I ...
10
votes
1answer
2k views

What is the modern equivalent of display lists?

Display lists were an OpenGL feature that could, in theory, accelerate any part of the API by storing a group of commands for later use. In my understanding, this makes a lot of sense with regards to ...
10
votes
1answer
257 views

Do the alignement and declaration order of uniforms matter?

In the section 6.4 Constant Buffers of the book Practical Rendering & Computation with Direct3D 11 (pages 325, 326) it is mentioned: By default, the HLSL compiler will attempt to align ...
9
votes
4answers
11k views

Multiple viewports with modern OpenGL?

I use SDL2. Currently my only shader has a MVP matrix, and transforms the points with it. I calculate my View and Projection matrix for a camera with GLM: ...
9
votes
1answer
2k views

Is it good practice to use all the available texture units?

When applying multiple textures to a mesh, like for bump-mapping, I usually bind the textures to the first few fixed texture units, e.g.: diffuse = unit 0, bump = unit 1, specular = unit 2, then keep ...
9
votes
1answer
3k views

OpenGL specular shading - Gradient banding issues

I use Phong shading as my lighting model. Nevertheless, the specular shading produces gradients in the light cone: Hopefully you can see the gradient starting from the lower left corner expanding ...
9
votes
1answer
3k views

Screen capture of game video

I'd like to "hook" into a running game, say Mario Bros, and capture each frame rendered... saving that frame to an image file. A good example of something similar is FRAPS. --Note: I don't want to ...
9
votes
1answer
447 views

What are sample gaps during scan conversion?

In this tutorial, It is very often the case that triangles are rendered that share edges. OpenGL offers a guarantee that, so long as the shared edge vertex positions are identical, there will be no ...
9
votes
2answers
7k views

Why do I need to inverse the orientation matrix of a camera to be able to translate it in the direction it is facing?

I've been going over some OpenGL learning resources and one of them is this article: Modern OpenGL 04 - Cameras, Vectors & Input in which the author presents an approach to building a ...
9
votes
1answer
530 views

Creating shared vertex normals on GPU

I've mostly succeeded at porting an implementation of Marching Cubes from CPU over to OpenGL compute shaders, but I haven't tackled normals yet and wondering the best way to go about it. My ...
9
votes
1answer
1k views

Optimal memory access when using lookup tables on GPU?

I'm exploring isosurface algorithms on GPU for a bachelor's project (specifically concentrating on just binary in/out voxel data rather than real-valued fields). So I have a CPU implementation of good ...
9
votes
1answer
1k views

Is it possible to alpha blend multiple render targets using a specified alpha?

Say I have render targets 0 through N and RT 0 happens to have in its fourth component an alpha channel specified by a material or mask or something. Is it possible to have the hardware compositor ...
9
votes
1answer
216 views

Per Vertex Computation in OpenGL Tesselation

I try to implement a position based cloth simulation using hardware tesselation. This means I want to just upload a control quad to the graphics card and then use tesselation and geometry shading to ...
9
votes
2answers
689 views

How to unproject quadrilateral into rectangle?

tl;dr: Math problem in projective geometry: How does one find some 4x4 camera matrix that gives a projection as illustrated below, such that points A,B,C,D are somewhere on the edges of the unit box (...
8
votes
1answer
9k views

How to use GLSL texelFetch?

I have read the OpenGl documentation of texelFetch, which is: gvec4 texelFetch(gsampler2D sampler, ivec2 P, int lod). I know the first argument "sampler" is just a texture. But I am very confused ...
8
votes
2answers
242 views

When is it better to upload partial model matrices to the vertex shader?

As of now, when rendering my scene and while iterating through the scene graph, for each node its model matrix is calculated from the parent's model matrix and the scene node's pose. This is quite ...
8
votes
2answers
801 views

Help me grasp Anisotropic Filtering (AF)

Lately I've been reading about texture filtering, namely Nearest-neighbor filtering, Bilinear filtering, Trilinear filtering, Anisotropic filtering, MIP maps, RIP Maps and so on. From a high-level ...
8
votes
1answer
1k views

Shadow Mapping artefacts

I've been playing around with shadow mapping in OpenGL using depth textures. The depth texture is fine and I can map it onto the scene but I have some strange artefacts on the back of the object: My ...
8
votes
1answer
676 views

Why different result when change input order in GL_LINES?

Code: ...
8
votes
1answer
2k views

Are draw calls executed in parallel or sequentially or both?

This a follow up for a question I answered on GameDev SE. The question was simply Is glDrawArraysInstanced in OpenGL parallel when drawing those instances? My answer was in the lines of "the GPU ...
8
votes
1answer
1k views

How much precision (half, float, double, etc) is enough for a Color class?

While doing some reading on how real-time applications handle color under OpneGL, I noticed that some examples implemented Color as a collection of 4 floats, while ...
8
votes
1answer
473 views

Rendering fog underneath water

I'm aware of glFog, which blends between the fog and surface colour based on distance to the camera, like this: The equations are even given in the docs. But the fog is applied immediately in front ...
8
votes
1answer
1k views

Writing to a compressed texture using a compute shader, with no extra copies

I'm trying to figure out what the best way is to generate an OpenGL texture using a compute shader. So far, I've read that pixel buffer objects are good for non-blocking CPU -> GPU transfers, and that ...
8
votes
2answers
1k views

What is a good approach for handling uniforms in modern OpenGL?

I'm creating a renderer using modern OpenGL (3.1 and up) and now I'm trying to create an efficient but flexible way of handling uniforms. I've been reading up on uniform buffer objects and on what a '...
7
votes
3answers
9k views

Dynamic Array in GLSL

Is it possible to have a dynamic array in a GLSL shader? For instance, what if I have something like this in my GLSL Shader: ...

1
2 3 4 5
13