没有日志,没有堆栈跟踪,只有Libgdx Mesh无法渲染。我在spriteBatch上测试了Shader,它运行得很好。网格对渲染方法没有任何作用,甚至不是图形错误......你知道问题是什么吗?
这是渲染代码:
Gdx.gl20.glClearColor(0f, 0f, 0f, 1f);
Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT);
Gdx.gl20.glEnable(GL20.GL_BLEND);
Gdx.gl20.glEnable(GL20.GL_TEXTURE_2D);
Gdx.gl20.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
Mesh m = ShipMesh.MakeMeshGid(center,w,h,shipsels);
this.getDisplayTexture().bind();
ShipManager.ShipShader.begin();
ShipManager.ShipShader.setUniformi("u_mode", -4);
ShipManager.ShipShader.setUniformi("u_texture", 0);
ShipManager.ShipShader.setUniformMatrix(0, cam.combined);
m.render(ShipManager.ShipShader, GL20.GL_TRIANGLES);
ShipManager.ShipShader.end();
我使用的着色器使用基本的passtrough Shader和这个片段Shader:
varying vec4 vColor;
varying vec2 vTexCoord0;
uniform sampler2D u_texture;
uniform int u_mode;
void main()
{
vec4 col = vec4(1, 0, 0.682,1);
if (u_mode == -4){
col = vec4(vTexCoord0.xy,0.,1.);
}
if (u_mode == -3){
col = vec4(0.);
}
if (u_mode == -2){
col = vec4(0.,0.,0.,1.);
}
if (u_mode == -1){
col = vec4(1.);
}
if (u_mode == 0){
col = vec4(vColor.rgb,1);
}
if(u_mode == 1){
col = texture2D(u_texture, vTexCoord0);
}
gl_FragColor = col;
}
对于MakeMeshGrid方法,我使用MeshBuilder:
public static Mesh MakeMeshGid(Vector2 center,int width,int height,Shipsel[][] data){
MeshBuilder meshBuilder = new MeshBuilder();
meshBuilder.begin(Usage.Position | Usage.TextureCoordinates | Usage.ColorPacked);
for (Shipsel[]sh:data){
for (Shipsel s:sh){
if (s!= null){
meshBuilder.part(s.getX()+":"+s.getY(), GL20.GL_TRIANGLES);
meshBuilder.setColor(Color.WHITE);
Vector3[] bounds = getShipselBounds(width,height,s,center);
Vector2[] uvs = getUVs(width,height,s);
MeshPartBuilder.VertexInfo v1 = new MeshPartBuilder.VertexInfo().setPos(bounds[0]).setCol(null).setUV(uvs[0]);
MeshPartBuilder.VertexInfo v2 = new MeshPartBuilder.VertexInfo().setPos(bounds[1]).setCol(null).setUV(uvs[1]);
MeshPartBuilder.VertexInfo v3 = new MeshPartBuilder.VertexInfo().setPos(bounds[2]).setCol(null).setUV(uvs[2]);
MeshPartBuilder.VertexInfo v4 = new MeshPartBuilder.VertexInfo().setPos(bounds[3]).setCol(null).setUV(uvs[3]);
meshBuilder.rect(v1, v2, v3, v4);
}
}
}
Mesh mesh = meshBuilder.end();
return mesh;
}
private static Vector3[] getShipselBounds(int w,int h,Shipsel s, Vector2 center) {
Vector3[] bounds = new Vector3[4];
bounds[0] = new Vector3(0.5f, 0.5f,0).add(s.getX() - w / 2,
s.getY() - h / 2,0).add(center.x,center.y,0);
bounds[1] = new Vector3(-0.5f, 0.5f,0).add(s.getX() - w / 2,
s.getY() - h / 2,0).add(center.x,center.y,0);
bounds[2] = new Vector3(-0.5f, -0.5f,0).add(s.getX() - w / 2,
s.getY() - h / 2,0).add(center.x,center.y,0);
bounds[3] = new Vector3(0.5f, -0.5f,0).add(s.getX() - w / 2,
s.getY() - h / 2,0).add(center.x,center.y,0);
return bounds;
}
private static Vector2[] getUVs(int w,int h,Shipsel s) {
Vector2[] uvs = new Vector2[4];
uvs[0] = new Vector2((s.getX() + 1) / (w + 1), (s.getY() + 1) / (h + 1));
uvs[1] = new Vector2((s.getX()) / (w + 1), (s.getY() + 1) / (h + 1));
uvs[2] = new Vector2((s.getX()) / (w + 1), (s.getY()) / (h + 1));
uvs[3] = new Vector2((s.getX() + 1) / (w + 1), (s.getY()) / (h + 1));
return uvs;
}
给我至少一个提示或类似的东西。
更新:
当我正在修修补补时,我得到了一些东西可以呈现,但它的工作方式非常有效:
Mesh m = ShipMesh.MakeMeshGid(center,w,h,shipsels);
this.getDisplayTexture().bind();
ShipManager.ShipShader.begin();
ShipManager.ShipShader.setUniformi("u_mode", -4);
ShipManager.ShipShader.setUniformi("u_texture", 0);
ShipManager.ShipShader.setUniformMatrix(0, cam.combined);
m.render(ShipManager.ShipShader, GL20.GL_TRIANGLES);
ShipManager.ShipShader.end();
m.dispose();
ShipManager.ShipShader.begin();
ShipManager.ShipShader.setUniformi("u_mode", 1);
ShipManager.ShipShader.end();
Texture tex = getDisplayTexture();
Batch b = new SpriteBatch();
b.setShader(ShipManager.ShipShader);
b.setProjectionMatrix(cam.combined);
Vector2 o = new Vector2(center);
o.sub(matMap.getWidth()/2, matMap.getHeight()/2);
b.begin();
b.draw(tex, o.x, o.y,matMap.getWidth(),matMap.getHeight());
b.end();
b.dispose();
以这种格式,其他一切像以前一样,它用黑色绘制网格,如果我删除了Spritebatch部分,它就不起作用。
它应该绘制纹理坐标,而不是纯黑色。
我想我错过了SpriteBatch中包含的内容。
答案 0 :(得分:0)
所以我发现这是一个愚蠢的转换错误,正在弄乱UV。紫外线是处理中而不是浮法。对于未渲染的网格,调用Gdx.gl.glDepthMask(true);
在mesh.render();
解决了该问题后,使用精灵批处理解决了问题:)
我希望它有所帮助:)。