LibGdx GLES2.0 cube texel stretching

◇◆丶佛笑我妖孽 提交于 2019-12-11 00:25:25

问题


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.

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.

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.

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

If this is a bad question please let me know, It's my first one.


回答1:


Playing with images I found the answer.

Was using a 32 bit .png RGBA8888, but not telling libgdx that.

Switched to take in the image as RGBA8888:

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

I feel slightly sheepish, sorry all.

EDIT: Strangely, no transparency though...



来源:https://stackoverflow.com/questions/10980702/libgdx-gles2-0-cube-texel-stretching

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!