Jump to content
  • Advertisement
Sign in to follow this  

OpenGL Adding shaders to an existing program

This topic is 2163 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts



I have a very large OpenGL application that doesn't use shaders. We use almost all the non-shader gl functionality in this application. We recently found the need to add some functionality for which we will need to add shaders.


My question: if I add shaders do I have to recreate all the functionality I already have (it's a lot!) just to be able to add one more piece of functionality? It feels almost like rewriting the entire code again. For example, lighting and texturing.



Share this post

Link to post
Share on other sites

With shaders, vertices are not transformed via the model-view-projection matrix, so you will have to manually create one and transform the vertices yourself.

Lighting is not done for you, so you will need to write your own lighting equations and send your own lighting data.

Textures are not applied for you.  You need to sample them manually in the pixel shader.

Fog is not done for you.  You need to write your own equation and send the parameters manually to the shaders.

The list continues.


Basically, unless you already keep copies of all of these parameters (light data, fog data, etc.) (and you should be), you will need to gut a large amount of your existing code to prepare the data for the shaders and then write all the shaders from scratch to replicate any existing functionality needed in addition to the new feature you want to add.

In addition to making a framework for working with shaders in general (compiling them, linking them, applying them, setting uniforms, etc.)


You may need to write your own matrix math routines or get them online.



It may make more sense to re-write an entirely shader-based solution despite the amount of work entailed, but at the end of the day the fixed-function pipeline is universally deprecated for a reason, and from a design/organisation/consistency standpoint the worst-possible case is to have a mix of fixed-function and programmable-pipeline—you may as well join us in the 21st century and go full-on shader-based.



L. Spiro

Share this post

Link to post
Share on other sites



Thanks for your comments. That's exactly what I was afraid of.



On the bright side, once you get the hang of it - it's a fairly easy and standard process for most shaders

and, you'll never want to go back!


All those fancy things you see in all the other games out there are within your grasp smile.png

And there are many many tutorials for getting started with shaders.


Edit: If you get stuck on anything with either creating or loading shaders just write up a post with the specific issue

Edited by Kaptein

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!