OpenGL Shader like effects in Bmax - without glsl

BlitzMax Forums/BlitzMax Programming/OpenGL Shader like effects in Bmax - without glsl

juankprada(Posted 2014) [#1]
Hi all.

I am looking for effective ways to implement shader like effects in bmax without relying on opengl glsl as right now it doesn't work with the 2D functions bmax provides.

How would you do such things with just bmax?

Thanks


Kryzon(Posted 2014) [#2]
If I were in your place I would just look into implementing shaders with Max2D as it is.
To manage shader programs you use specific API calls, so in the end you could add a SetShader( shader ) function that work in a similar way to SetBlend, SetScale etc. that are called just before drawing an image.
This shouldn't require the modification of any native module code, you can add it as an extension.

Note that you'll need a lot of new functions, which would handle the creation of a shader program from a source file, the retrieval of uniform locations etc.

You learn all of this when you study graphics programming with GLSL and HLSL. The material for this can be found around the web.


juankprada(Posted 2014) [#3]
Please correct me if I am wrong. But I dont think it is possible to use shaders in the Fixed Function Pipeline in OpenGL which is the one used by Max2D. I would have to relay on Vertex array objects or Bertex buffer objects.

Thanks


AdamStrange(Posted 2014) [#4]
in theory it would be possible as Max2d is using opengl as the renderer (on a mac)

You would need to reverse engineer the flip command and insert the shaders at this stage


Kryzon(Posted 2014) [#5]
Please correct me if I am wrong. But I dont think it is possible to use shaders in the Fixed Function Pipeline in OpenGL which is the one used by Max2D. I would have to relay on Vertex array objects or Bertex buffer objects.

With OpenGL (GLMax2DDriver), Max2D makes state changes that are required for either the fixed function or the programmable pipelines: setting matrices, textures and rendering geometry. The same can be said of the Direct3D 9 driver (D3D9Max2DDriver).
This is why I said it would be easy to add pixel shader support with an "extension" function such as a "SetShader" function used in the same manner as SetAlpha, SetScale etc. before rendering.

From what I have read of the Max2D driver sources, to add shaders you would only need to 'add' some more code - you wouldn't have to change the existing code.

However, not all systems support shaders. Some of the older systems may not have this capability. Therefore you can safely include the shader functions in Max2D, but you can only call them if you test the system for shader support first, or else your game\application will crash.