简体   繁体   English

Libgdx 渲染网格问题

[英]Libgdx Issue with rendering mesh

I am having an issue with rendering a mesh and using the shaders.我在渲染网格和使用着色器时遇到问题。 I had it working previously, but I have been doing some refactoring for better control over the data, and now it is doing some funky things.我以前让它工作过,但我一直在进行一些重构以更好地控制数据,现在它正在做一些时髦的事情。 It looks like either the vertices are being set weird, or the camera matrix is doing something weird with where the vertices are rendered on screen.看起来要么顶点被设置得很奇怪,要么相机矩阵对顶点在屏幕上的渲染位置做了一些奇怪的事情。

My vertex shader is extremely simple right now.我的顶点着色器现在非常简单。

attribute vec4 a_color;
uniform mat4 u_projTrans;
varying vec4 vColor;

void main() {
    vColor = vec4(.5,.5,.5,.8);
    gl_Position = u_projTrans * vec4(a_position.x,a_position.y, 0.0, 1.0);
}

Here is an example of position and color data (though right now I am just ignoring the color data in the shader)这是 position 和颜色数据的示例(尽管现在我只是忽略了着色器中的颜色数据)

[960.0, 980.0, -1.0, 980.0, 970.0, -1.0, 980.0, 960.0, -1.0]
[960.0, 980.0, -1.0, 980.0, 960.0, -1.0, 960.0, 960.0, -1.0]

Each row is a triangle, with 3 vertices (2 position components, and 1 color)每行是一个三角形,有 3 个顶点(2 个 position 分量,1 个颜色)

Here is how I am setting up the mesh and the vertex attributes这是我设置网格和顶点属性的方式

mesh = new Mesh(true, withShaderData.length, 0,
                new VertexAttribute(VertexAttributes.Usage.Position, POSITION_COMPONENTS, "a_position"),
                new VertexAttribute(VertexAttributes.Usage.ColorPacked, COLOR_COMPONENTS, "a_color"));
mesh.setVertices(withShaderData);

When I render this mesh it looks like this.当我渲染这个网格时,它看起来像这样。

在此处输入图像描述 It should look like a simple cave system, and it should only fill in 1 of those purple squares.它应该看起来像一个简单的洞穴系统,并且应该只填充其中一个紫色方块。 I know the generation code is working correctly because it was working just a bit ago, but I have been refactoring to give myself more control of the mesh, and now I can't figure out what is happening.我知道生成代码工作正常,因为它刚刚工作,但我一直在重构以让自己更好地控制网格,现在我无法弄清楚发生了什么。

This picture shows a zoomed in version.这张照片显示了一个放大的版本。 在此处输入图像描述

As you can see from this image, the edges are overlapping, which shouldn't be the case with the data I have.正如您从这张图片中看到的,边缘是重叠的,这不应该是我拥有的数据的情况。

Does anybody have any suggestions on why its not rendering correctly?有人对为什么它不能正确渲染有任何建议吗? I have made sure that the data is properly formatted, at least I think I am.我已经确保数据格式正确,至少我认为是这样。 I made sure the shader isn't doing anything crazy.我确保着色器没有做任何疯狂的事情。 But it is still rendering the triangles in weird locations.但它仍然在奇怪的位置渲染三角形。

Any help would be appreciated.任何帮助,将不胜感激。 Thank you.谢谢你。

Ahh, I was being stupid.啊,我是愚蠢的。 I thought I had formatted it correctly, but I found out I had 1 thing that was completely wrong with my formatting.我以为我的格式正确,但我发现我的格式有 1 件事完全错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM