opengl 如何显示纹理使用着色器,为什么我的方式不工作?

dhxwm5r4  于 2022-11-04  发布在  其他
关注(0)|答案(1)|浏览(150)

当我启用着色器程序时,纹理不起作用

  • A_andrew是别名中的纹理(|在纹理2D中)*别名为别名(纹理2D)

CSharp代码

GL.ClearColor(255, 255, 255, 255);
GL.Clear(ClearBufferMask.DepthBufferBit);

A_andrew.Bind();
//shaderProgram.Use(); when enabled texture are disapeare
shaderProgram.GetUniform("texture0").SetVec1(alias.id);

GL.Begin(BeginMode.Quads);
AliasTexture2D tex = Draw.CurrentTexutre;

GL.TexCoord2(tex.GetLeftBottom());
GL.Vertex2(-0.6f, -0.4f);

GL.TexCoord2(tex.GetRightBottom()); 
GL.Vertex2(0.6f, -0.4f);

GL.TexCoord2(tex.GetRightTop()); 
GL.Vertex2(0.6f, 0.4f);

GL.TexCoord2(tex.GetLeftTop()); 
GL.Vertex2(-0.6f, 0.4f);

GL.End();
window.SwapBuffers();

片段着色器

version 330 core
in vec2 texCords;

uniform sampler2D texture0;

out vec4 color;

void main()
{
    vec4 texColor = texture(texture0, texCords);
    color = texColor;
}

顶点着色器

version 330 core
layout (location = 0) in vec3 inPosition;
layout (location = 1) in vec2 inTexCords;

out vec2 texCords;

void main()
{
    texCords = inTexCords;
    gl_Position = vec4(inPosition.xyz, 1.0);
}

我认为碎片着色器中的问题,他无法获得纹理或|和纹理坐标

sd2nnvve

sd2nnvve1#

不能将固定函数属性与固定函数矩阵堆栈与3.30版着色器程序混合使用。
必须使用内置属性,如gl_Vertexgl_MultiTexCoord0(请参见顶点属性)。
你必须使用内置的统一变量,如gl_ModelViewProjectionMatrix。在传统的OpenGL(GLSL 1.20)中提供了内置的统一变量。请参阅OpenGL着色语言1.20规范; 7.5内置统一状态。
其中一个是mat4类型的gl_ModelViewProjectionMatrix,它提供了由模型视图和投影矩阵的变换,模型视图和投影矩阵中还存在分离的变量gl_ModelViewMatrixgl_ProjectionMatrix
顶点着色器:

version 120

varying vec2 texCords;

void main()
{
    texCords = gl_MultiTexCoord0.xy;
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}

相关问题