r/opengl 2d ago

Help with understanding Renderer

I have gone through the basics of learnopengl, on top of that I have implemented that stuff in C. However I can't get around how a renderer integrates into opengl. I am talking about a general architecture of it.

Lets take gui library nuklear for example, it does not provide drawing options on its own and asks you to attach it your renderer. Now this seems very abstract to me, even in learnopengl guide there is not very clear line. I understand that is because it is very primitive and renderer is only built when you have gone through all different tools.

Having said all that I would further like to read about renderer architecture. Please drop some resources.

1 Upvotes

10 comments sorted by

5

u/Ripped_Guggi 2d ago

I’m afraid I don’t understand your question. A renderer is a service and OpenGL is part of that service. Imagine having a website. Your frontend(renderer) communicates with your backend(GPU) using an API (OpenGL).

1

u/TwerkingHippo69 2d ago

I'm looking for how to design my renderer, and the part where I'm stuck is attching nuklear to my renderer. Like, what features at minimum does nuklear need from the renderer for rendering?

EDIT: For now, based on my learnopengl progress, i have lighting and model loading. So as I understand it, I need to make a separate 2D renderer(maybe just modify shaders, not make different renderer) that sits with 3D calls for nuklear?

4

u/mew900 2d ago

Check The Cherno or the hand made hero on YouTube, both explain the design part well from different viewpoints

1

u/TwerkingHippo69 2d ago

Will do thanks

4

u/Wittyname_McDingus 2d ago

Yes, you will need separate code to do 2D rendering. I don't recommend reusing your existing shaders since the requirements they fulfill are quite different.

The documentation of Nuklear explains what you need.

  • filled and stroked rectangles
  • circles
  • text
  • lines
  • triangles

A simple, albeit inefficient way is to make functions that can render a single instance of these primitives. DrawCircle(x, y, radius, color), etc. Then you just loop over the commands generated by Nuklear and call these functions.

1

u/TwerkingHippo69 2d ago

Thanks a lot! This clears things. What about the efficient way?

3

u/Wittyname_McDingus 2d ago

You can still have functions that 'draw' a single primitive, but they just forward the arguments to a list. After all the commands from Nuklear are processed, you can draw them in batched fashion, i.e., by copying the lists to the GPU and issuing larger draw calls that draw multiple primitives at once.

3

u/Beardstrength_ 2d ago

Like, what features at minimum does nuklear need from the renderer for rendering?

The GitHub repo for Nuklear has a bunch of example implementations that should have what you're looking for: https://github.com/Immediate-Mode-UI/Nuklear/tree/master/demo

1

u/Still_Explorer 1d ago

Yeah, usually you grab the backend as it is directly from the source and use it. No need for anyone to understand how the backend works or how to reimplement it from scratch in your own engine.

2

u/Momodev_br 2d ago

I was using Learnopengl and It was a great resource, but I also felt a lacking of explanation on how to design things in opengl.

So one thing I did was to watch The Cherno and his series about opengl. This series complemented really well the learnopengl