我有一个 Sampler2D 数组,如下所示:
uniform sampler2D u_Textures[2];。我希望能够在同一个绘图调用中渲染更多纹理(在本例中为 2 个)。在我的片段着色器中,如果我将颜色输出值设置为红色之类的值,它确实会向我显示 2 个红色方块,让我相信我在绑定纹理时做错了什么。我的代码:
Texture tex1("Texture/lin.png");
tex1.Bind(0);
Texture tex2("Texture/font8.png");
tex2.Bind(1);
auto loc = glGetUniformLocation(sh.getRendererID(), "u_Textures");
GLint samplers[2] = { 0, 1 };
glUniform1iv(loc, 2, samplers);
Run Code Online (Sandbox Code Playgroud)
void Texture::Bind(unsigned int slot) const {
glActiveTexture(slot + GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_RendererID);
}
Run Code Online (Sandbox Code Playgroud)
这是我的片段着色器:
#version 450 core
layout(location = 0) out vec4 color;
in vec2 v_TexCoord;
in float v_texIndex;
uniform sampler2D u_Textures[2];
void main()
{
int index = int(v_texIndex);
vec4 texColor = texture(u_Textures[index], v_TexCoord);
if (texColor.a == 0.0) { …Run Code Online (Sandbox Code Playgroud) 我正在制作一个 C++ 问题,我必须编写一个带有列表的函数。问题是我根本不理解列表,因为我不知道如何使用指针或迭代器。有什么方法可以将所有元素从该列表移动到数组或向量吗?这会让我的生活更轻松。