在多维数据集上的opentk多个纹理不起作用

塞缪尔·艾伦(Samuel Allan)

因此,在我的程序中有一个用于绘制多维数据集的函数。我在Linux上将c#与monodevelop一起使用。这是函数:

private int DrawCube(float x, float y, float z, float ori, int SideTexture, int TopTexture, int BottomTexture)
{
    GL.PushMatrix();

    GL.Translate(x, y, z);
    GL.Rotate(ori, 0, 1, 0);

    GL.BindTexture(TextureTarget.Texture2D, SideTexture);

    GL.Begin(BeginMode.Quads);

    GL.Color3(Color.White);
    GL.TexCoord2(0.0f, 1.0f - 0.0f); GL.Vertex3(0, 0, 0);
    GL.TexCoord2(1.0f, 1.0f - 0.0f); GL.Vertex3(20, 0, 0);
    GL.TexCoord2(1.0f, 1.0f - 1.0f); GL.Vertex3(20, 20, 0);
    GL.TexCoord2(0.0f, 1.0f - 1.0f); GL.Vertex3(0, 20, 0);
    //Top
    //GL.ActiveTexture(TextureUnit.Texture0);
    GL.BindTexture(TextureTarget.Texture2D, TopTexture);
    GL.TexCoord2(0.0f, 1.0f - 0.0f); GL.Vertex3(20, 0, 0);
    GL.TexCoord2(1.0f, 1.0f - 0.0f); GL.Vertex3(20, 0, -20);
    GL.TexCoord2(1.0f, 1.0f - 1.0f); GL.Vertex3(20, 20, -20);
    GL.TexCoord2(0.0f, 1.0f - 1.0f); GL.Vertex3(20, 20, 0);
    //Bottom
    GL.BindTexture(TextureTarget.Texture2D, BottomTexture);
    GL.TexCoord2(0.0f, 1.0f - 0.0f); GL.Vertex3(0, 0, 0);
    GL.TexCoord2(1.0f, 1.0f - 0.0f); GL.Vertex3(0, 0, -20);
    GL.TexCoord2(1.0f, 1.0f - 1.0f); GL.Vertex3(20, 0, -20);
    GL.TexCoord2(0.0f, 1.0f - 1.0f); GL.Vertex3(20, 0, 0);
    GL.BindTexture(TextureTarget.Texture2D, SideTexture);
    GL.TexCoord2(0.0f, 1.0f - 0.0f); GL.Vertex3(0, 0, -20);
    GL.TexCoord2(1.0f, 1.0f - 0.0f); GL.Vertex3(0, 0, 0);
    GL.TexCoord2(1.0f, 1.0f - 1.0f); GL.Vertex3(0, 20, 0);
    GL.TexCoord2(0.0f, 1.0f - 1.0f); GL.Vertex3(0, 20, -20);

    GL.TexCoord2(0.0f, 1.0f - 0.0f); GL.Vertex3(0, 20, 0);
    GL.TexCoord2(1.0f, 1.0f - 0.0f); GL.Vertex3(20, 20, 0);
    GL.TexCoord2(1.0f, 1.0f - 1.0f); GL.Vertex3(20, 20, -20);
    GL.TexCoord2(0.0f, 1.0f - 1.0f); GL.Vertex3(0, 20, -20);

    GL.TexCoord2(0.0f, 1.0f - 0.0f); GL.Vertex3(20, 0, -20);
    GL.TexCoord2(1.0f, 1.0f - 0.0f); GL.Vertex3(0, 0, -20);
    GL.TexCoord2(1.0f, 1.0f - 1.0f); GL.Vertex3(0, 20, -20);
    GL.TexCoord2(0.0f, 1.0f - 1.0f); GL.Vertex3(20, 20, -20);

    GL.End();
    GL.PopMatrix();

return 6;   // Return number of faces drawn
}

您可能已经猜到了,此函数绘制一个带有position的立方体x, y, zori侧面的Direction和SideTexture以及顶部和底部的TopTexture和BottomTexture。现在的问题是,它仅用一种纹理绘制立方体!侧面纹理。我不知道是什么问题。我是否需要取消绑定纹理?正如我说的那样,代码中的其他所有内容都可以正常工作,因为纹理已经很讨厌了。任何帮助表示赞赏。

提琴手

您无法GL.BindTexture()在始端区域内拨打电话从文档中

glBegin和glEnd之间只能使用GL命令的子集命令是glVertex,glColor,glSecondaryColor,glIndex,glNormal,glFogCoord,glTexCoord,glMultiTexCoord,glVertexAttrib,glEvalCoord,glEvalPoint,glArrayElement,glMaterial和glEdgeFlag。同样,可以使用glCallList或glCallLists执行仅包含前面命令的显示列表。如果在glBegin和glEnd之间执行了其他任何GL命令,则会设置错误标志,并且该命令将被忽略。

如果进行检查,GL.GetError()您将看到收到InvalidOperation错误。实际上,GL.GetError()当某些东西无法按OpenGL预期渲染时,这应该是您的第一反应。

解决方案:

