c++ - 如何将片段着色器仅应用于 OpenGL 中的一个对象?

标签 c++ opengl

我刚刚开始学习 OpenGL。在我看过的所有教程中,它们都演示了如何使用片段着色器来设置 View 中所有对象的颜色。我还没有发现的是如何在其中一个对象上使用片段着色器,为不同的对象赋予不同的颜色。你是怎么做到的?

为了提供问题的背景,我在二维中绘制了一个带有房屋和道路的简单场景。我发现了如何使用固定图形管道设置我的每个对象(房子的主体、 window 等)的颜色,我只是不明白如何使用片段着色器设置颜色。

如有任何澄清,包括我误解之处的更正,我们将不胜感激。

最佳答案

To provide background to the question, I'm drawing a simple scene with a house and a road in 2d. I have discovered how to set the colors of each of my objects (the main body of the house, the window, etc) using the fixed graphics pipeline, I just don't understand how to set the colors using fragment shaders.

As RobertRouhani said , 使颜色统一并为每个对象更改它。


How to apply a fragment shader to only one object in OpenGL?

您可以使用 glUseProgram 简单地更改着色器程序,并在它将使用不同的着色器后进行渲染调用。

看这个:https://gamedev.stackexchange.com/questions/22216/using-multiple-shaders

关于c++ - 如何将片段着色器仅应用于 OpenGL 中的一个对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13244450/

相关文章:

c++ - 有什么方法可以在运行时不间断地动态更新二进制文件(可执行文件)?

c++ - Qt SQL 线程数据库查询

opengl - OpenGL/GLSL 中的术语 "genType"是什么意思?

c++ - 多维数据集未显示为多维数据集

c++ - fread/fwrite 引入垃圾值

c++ - IHTMLDocument2::write() 的问题

c++ - Windows/C++ : why are loaded module memory bytes changing at run-time?

c++ - OpenGL,具有正交投影的几何着色器

OpenGL:3d 网格和法线的三角形条问题

c++ - Error1 错误 LNK1107 : invalid or corrupt file: cannot read at 0x2B0