r/opengl • • Mar 07 '15

[META] For discussion about Vulkan please also see /r/vulkan

78 Upvotes

The subreddit /r/vulkan has been created by a member of Khronos for the intent purpose of discussing the Vulkan API. Please consider posting Vulkan related links and discussion to this subreddit. Thank you.


r/opengl • • 12h ago

Calculating the tangent of a sphere

4 Upvotes

Hello everyone hope you have a lovely day

I was following learnopengl pbr chapter and I encountered the code that render the sphere, ofc I want my sphere to be textured, but when The renderSphere function doesn't calculate the tangent and bitangent of the sphere, it calculates it's position, indices and normals and calculate the tangent in the fragment shader.

I decided to calculate the tangent from the cpu side for a better performance and also because I'm working with integrated gpu laptop.

I didn't find so much information after doing some research so I went with the option I don't like tbh, asking Ai about the theory

P = (cos φ sin θ,  cos θ,  sin φ sin θ)
  • Tangent = direction of increasing U, which is ∂P/∂φ: (-sin φ sin θ, 0, cos φ sin θ). This vanishes at the poles because of the sin θ factor, but its direction (-sin φ, 0, cos φ) is still well defined, so drop the factor and use that directly.
  • Bitangent = direction of increasing V, which is ∂P/∂θ: (cos φ cos θ, -sin θ, sin φ cos θ). P = (cos φ sin θ, cos θ, sin φ sin θ) Tangent = direction of increasing U, which is ∂P/∂φ: (-sin φ sin θ, 0, cos φ sin θ). This vanishes at the poles because of the sin θ factor, but its direction (-sin φ, 0, cos φ) is still well defined, so drop the factor and use that directly. Bitangent = direction of increasing V, which is ∂P/∂θ: (cos φ cos θ, -sin θ, sin φ cos θ).

this was the answer so calculating the tangent based on opengl renderSphere function will be this

tangents.emplace_back(glm::vec3(-std::sin(xSegment * 2 * PI), 0, std::cos(xSegment * 2 * PI)));

and this was the result

Tangent result based on ai theory

I don't trust Ai so much I decided to test how learnopengl generate TBN matrix using partial derivative and this was the result

Tangent Based on learnopengl fragment shdaer partial derivative calculation

So Did I calculate the tangent correctly or what? how did you guys overcome that?

Thanks appreciate your help and your time!


r/opengl • • 1d ago

[Android / OpenGL ES 2.0] Offloading 2,000-particle snow physics entirely to a vertex shader (dropping CPU usage from 62% down to ~3%) — how would you optimize this even further?

Post image
1 Upvotes

Hey r/opengl!

I built a transparent holiday snow globe screen overlay for Android using pure EGL14 and GLES20 (zero external dependencies). What started as a 1-hour toy turned into a fun exercise in moving everything off the CPU onto the GPU.

Performance progression (FullHD+ 120Hz):

  • Software Canvas: ~55–62% CPU, 227 MB RAM
  • Hardware Canvas: ~35–41% CPU, 122 MB RAM
  • GLES 2.0 (CPU physics loop): ~6–13% CPU, 97 MB RAM
  • GLES 2.0 (Static VBO + Vertex Shader): 0–3% CPU (0.0% at rest), ~93 MB PSS

Graphics & Shader details:

  • Analytical Vertex Shader Physics: Instead of updating particle positions per frame on the CPU, a GL_STATIC_DRAW VBO stores rest positions, burst vectors, phases, and scale factors. The CPU only passes uTime and uShakeTime uniforms while the vertex shader computes viscous drag deceleration (1.0 - exp(-drag * dt)) / drag, sinusoidal air sway, and screen-edge reflections in parallel.
  • Procedural 4×4 Texture Atlas: At EGL startup, 16 distinct snowflake dendrites and stars are procedurally drawn onto a single 512×512 GL_TEXTURE_2D atlas and immediately freed from system RAM.
  • Zero-Cost Idle: Once particles settle into a snowbank at the bottom edge, the render loop stops completely until an accelerometer shake event triggers a new burst.