private int DrawCube(float x, float y, float z, float ori, int SideTexture, int TopTexture, int BottomTexture)
{
    GL.PushMatrix();

    GL.Translate(x, y, z);
    GL.Rotate(ori, 0, 1, 0);

    GL.BindTexture(TextureTarget.Texture2D, SideTexture);
    GL.Begin(BeginMode.Quads);
    GL.Color3(Color.White);
    GL.TexCoord2(0.0f, 1.0f - 0.0f); GL.Vertex3(0, 0, 0);
    GL.TexCoord2(1.0f, 1.0f - 0.0f); GL.Vertex3(20, 0, 0);
    GL.TexCoord2(1.0f, 1.0f - 1.0f); GL.Vertex3(20, 20, 0);
    GL.TexCoord2(0.0f, 1.0f - 1.0f); GL.Vertex3(0, 20, 0);
    GL.End();

    //Top
    GL.BindTexture(TextureTarget.Texture2D, TopTexture);
    GL.Begin(BeginMode.Quads);
    GL.TexCoord2(0.0f, 1.0f - 0.0f); GL.Vertex3(20, 0, 0);
    GL.TexCoord2(1.0f, 1.0f - 0.0f); GL.Vertex3(20, 0, -20);
    GL.TexCoord2(1.0f, 1.0f - 1.0f); GL.Vertex3(20, 20, -20);
    GL.TexCoord2(0.0f, 1.0f - 1.0f); GL.Vertex3(20, 20, 0);
    GL.End();

    //Bottom
    GL.BindTexture(TextureTarget.Texture2D, BottomTexture);
    GL.Begin(BeginMode.Quads);
    GL.TexCoord2(0.0f, 1.0f - 0.0f); GL.Vertex3(0, 0, 0);
    GL.TexCoord2(1.0f, 1.0f - 0.0f); GL.Vertex3(0, 0, -20);
    GL.TexCoord2(1.0f, 1.0f - 1.0f); GL.Vertex3(20, 0, -20);
    GL.TexCoord2(0.0f, 1.0f - 1.0f); GL.Vertex3(20, 0, 0);
    GL.End();

    GL.BindTexture(TextureTarget.Texture2D, SideTexture);
    GL.Begin(BeginMode.Quads);
    GL.TexCoord2(0.0f, 1.0f - 0.0f); GL.Vertex3(0, 0, -20);
    GL.TexCoord2(1.0f, 1.0f - 0.0f); GL.Vertex3(0, 0, 0);
    GL.TexCoord2(1.0f, 1.0f - 1.0f); GL.Vertex3(0, 20, 0);
    GL.TexCoord2(0.0f, 1.0f - 1.0f); GL.Vertex3(0, 20, -20);

    GL.TexCoord2(0.0f, 1.0f - 0.0f); GL.Vertex3(0, 20, 0);
    GL.TexCoord2(1.0f, 1.0f - 0.0f); GL.Vertex3(20, 20, 0);
    GL.TexCoord2(1.0f, 1.0f - 1.0f); GL.Vertex3(20, 20, -20);
    GL.TexCoord2(0.0f, 1.0f - 1.0f); GL.Vertex3(0, 20, -20);

    GL.TexCoord2(0.0f, 1.0f - 0.0f); GL.Vertex3(20, 0, -20);
    GL.TexCoord2(1.0f, 1.0f - 0.0f); GL.Vertex3(0, 0, -20);
    GL.TexCoord2(1.0f, 1.0f - 1.0f); GL.Vertex3(0, 20, -20);
    GL.TexCoord2(0.0f, 1.0f - 1.0f); GL.Vertex3(20, 20, -20);
    GL.End();

    GL.PopMatrix();

    return 6;   // Return number of faces drawn
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Three.js多维数据集-不同的纹理不起作用

来自分类Dev

OpenTK纹理多维数据集显示为黑色吗?

来自分类Dev

使用ChartJS时多个数据集不起作用

来自分类Dev

纹理不起作用

来自分类Dev

球体的透明度在我的多维数据集的所有面上均不起作用-Helixtoolkit

来自分类Dev

OpenTK 从 dds 纹理手动上传 mipmap 不起作用

来自分类Dev

Laravel 上的多个地方不起作用

来自分类Dev

OpenTK在着色器上绑定多个纹理

来自分类Dev

无法使用OpenGL和SFML在我的多维数据集上应用纹理

来自分类Dev

如何在jMonkeyEngine 3中将相机作为纹理投射到多维数据集上?

来自分类Dev

在多维数据集three.js上使用纹理和颜色

来自分类Dev

多个“ \ a”不起作用

来自分类Dev

渲染到纹理不起作用

来自分类Dev

LWJGL某些纹理不起作用

来自分类Dev

Twitter提前输入本地数据集不起作用

来自分类Dev

查询所选选项的数据集不起作用

来自分类Dev

Twitter提前输入本地数据集不起作用

来自分类Dev

多维数组中的 ksort 不起作用

来自分类Dev

kendogrid上的多个过滤器不起作用

来自分类Dev

在JPanel上绘制多个JComponent不起作用

来自分类Dev

SceneKit-将多维数据集纹理映射到框

来自分类Dev

多个.on()函数不起作用

来自分类Dev

多个IF语句不起作用?

来自分类Dev

熊猫数据框的groupby上的峰度不起作用

来自分类Dev

在Primefaces数据表上分页不起作用

来自分类Dev

在Redis作业上存储“元”数据不起作用?

来自分类Dev

空数组上的角双向数据绑定不起作用

来自分类Dev

响应数据表上的jQuery事件不起作用

来自分类Dev

WindowBuilder上的双向数据绑定似乎不起作用

Related 相关文章

热门标签

归档