开发者

Where do shaders fit in with the older methods of rendering in OpenGL?

开发者 https://www.devze.com 2023-04-10 11:02 出处:网络
I have written a level renderer in OpenGL following many online tutorials. I actually render with vertex arrays and the开发者_StackOverflow中文版 range draw command. Now because I want to have the lev

I have written a level renderer in OpenGL following many online tutorials. I actually render with vertex arrays and the开发者_StackOverflow中文版 range draw command. Now because I want to have the level lit with per pixel lighting, I realize shaders are a huge part if not the main part of OpenGL at this point.

So here I am with my "traditional" method of rendering without shaders and I want to know how shaders fit into the grand sceme of things. Will my main rendering function actually be done with shaders if I rework it to utilize the latest capabilities of OpenGL? Can I leave the rendering in code and just use shaders for lighting?

I want to do this correctly, not fast so I am going to continue reading through OpenGL Superbible and learning as I go.

Can anyone educate me as to how everything fits in and if these old tutorials online like Nehe and gametutorials are actually still applicable.


Using fixed function OpenGL coarsely follows those steps:

  • Setting projection matrix
  • Setting modelview matrix
  • Set lighting parameters
  • Bind textures to texture units
  • Define texture environment operations
  • Setting up geometry (Vertex Arrays / Vertex Buffer Objects)
  • Issue draw commands

It are the first 5 steps that differ, when using shaders. Shaders replace the fixed function pipeline, which is controlled by the settings done there. First and formost you must supply shaders that implement the vertex transformation and fragment generation. Those shaders take their parameters as so called Uniforms.

You still work with matrices, only this time you deliver them to OpenGL through uniforms instead the matrix stack (in OpengGL-2 and OpenGL-3 compatibility profile the matrix stack is still there and the matrices put into builtin uniforms).

Textures still bound to texture units. Using sampler uniforms texture units are passed into fragment generation. The whole texture environment has been replaced by fragment shaders. And frankly: Setting up a fragment shader is much easier than fiddling with a dozen of calls to glTexEnvi.

Lighting happens through shaders, so you pass lighting parameters as uniforms and do the calculations in the shaders.

The drawing commands though remain the same.

Will my main rendering function actually be done with shaders

If by that you mean, if the shader will do the drawing calls: No! Actually it is not so hard to lift an old OpenGL-1.1 renderer that doesn't make use of Display Lists, Selection Mode and Immediate Mode, to OpenGL-3 core. (If Display Lists, Selection Mode and Immediate Mode are involved though…)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号