java - OpenGL + Slick Loaded Textures Are Rotating -
i using opengl create 3d game engine in java. , using slick library implement textures. using method create rectangle/square prisms (6 squares/rectangles). in same method, implement textures.
the problem 5 sides of prism render 90 degrees rotated textures. doesn't matter when maing floor since using on brick wall texture isn't looking right.
since wall care 4 sides of it.
the wall texture being rendered 90 degrees rotated on 3 sides of prism. , rendered without rotation on 1 side.
i couldn't work problem out. need change how texture implemented?
here method creating prism.
public static void quadprizm(float x, float y, float z, float sx, float sy, float sz, texture tex){ glpushmatrix(); { gltranslatef(x, y, z); tex.bind(); glbegin(gl_quads); { //rotated (wrong) gltexcoord2f(0, 0); glvertex3f(-sx/2, -sy/2, sz/2); gltexcoord2f(0, 4); glvertex3f(sx/2, -sy/2, sz/2); gltexcoord2f(4, 4); glvertex3f(sx/2, sy/2, sz/2); gltexcoord2f(4, 0); glvertex3f(-sx/2, sy/2, sz/2); //the correct side gltexcoord2f(0, 0); glvertex3f(-sx/2, -sy/2, -sz/2); gltexcoord2f(0, 4); glvertex3f(-sx/2, sy/2, -sz/2); gltexcoord2f(4, 4); glvertex3f(sx/2, sy/2, -sz/2); gltexcoord2f(4, 0); glvertex3f(sx/2, -sy/2, -sz/2); //rotated (wrong) gltexcoord2f(0, 0); glvertex3f(-sx/2, -sy/2, -sz/2); gltexcoord2f(0, 4); glvertex3f(-sx/2, -sy/2, sz/2); gltexcoord2f(4, 4); glvertex3f(-sx/2, sy/2, sz/2); gltexcoord2f(4, 0); glvertex3f(-sx/2, sy/2, -sz/2); //rotated (wrong) gltexcoord2f(0, 0); glvertex3f(sx/2, -sy/2, -sz/2); gltexcoord2f(0, 4); glvertex3f(sx/2, -sy/2, sz/2); gltexcoord2f(4, 4); glvertex3f(sx/2, sy/2, sz/2); gltexcoord2f(4, 0); glvertex3f(sx/2, sy/2, -sz/2); //bottom side gltexcoord2f(0, 0); glvertex3f(-sx/2, -sy/2, -sz/2); gltexcoord2f(0, 4); glvertex3f(sx/2, -sy/2, -sz/2); gltexcoord2f(4, 4); glvertex3f(sx/2, -sy/2, sz/2); gltexcoord2f(4, 0); glvertex3f(-sx/2, -sy/2, sz/2); //top side gltexcoord2f(0, 0); glvertex3f(-sx/2, sy/2, -sz/2); gltexcoord2f(0, 4); glvertex3f(sx/2, sy/2, -sz/2); gltexcoord2f(4, 4); glvertex3f(sx/2, sy/2, sz/2); gltexcoord2f(4, 0); glvertex3f(-sx/2, sy/2, sz/2); } glend(); } glpopmatrix(); }
with following line, create cube wall texture.
draw.cube(0, 10, 10, 5, 5, 5, wall);
here one of 3 rotated sides:
here only side correct:
i have solved problem changing texture coordinates. new code this:
public static void quadprizm(float x, float y, float z, float sx, float sy, float sz, texture tex){ glpushmatrix(); { gltranslatef(x, y, z); tex.bind(); glbegin(gl_quads); { //rotated (wrong) gltexcoord2f(4, 0); glvertex3f(-sx/2, -sy/2, sz/2); gltexcoord2f(0, 0); glvertex3f(sx/2, -sy/2, sz/2); gltexcoord2f(0, 4); glvertex3f(sx/2, sy/2, sz/2); gltexcoord2f(4, 4); glvertex3f(-sx/2, sy/2, sz/2); //the correct side gltexcoord2f(0, 0); glvertex3f(-sx/2, -sy/2, -sz/2); gltexcoord2f(0, 4); glvertex3f(-sx/2, sy/2, -sz/2); gltexcoord2f(4, 4); glvertex3f(sx/2, sy/2, -sz/2); gltexcoord2f(4, 0); glvertex3f(sx/2, -sy/2, -sz/2); //rotated (wrong) gltexcoord2f(4, 0); glvertex3f(-sx/2, -sy/2, -sz/2); gltexcoord2f(0, 0); glvertex3f(-sx/2, -sy/2, sz/2); gltexcoord2f(0, 4); glvertex3f(-sx/2, sy/2, sz/2); gltexcoord2f(4, 4); glvertex3f(-sx/2, sy/2, -sz/2); //rotated (wrong) gltexcoord2f(4, 0); glvertex3f(sx/2, -sy/2, -sz/2); gltexcoord2f(0, 0); glvertex3f(sx/2, -sy/2, sz/2); gltexcoord2f(0, 4); glvertex3f(sx/2, sy/2, sz/2); gltexcoord2f(4, 4); glvertex3f(sx/2, sy/2, -sz/2); //bottom side gltexcoord2f(0, 0); glvertex3f(-sx/2, -sy/2, -sz/2); gltexcoord2f(0, 4); glvertex3f(sx/2, -sy/2, -sz/2); gltexcoord2f(4, 4); glvertex3f(sx/2, -sy/2, sz/2); gltexcoord2f(4, 0); glvertex3f(-sx/2, -sy/2, sz/2); //top side gltexcoord2f(0, 0); glvertex3f(-sx/2, sy/2, -sz/2); gltexcoord2f(0, 4); glvertex3f(sx/2, sy/2, -sz/2); gltexcoord2f(4, 4); glvertex3f(sx/2, sy/2, sz/2); gltexcoord2f(4, 0); glvertex3f(-sx/2, sy/2, sz/2); } glend(); } glpopmatrix(); }
Comments
Post a Comment