Open gl

Discussions related to graphics (2D and 3D), animation and games programming
Ric
Posts: 221
Joined: Tue 17 Apr 2018, 21:03

Open gl

Post by Ric »

Does anyone know in the opengl demo program, where are the shaders stored?
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Richard Russell
Posts: 457
Joined: Tue 18 Jun 2024, 09:32

Re: Open gl

Post by Richard Russell »

Ric wrote: Mon 04 Aug 2025, 17:07 Does anyone know in the opengl demo program, where are the shaders stored?
If you mean opengl.bbc in the examples/graphics/ directory, that uses the old (and deprecated) Fixed Function Pipeline so no shaders are involved (at least, not that are visible in user-mode).

It's the webgllib.bbc library (which despite its name works equally well on desktop and mobile platforms) that uses shaders.
Richard Russell
Posts: 457
Joined: Tue 18 Jun 2024, 09:32

Re: Open gl

Post by Richard Russell »

Ric wrote: Mon 04 Aug 2025, 17:07 Does anyone know in the opengl demo program, where are the shaders stored?
I should add that there are some platforms which support only the Fixed Function Pipeline (for example some older versions of Android) so it's better to use ogllib.bbc if you don't actually need shaders.

If you must use shaders be aware that your program won't work on some platforms which are otherwise supported by BBCSDL. This includes even the newest version of the Amazon Fire TV Stick I think.
Ric
Posts: 221
Joined: Tue 17 Apr 2018, 21:03

Re: Open gl

Post by Ric »

Thanks Richard, I was looking at the opengl.bbc program and that would explain why I couldn't find the shaders. Is there a set of programs like the d3d tutorials for opengl? The webgllib etc are far beyond my capability, small steps are what I need. I have become accustomed to the shaders in d3d with snippets to remove pixels on the alpha channel etc.
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Richard Russell
Posts: 457
Joined: Tue 18 Jun 2024, 09:32

Re: Open gl

Post by Richard Russell »

Ric wrote: Mon 04 Aug 2025, 21:05 The webgllib etc are far beyond my capability,
Perhaps understanding them is, but not using them! You're not expected to understand libraries, you can treat them as 'black boxes'; all you should need in order to use them is the documentation here.

After all that's the entire point of libraries, they hide the complexities of the native APIs by wrapping them in FNs and PROCs, providing an interface familiar to BBC BASIC programmers. In addition, the libraries provide a common interface whether the underlying API is Direct3D or OpenGL.

So if you' want to write 3D programs which run in both BB4W and BBCSDL, using the supplied libraries is the only practical way to achieve that. Otherwise you'd be faced with writing both Direct3D and OpenGL code, doubling the amount of work!

Of course the price you pay for the very simple interface provided by the libraries is a loss of flexibility. They support only the capabilities of the Fixed Function Pipeline, and if that doesn't meet your needs then you're stuck with much more complex approaches such as shaders.
small steps are what I need.
Well, the "small steps" are provided by the supplied example programs. pyramid.bbc is about the simplest possible example of 3D rendering, lighting.bbc adds lighting to the scene, teapot.bbc incorporates specular reflections and so on.
Ric
Posts: 221
Joined: Tue 17 Apr 2018, 21:03

Re: Open gl

Post by Ric »

Thanks for the reply Richard,
I will try to be more specific, it is not opengl passé that I have a problem with, it is how the shaders are loaded and compiled. In d3d it was a separate part of your tutorial and thus easy to follow. In the seascape program for example it is all in data statements and in d3d it is loaded from a file.
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Richard Russell
Posts: 457
Joined: Tue 18 Jun 2024, 09:32

Re: Open gl

Post by Richard Russell »

Ric wrote: Tue 05 Aug 2025, 08:41 it is not opengl that I have a problem with, it is how the shaders are loaded and compiled.
You can find the relevant code for that in both webgllib.bbc and shaderlib.bbc. For example here's an extract from webgllib:

Code: Select all

      REM Create shader objects:
      SYS `glCreateShader`, GL_VERTEX_SHADER, @memhdc% TO oVertex@webgl%
      SYS `glCreateShader`, GL_FRAGMENT_SHADER, @memhdc% TO oFragment@webgl%

      REM Compile shaders:
      PROC_compilewebgl(oVertex@webgl%, vertex$(), "Vertex")
      PROC_compilewebgl(oFragment@webgl%, fragment$(), "Fragment")

      REM Link and use shaders:
      oProgram@webgl% = FN_usewebgl(oVertex@webgl%, oFragment@webgl%)
In the seascape program for example it is all in data statements and in d3d it is loaded from a file.
PROC_compilewebgl() accepts the shader code in a string array, so whether it was originally in DATA statements or a file (or indeed stored directly using BBC BASIC's array initialisation syntax) makes no difference.
Richard Russell
Posts: 457
Joined: Tue 18 Jun 2024, 09:32

Re: Open gl

Post by Richard Russell »

An easy way to customise the shaders, whilst retaining the rest of the code such as manipulating the various matrices needed for rendering, would be to make a copy of webgllib.bbc and change the shader code in that copy. Maybe call it my_webgllib.bbc.
Richard Russell
Posts: 457
Joined: Tue 18 Jun 2024, 09:32

Re: Open gl

Post by Richard Russell »

Ric wrote: Tue 05 Aug 2025, 08:41it is not opengl passé that I have a problem with, it is how the shaders are loaded and compiled.
For my interest, why do you need custom shaders? What capability or capabilities do the built-in shaders in webgllib not have? Do you need a lighting model other than Phong? Or more sources of illumination than the current limit (eight)? Or shadows?

Maybe the capability you need could be added to the standard library, to make your life - and everybody else's - easier.