简体   繁体   English

LibGdx GLES2.0立方体纹理拉伸

[英]LibGdx GLES2.0 cube texel stretching

I've been programming OpenGL on Windows/SDL for a few years and am able to do quite a lot of advanced things with it. 我已经在Windows / SDL上对OpenGL编程了几年,并且能够用它做很多高级的事情。

I've switched over to Android and libgdx and over the past few days have tried to put a simple demo together, just a spinning cube. 我已经切换到Android和libgdx,并且在过去几天中尝试将一个简单的演示放在一起,只是一个旋转的立方体。

Using libgdx's ObjLoader and Mesh classes, I loaded a cube mesh exported from blender(with normals and uv coords), and tried to apply a texture, and it draws a cube, but seems to only uses one texel from the texture to cover the whole model. 使用libgdx的ObjLoaderMesh类,我加载了从Blender导出的立方体网格(具有法线和uv坐标),并尝试应用纹理,并绘制了一个立方体,但似乎仅使用纹理中的一个texel覆盖了整个模型。

I've double checked the texture coordinates and even hand coded a plane with specific coordinates to test, and the same thing is happening. 我已经仔细检查了纹理坐标,甚至手工编码了具有特定坐标的平面以进行测试,并且发生了同样的事情。

This is the Vertex Shader: 这是顶点着色器:

attribute vec4 a_position;
attribute vec3 a_normal;
attribute vec2 a_texCoord;

uniform mat4 mvp;

varying vec3 outNormal;
varying vec2 outTexcd;

void main(){
    outNormal = a_normal;
    outTexcd = a_texCoord;
    gl_Position = mvp * a_position;
}

And the fragment shader: 和片段着色器:

precision highp float;

varying vec3 outNormal;
varying vec2 outTexcd;
uniform sampler2D tex;

void main(){
    vec3 norms = outNormal;
    gl_FragColor = texture2D(tex,outTexcd);
}

But I don't think that's where the problem lies. 但是我不认为这就是问题所在。 Or maybe it does, I'm not sure. 也许确实如此,我不确定。

Didn't want to clog up this question too much so the main source is here(pastebin): Main Source 不想过多地阻塞这个问题,所以主要来源在这里(pastebin): 主要来源

If this is a bad question please let me know, It's my first one. 如果这个问题不好,请告诉我,这是我的第一个问题。

Playing with images I found the answer. 玩图像我找到了答案。

Was using a 32 bit .png RGBA8888, but not telling libgdx that. 正在使用32位.png RGBA8888,但没有告诉libgdx。

Switched to take in the image as RGBA8888: 切换为以RGBA8888的形式拍摄图像:

t = new Texture(Gdx.files.internal("Image/r3.png"),Format.RGBA8888,true);

I feel slightly sheepish, sorry all. 我感到有些不高兴,对不起。

EDIT: Strangely, no transparency though... 编辑:奇怪的是,虽然没有透明度...

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

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