Source code, shader implementation, and ADB profiling scripts: github.com/AVakhrin/snowglobe

Question for the community: Looking at the shader math, VBO layout, or mobile GLES 2.0 pipeline — how would you optimize this process even further (e.g., reducing overdraw/blending cost, precision qualifiers, or GL_POINTS vs instanced rendering)?


r/opengl • • 1d ago

gl_DrawID as SSBO array index produces incorrect results.

4 Upvotes

Hey everyone,

I'm working on some OpenGL code that is producing strange results and I'm starting to wonder if it's a driver bug. I'm trying to render line segments with two SSBOs, one containing line parameters (e.g. color, width, base_point) and one containing the points of all the line segments I want to render. I'm trying to do this using glMultiDrawArrays since segments can have a different number of points which I can control with the count parameter. In the shader I use gl_DrawID as an index to get the line parameters and a combination of base_point (from the line parameters) and gl_VertexID as an index to get the segment point.

The problem is that when I hit ~60 draw calls, the output is not what I expect. I'm trying to render a grid using line segments and the first 59 lines are correct but after that the behavior is unpredictable. Sometimes they seem to overlap existing lines or just draw in the incorrect place.

I'm not sure how clear this will be but I've attached screenshots of the RenderDoc output for draw calls 58, 59, and 60. Between 58 and 59 you can see an extra grid line being added at the correct spacing but for draw call 60 the line is in the incorrect place. The weird thing is RenderDoc shows the correct gl_Position for these different draw calls (i.e. the MeshViewer shows the line segment in the correct VS Out location) but the actual output in the framebuffer is not right. I've also tried debugging by using gl_DrawID as an increasing color parameter and everything looks right in RenderDoc.

Additionally, if I switch to using glDrawArraysInstanced and index in the SSBOs using gl_InstanceID, everything works correctly. Note that I would prefer to use a multi draw since instancing requires that each line segment have the same number of points (which is true for this grid but not true for what I want to do generally).

Anyone have any ideas? Anything else I can provide to help debug? I'm wondering if it's a driver bug because this problem only happens on my Linux laptop but works fine on my Windows desktop. Thanks!

Draw call 58
Draw call 59
Draw call 60

r/opengl • • 2d ago

Fragmentshader-raycaster renders from quite a few years ago

Thumbnail gallery
57 Upvotes

Heyo!

Searched through my USB-sticks to find a fragmentshader-raycaster I made like at the end of the 2010s. The actual version, I was looking for, is nowhere to be found though, which likely means, it is (or was) on that one SSD, that seems bricked and refuses to boot, or do anything at all. ..Apparently SSDs can get damaged by laying around..

But not much is lost, iirc.

Those images are from different earlier versions, rendered just yesterday.

Those are mostly tests of different techniques - the usual suspects, like texture-materials, bump-maps, reflections (ofc), different shadows, fog, or blur.

And it was a whole lot of fun programming this by hand!

Lastly I'd like to ask: Which image causes brain-tickling the most to you?

Cheers


r/opengl • • 2d ago

Built a parametric V8 engine assembly inside a custom C++20 + OpenGL CAD/physics engine I wrote from scratch — runs offline on an Intel UHD iGPU

21 Upvotes

r/opengl • • 2d ago

using fragment shader as compute shader in GLES 2

1 Upvotes

This is just a concept I wanted to share and possibly receive feedback on. I have this idea to calculate rotations of things by passing a texture specifying the current animation frame, initial position, and rotation limits of each thing.

#version 100
precision float mediump;
uniform sampler2D RotHints;
varying mediump Coords;
void main(){
vec4 Hints = texture2D(RotHints,Coords);
Hints.g=Hints.g-Hints.b;
Hints.a=Hints.g*Hints.r+Hints.a;
gl_FragColor = Hints.a;
}

