OpenGL - Fixed pipeline shader defaults (Mimic fixed pipeline with shaders)

梦想的初衷 提交于 2019-12-07 08:59:04

问题


Can anyone provide me the shader that are similar to the Fixed function Pipeline?

I need the Fragment shader default the most, because I found a similar vertex shader online. But if you have a pair that should be fine!

I want to use fixed pipeline, but have the flexability of shaders, so I need similar shaders so I'll be able to mimic the functionality of the fixed pipeline.

Thank you very much!

I'm new here so if you need more information tell me:D

This is what I would like to replicate: (texture unit 0)

  • functionality of glTranslatef
  • functionality of glColor4f
  • functionality of glTexCoord2f
  • functionality of glVertex2f
  • functionality of glOrtho (I know it does some magic stuff behind the scenes with the shader)

Thats it. That is all the functionality I would like to replicate form the fixed function pipeline. Can anyone show me an example of how to replicate those things with shaders?


回答1:


You have a couple of issues here that will make implementing this using shaders more difficult.

First and foremost, in addition to using fixed-function features you are also using immediate mode. Before you can make the transition to shaders, you should switch to vertex arrays. You could write a class that takes immediate mode-like commands that would come between glBegin (...) and glEnd (...) and pushes them into a vertex array if you absolutely need to structure your software this way.

As for glTranslatef (...) and glOrtho (...) these are nothing particularly special. They create translation matrices and orthographic projection matrices and multiply the "current" matrix by this. It is unclear what language you are using, but one possible replacement for these functions could come from using a library like glm (C++).

The biggest obstacle will be getting rid of the "current" state mentality that comes with thinking in terms of the fixed-function pipeline. With shaders you have full control over just about every state, and you don't have to use functions that multiply the "current" matrix or set the "current" color. You can simply pass the exact matrix or color value that you need to your shader. This is an altogether better way of approaching these problems, and is why I honestly think you should ditch the fixed-function approach altogether instead of trying to emulate it.

This is why your desire to "use the fixed-function pipeline but have the flexibility of shaders" fundamentally makes very little sense.

Having said all that, in OpenGL compatibility mode, there are reserved words in GLSL that refer to many of the fixed-function constructs. These include things like gl_MultiTexCoord<N>, gl_ModelViewProjectionMatrix, etc. They can be used as a transitional aid, but really should not be relied upon in the long run.




回答2:


Se also this question: OpenGL Fixed function shader implementation where they point to a few web resources.


The OpenGL ES 2 book contains an implementation of the OpenGL ES 1.1 fixed function pipeline in Chapter 8 (vertex shader) and Chapter 10 (fragment shader).

Unfortunately, these shaders seem to not be included in the book's sample code. On the other hand, reading the book and typing the code is certainly worthwile.



来源:https://stackoverflow.com/questions/18806175/opengl-fixed-pipeline-shader-defaults-mimic-fixed-pipeline-with-shaders

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!