如何显示使用着色器的纹理以及为什么我的方法不起作用?

发布于 2025-01-17 04:56:20 字数 1338 浏览 4 评论 0原文

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

A_andrew是别名中的纹理(Texture2D的一部分|在Texture2D中) alias is alias (Texture2D)

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);
}

我认为片段着色器有问题,他没有得到纹理或|和纹理坐标

When I enable shader program, texture doesnt work

A_andrew is texture in alias (Part of|in Texture2D)
alias is alias (Texture2D)

CSharp Code

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();

Fragment Shader

version 330 core
in vec2 texCords;
    
uniform sampler2D texture0;
    
out vec4 color;
    
void main()
{
    vec4 texColor = texture(texture0, texCords);
    color = texColor;
}

Vertex Shader

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);
}

I think problem in Fragment Shader, he dont get texture or|and texture cordinates

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梨涡少年 2025-01-24 04:56:20

您不能将固定函数属性和固定函数矩阵堆栈与版本 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;
}

You cannot mix fixed function attributes and the fixed function matrix stack with a version 3.30 shader program.

You have to use the built in attributes such as gl_Vertex and gl_MultiTexCoord0 (see Vertex Attributes).

You have to use the the built in uniform variables like gl_ModelViewProjectionMatrix. In legacy OpenGL (GLSL 1.20) there are provided built-in uniforms. See OpenGL Shading Language 1.20 Specification; 7.5 Built-In Uniform State.
One of them is gl_ModelViewProjectionMatrix of type mat4, which provides the transformation by the model view and projection matrix. There also exist separated varables gl_ModelViewMatrix and gl_ProjectionMatrix vor the model view and projection matrix.

Vertex shader:

version 120
 
varying vec2 texCords;
    
void main()
{
    texCords = gl_MultiTexCoord0.xy;
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文