C#SharpGL如何绘制具有半透明顶点的Quad?

时间:2018-08-15 00:27:07

标签: c# sharpgl

我已经在这个问题上工作了大约一个星期,甚至谷歌都没有帮助。我可以绘制四边形,在其上放置纹理。但是当需要尊重Alpha通道时,事实并非如此。

所以这就是我的位置:暂时我将代码简化为基本内容。我的画图调用会执行所有操作(清除,启用/禁用标志,具有混合填充,渲染顶点和为顶点着色并进行着色)。 init()和resize()调用现在没有任何反应。

根据互联网示例,我遗留下了我一直在换入和换出的各种代码,并仅对其进行了注释。我还在代码中添加了一些注释,以说明我在做什么。

要删除变量,我只是设置了颜色,每个顶点都有一个不同的alpha。我在网上看到的有关此类代码的示例显示了它适用于这些示例。

代码如下:

public void glDraw(OpenGL gl)
{
    int w = gl.RenderContextProvider.Width;
    int h = gl.RenderContextProvider.Height;
    int x = 0 + 2 ; //Positioning code for the debug bit
    int y = h - 12 - 2;// --^


    gl.Disable(OpenGL.GL_DEPTH_TEST); //If i turn this off nothing draws
    //  Clear the color and depth buffers.
    gl.ClearColor(0.75f, 0.75f, 0.75f, 1f);
    //gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT); //if i turn this on, my reasearch says alpha blending wont work with depth buffers
    gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT);

    //This is a call to a debug bit and works fine, so its been disabled for now.
    //if (_currentNote != null) { SharpGLHelper.DrawColoredText(gl, x, y, new GLColor(0, 0, 0, 1), "Consolas", 12f, _currentNote.AsEncoded()); }

    gl.BlendFunc(OpenGL.GL_BLEND_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA);
    gl.Enable(OpenGL.GL_BLEND);
    //gl.DepthMask(0);

    //gl.BindTexture(OpenGL.GL_TEXTURE_2D, tDemo.textureObject); //The texture i'll be applying to this quad when it behaves. (it does apply now, but doesnt respect alpha)
    gl.Begin(OpenGL.GL_QUADS);

    gl.Color(new GLColor(1f,0,0,0.5f));
    //gl.TexCoord(0, 0);
    gl.Vertex2sv(new short[2] { 0, 0 });
    //gl.Vertex(0,0,0);

    gl.Color(new GLColor(1, 1, 1, 0.25f));
    //gl.Color(Color.White);
    //gl.TexCoord(1, 0);
    gl.Vertex2sv(new short[2] { 1, 0 });
    //gl.Vertex(1, 0, 0);

    gl.Color(new GLColor(1, 1, 1, 0.75f));
    //gl.TexCoord(1, 1);
    //gl.Color(Color.White);
    gl.Vertex2sv(new short[2] { 1, -1 });
    //gl.Vertex(1, -1, 0);

    gl.Color(new GLColor(1, 1, 1, 1f));
    //gl.TexCoord(0, 1);
    //gl.Color(Color.White);
    gl.Vertex2sv(new short[2] { 0, -1 });
    //gl.Vertex(0, -1, 0);

    gl.End();

    //gl.Disable(OpenGL.GL_BLEND);
    //gl.DepthMask(1);

    gl.Flush();
}

所以我不能发布图片,但是可以发布一个链接: https://cdn.discordapp.com/attachments/428251730883379203/479081428953464842/Capture_OpenGLOutput.PNG

这是当前输出。即使那里有alpha信息,但我还没有发现使魔术发生的组合。任何帮助都是最大的帮助,所以我可以跳过此问题,找到下一个^。^

0 个答案:

没有答案
相关问题