r/opengl • • 2d ago

Am I a fraud for using AI boilerplate code?

0 Upvotes

I had tried the learnopengl tutorials about a year ago and the reason i got fed up was the build process with CMake. Is it bad that I asked claude to generate me all the CMake boilerplate? It also made me a GLFW window wrapper. Should I start over? I just needed to build on mac and windows so I can code when I’m not home at my PC.


r/opengl • • 2d ago

Building an interactive 2D surveillance map with PyOpenGL, live video textures and dynamic camera visibility

1 Upvotes

r/opengl • • 3d ago

Cigarette game (WIP)

45 Upvotes

r/opengl • • 4d ago

How hard is it actually to get that initial rainbow triangle?

4 Upvotes

i know literally nothing about graphics programming, im a game dev and im honestly considering learning c++

how long does it take to get that rainbow triangle?

is getting the triangle a beginner c++ thing or a intermediate thing?

how much harder is it to do in vulkan?


r/opengl • • 5d ago

Nueva version de Open3d Game engine

34 Upvotes

Open3d es un motor de juegos para linux con opengl hecho en c++ open3d incluye lenguaje propio

codigo fuente en: https://github.com/ciroparada81-boop/Open3D-game-engine.git


r/opengl • • 6d ago

Started Learning OpenGL

314 Upvotes

I started Learning OpenGL recently. I took me so goddam time to just make a triangle and I don't even remember why I stared this. Oh, I remember. To make a Boids simulation. Yeah, learning OpenGL, just to make a Boids simulation. Now, you may wondering, is this guy stupid? yes. And very delusional. This is basically the story of every project I ever stared.
Okay, I know there are much more simpler ways to make a Boids simulation. But what if I want to make lots of boids. I mean a lot.
And the next question is, Why you need boids? Idk. I will think about it after I made it. Wish me luck.

Any advice?


r/opengl • • 8d ago

OpenGL vs Vulkan: Which API Is Better for Gaming?

Thumbnail codexdeal.com
0 Upvotes

r/opengl • • 10d ago

New video tutorial: Row Major VS Column Major

Thumbnail youtu.be
5 Upvotes

r/opengl • • 11d ago

4k balls, single threaded

Thumbnail youtu.be
8 Upvotes

r/opengl • • 12d ago

Physics Programming Part 5: Spring Physics

Thumbnail youtu.be
9 Upvotes

I explain the mathematics underpinning spring mechanics then implement a solution in C++ using a net as an example. Implementation begins at 10:05. Feedback is welcome.


r/opengl • • 12d ago

Newbie here, studying open gl and shaders. I have to make *something* in a couple of weeks. I was thinking a cloud with different light scenarios, but I'd love some suggestions for starter projects!

Thumbnail reddit.com
2 Upvotes

r/opengl • • 13d ago

I did my first triangle, what now?

17 Upvotes

Yes, I created an orange and horrible triangle but what now? I didn't understand anything! I'm so confuse. Yes maybe I did understand some basics basics things but if you ask me to create a triangle with no tutorials I will stop at declaring the VBO and VAO!

I saw people creating games, the universe, AI robots in OpenGL and I? A stupid triangle did with a tutorial 😭.


r/opengl • • 13d ago

Rendering text through ImGui?

2 Upvotes

I'm hoping to get a basic repl running with ImGui, OpenGL, and GLFW. I'm comfortable with GLfW and OpenGL rendering but not the ImGui portion.

My question is, can I use the OpenGL context and the GLFW window and then get basic text editing functionality with just ImGui? No opengl buffers, no custom shaders. I think the opengl context needs a default vertex and fragment shader to function but I'm looking to keep that very minimal and handle basic repl input and text rendering between imgui::begin() and imgui::end(). A basic per keypress render loop where each GLFW key event updates a string and then ImGui renders a new frame for the window. I haven't worked with ImGui before. Do you think this is possible?


