java - Lwjgl texture edges issue -
i have issue when try bind texture 3d model in opengl ( don't have issue blender). texture correctly placed on model except regions. problem visible on edges of model:
in blender can see problem tight model cut:
i verified read correctly vt fields in .obj file, face lines link each vertex appropriate texture coordinates.
the code use bind texture is:
glbindtexture(gl_texture_2d, _texture.gettextureid()); gl11.gltexparameteri(gl11.gl_texture_2d, gl11.gl_texture_wrap_s, gl12.gl_clamp_to_edge); gl11.gltexparameteri(gl11.gl_texture_2d, gl11.gl_texture_wrap_t, gl12.gl_clamp_to_edge); gl30.glgeneratemipmap(gl11.gl_texture_2d); gl11.glcolor3d(0, 0, 0); gl11.glmaterial(gl_front_and_back, gl_ambient, _ambiant.getfloatbuffer()); gl11.glmaterial(gl_front_and_back, gl_diffuse, _diffuse.getfloatbuffer()); gl11.glmaterial(gl_front_and_back, gl_specular, _specular.getfloatbuffer()); gl11.glmaterialf(gl_front_and_back, gl_shininess, _shininess);
i don't know have change parameters or other changes. appreciated.
---- update ----
i wrote own obj reader, each line check if vertex, vt, vn or f:
line = next(); string[] arr = line.split("\\s+"); if (arr[0].equals("o")) { _name = arr[1]; continue; } if (arr[0].equals("v")) _v.add(new vec3(double.parsedouble(arr[1]), double .parsedouble(arr[2]), double.parsedouble(arr[3]))); if (arr[0].equals("vt")) { vec3 tex_coord = new vec3(double.parsedouble(arr[1]), 0, 0); if (arr.length > 2) { if (_flip) tex_coord.sety(1 - double.parsedouble(arr[2])); else tex_coord.sety(double.parsedouble(arr[2])); if (arr.length > 3) tex_coord.setz(double.parsedouble(arr[3])); } _vt.add(tex_coord); } if (arr[0].equals("vn")) _vn.add(new vec3(double.parsedouble(arr[1]), double .parsedouble(arr[2]), double.parsedouble(arr[3]))); if (arr[0].equals("f")){ parseface(arr); }
with:
private void parseface(final string[] arr) { int[][] face = new int[arr.length - 1][]; (int = 0; < face.length; i++) { string[] arrf = arr[i + 1].trim().split("/"); face[i] = new int[arrf.length]; face[i][0] = integer.parseint(arrf[0]) - 1; if (arrf.length > 1) { face[i][1] = integer.parseint(arrf[1]) - 1; if (arrf.length > 2) face[i][2] = integer.parseint(arrf[2]) - 1; } _f.add(face); }
then link vertex vertex coordinates:
private void computesimplifiedarrays() { (int = 0; < _v.size(); i++) { _normals.add(null); _texture_coordinates.add(null); } (int[][] f : _f) { int[] face = new int[f.length]; (int = 0; < f.length; i++) { int index = f[i][0]; face[i] = f[i][0]; if (f[i].length > 1) { _texture_coordinates.set(index, _vt.get(f[i][1])); if (f[0].length > 2) _normals.set(index, _vn.get(f[i][2])); else _normals.set(index, new vec3()); } } _faces.add(face); } }
so each vertex (even if have same coordinates) keep right texture coordinates.
Comments
Post a Comment