OpenGL-固定管道着色器默认设置(模仿带有着色器的固定管道) [英] OpenGL - Fixed pipeline shader defaults (Mimic fixed pipeline with shaders)

查看:215
本文介绍了OpenGL-固定管道着色器默认设置(模仿带有着色器的固定管道)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以给我提供与固定功能管线相似的着色器吗?

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

我最需要片段着色器"默认值,因为我在网上找到了类似的顶点着色器.但是,如果您有一对应该没问题!

我想使用固定管道,但具有着色器的灵活性,因此我需要类似的着色器,以便能够模仿固定管道的功能.

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.

非常感谢!

我是新来的,所以如果您需要更多信息,请告诉我:D

这就是我要复制的内容:(纹理单位0)

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

  • glTranslatef的功能
  • glColor4f的功能
  • glTexCoord2f的功能
  • glVertex2f的功能
  • glOrtho的功能(我知道它使用着色器在幕后做了一些神奇的事情)

就这样.那就是我想从固定功能管道复制的所有功能.谁能给我展示一个如何使用着色器复制这些东西的示例吗?

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?

推荐答案

此处存在一些问题,这些问题将使使用着色器实现此过程更加困难.

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

首先,除了使用固定功能之外,您还使用即时模式.在过渡到着色器之前,应切换到顶点阵列.您可以编写一个类,该类接受在glBegin (...)glEnd (...)之间出现的类似于即时模式的命令,如果绝对需要以这种方式构造软件,则将它们压入一个顶点数组.

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.

对于glTranslatef (...)glOrtho (...),这些没有什么特别的.他们创建平移矩阵和正交投影矩阵,并以此乘以当前"矩阵.目前尚不清楚您使用的是哪种语言,但是这些功能的一种可能替代方法是使用诸如 glm (C ++).

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.

话虽如此,在OpenGL兼容模式下,GLSL中有保留字表示许多固定功能构造.这些包括诸如gl_MultiTexCoord<N>gl_ModelViewProjectionMatrix等之类的东西.它们可以用作过渡援助,但从长远来看,绝对不应该依靠它.

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.

这篇关于OpenGL-固定管道着色器默认设置(模仿带有着色器的固定管道)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