r/opengl • • 14d ago

Interactive Video Feature Is Now Available

37 Upvotes

Get your lifetime engine for just $39.
Enjoy lifetime access to multiple systems with powerful features that make it stand out from other engines.
Discover its unique capabilities, explore its advantages, and learn what makes it different from other engines. Compare the features and see the difference for yourself.
Explore the documentation to learn more about all available features and system

https://documents.nexiorgame.workers.dev/


r/opengl • • 14d ago

SimpleX Engine Development (Continued)

5 Upvotes

I originally had a string of posts with various other reddit communities regarding game and game engine development and finally felt confident enough to post to this community! I went dark in my development logging/blogging(?) for awhile due to lifestyle responsibilities taking precedance over developing an engine or at least at the moment what is considered heavy boilerplate engine development.

Current development components/systems:

Three graphics backends - DirectX 11, DirectX 12, and OpenGL (WGL on Windows, GLX on Linux) behind an IRenderer interface. Vulkan is scaffolded but not implemented yet. Shadow maps, cubemaps, bloom, IBL/irradiance convolution, and instancing are supported at the moment.

HLSL as single source of truth compiling offline via DXC to DXBX/DXIL/SIPR-V with SIPRV-Cross transpiling to GLSL for the GL backend. Compiled byte code is also cached on disk and keyed by source hash as filename.

Three windowing backends - Win32, GLFW, and SDL3, with a fallback chain. Win32 is default for Windows and GLFW is default for Linux, but will fallback to GLFW and if GLFW fails fallback to SDL3; if DX fails on any window type under Windows platform fallback to OpenGL (if Vulkan would work with me DX would fallback to Vulkan then back to OpenGL) - similar results would also occur for Linux if Vulkan failed fallback to OpenGL but that requires Vulkan to be developed and not be a stub at the moment...

Fiber-based Job System - Win32 fibers and Linux ucontext behind one class - a worker thread has a dedicated dispatcher fiber that never runs job code, so fibers are pooled to switch back rather than to each other - no fiber needs to know any other fiber's state.

I went with no cross-thread fiber migration in my first attempt - less load-balancing from the inspirational full Naughty Dog design, but it buys a genuinely nice property: since a job's whole execution stays pinned to one thread, a pool allocator allocates inside a job function automatically thread-safe with zero sync.

Custom allocators - arena, pool, and a frame allocator with N rotating arenas.

BC texture compression with no on-disk cache - BC1 for opaque color, BC3 for color with alpha, and BC5 for normal maps.

TLDR; I've tested the boilerplate logic against the Sponza Palace model from Intel's site GPU Research Samples (https://www.intel.com/content/www/us/en/developer/topic-technology/graphics-research/samples.html) with the Colorful Curtains and Ivy extensions at 4K texture resolutions. The original load time took around 5.5 minutes (unbearable to test shader changes and object additions to the scene), but I cut it down to 4.6 seconds after texture compression, precompiled shader code, and submesh merging. The model (as an \.obj - I haven't implemented third-party vendor model software to utilize every model type just yet...) is 995MB on disk with nearly 2730MB of textures (4K per texture for the conjoining material \.mtl file) after texture compression all textures were compressed to 501MB on disk which originally took 933ms average to load cutting down to 259ms average.

Edit: grammar and spelling.

Edit 2: I've recently decided to rebuild what I later found out was more of a rendering framework into an actual engine. I haven't yet begun developing beyond an Application, Runtime, and Core module of an engine (each is self explanatory besides core being a mix of low level utilities and core engine components: reworked the threading and fibers for Linux using pThreads)


r/opengl • • 15d ago

New update 1.1Day and night mode

43 Upvotes

More improvements are coming to the engine!
Want to try it out? Join our Discord through the link below and get a free, limited-time trial version, along with full documentation.
Explore the features, test the engine, and see how it works before making a purchase.
Get your free trial before the offer ends!

https://discord.gg/Ts6MTVeAt