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: one of 3 wrong sides

here only side correct: the correct side

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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -