Need help with texturing 3dobjects, using Slick Util and LWJGL

Started by
8 comments, last by hannesp 8 years, 6 months ago

Hello,

I'm new here, so i don't know what to expect smile.png

Anyways, i have this weird problem with rendering a 3d model with textures in LWJGL

That's how it works:

1. The OBJ file is loaded, and an instance of Model3D

2. The corresponding MTL file, and a PNG texture is loaded.

3. The 3d model is rendered.

The revelant code

(This is a modification of my 2d game i want to port to 3d, basically much stuff needs to be rewritten. That's just the code that works):

The renders

  • First picture is the render

  • Second is the wireframe

  • Third is the texture

and a bit more of discussion here

Failed to load user signature

Advertisement
Seems to me as if your quads (the two triangles...) texcoords are wrong. The left upper vertex Has to have (0,1) as coord. Is this the case? The left below vertex must have (0,0) and so on. Have a look at http://www.opengl-tutorial.org/beginners-tutorials/tutorial-5-a-textured-cube/ or Google opengl texture coordinate space.

[...]The left upper vertex Has to have (0,1) as coord. Is this the case? The left below vertex must have (0,0) and so on. [...]

Oh, I didn't know that! I'll try to modify the OBJ manually to set the coords, and see it it works.

Failed to load user signature

Oh no!

Slick util rotates the texture when loading! http://wiki.lwjgl.org/wiki/The_Quad_textured#.28Texture.29_Coordinates

Failed to load user signature

Doesnt make sense to me, why does slick do it? What did you do to solve this Problem?

Doesnt make sense to me, why does slick do it? What did you do to solve this Problem?

I think slick makes it to compromise the coordinates, so if your texture wouldn;t be upside down.

This may be a part of the problem (What if my OpenGL logic fails to clamp it properly AND additionally Slick flips it upside-down?)

I tried different combos of multiplying texture coords by -1 but it didn't fix it.

I still need to create a basic OBJ file by hand with my own texcoords to see what will it do.

Make sure to check both revisions of the gist linked in the first post. Maybe you could see what's wrong or give me some general directions or tips?

Failed to load user signature

Although i dont unterstand what your texture offsets are, i think you should try ty = 1-ty. It is conversion between directx and opengl texture spaces and I remember i had to use it Some time ago with lwjgl/java.

But checking your model data is necessary for your success here, else we are just guessing.

Although i dont unterstand what your texture offsets are, i think you should try ty = 1-ty. It is conversion between directx and opengl texture spaces and I remember i had to use it Some time ago with lwjgl/java.
But checking your model data is necessary for your success here, else we are just guessing.


As soon as possible i will post the test obj file.

I also coded a new obj loader, just to make sure.
I will try to find actual uvmap test texture, for OpenGL.

Expect it this weekend/Fri.

Failed to load user signature

Now i tried to work it out by trying. I created another project, and started coding

Something weird happens:

Troj.java has 2 significant line groups,


Triangle3D troj1 = new Triangle3D( new Vertex3D[] {new Vertex3D(1, 2, 0), new Vertex3D(1,1, 0),new Vertex3D(2, 1, 0)},
				new Vertex3D[] {new Vertex3D(1, 1, 0), new Vertex3D(1, 0, 0),new Vertex3D(0, 1, 0)});

		Triangle3D troj2 = new Triangle3D( new Vertex3D[] {new Vertex3D(1, 2, 0), new Vertex3D(2,1, 0),new Vertex3D(2, 2, 0)},
				new Vertex3D[] {new Vertex3D(0, 0, 0), new Vertex3D(0, 1, 0),new Vertex3D(1, 0, 0)});




		Triangle3D troj3 = new Triangle3D( new Vertex3D[] {new Vertex3D(3, 2, 0), new Vertex3D(4,1, 0),new Vertex3D(4, 2, 0)},
				new Vertex3D[] {new Vertex3D(1, 0, 0), new Vertex3D(1, 1, 0),new Vertex3D(0, 1, 0)});

		try {
			troj1.tex = TextureLoader.getTexture("PNG", Troj.class.getResourceAsStream("/wood.png"));
			troj2.tex = TextureLoader.getTexture("PNG", Troj.class.getResourceAsStream("/wood.png"));
			//troj3.tex = TextureLoader.getTexture("PNG", Troj.class.getResourceAsStream("/wood.png"));
			System.out.println(troj1.tex.getImageHeight() + "x" + troj1.tex.getImageWidth());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

troj1.render();
//troj2.render();
//troj3.render();

So the fun begins.

When I comment out troj2.render();, the second triangle doesn't render. That's ok. The first renders ok with the texture in a form that can be distinguished

But when i comment out troj2.tex = [...], the first (!) triangle [ named troj1 in code ] doesn't have any texture. it's white!

I have no idea why this happens. It shouldn't happen. troj1 and troj2 are two different variables.

Full code

I'm new to LWJGL and game programming, please help!

Failed to load user signature

The white color comes probably from the color3f call while the texture isnt properly bound - wild guess here. You have to take a look at the bound texture on color attachment 0 AMD you should first consider using a Debugger and step through everything. Maybe the texture loader binds the texture somehow when loading.

This topic is closed to new replies.

Advertisement