Libgdx 3D?

The cube being glitchy could be because your rendering the faces in order and not by what is closest to the camera. For that you need depthtest. And face culling if you want to only render the face if your in front of it and not in the back.

      Gdx.gl.glEnable(GL20.GL_CULL_FACE);
      Gdx.gl.glEnable(GL20.GL_DEPTH_TEST);

Is the last code you posted working for you?

Yes dude my code is working… no need for culling faces yet…

Not sure you understand what i meant
"Okay been working on this all day now and i have got no where other then a plane (with colour) on the ground however for me to get this to work i had to create my own shader and make a transformation matrix using a method i made in LWJGL… I thought libgdx had all the basic stuff done?

I am now struggling with textureing as the Texture class doesnt allow you to access its ID but you can bind it but that doesnt work as i need to tell the shader which texture to draw using its ID… ahhhhhhhhh Angry

JUST IN CASE YOU DIDN’T SEE IT LOL"

^^ I cant seem to get textures working and another problem i am facing is debating is “rendering” not just rendering
I mean advance rendering and keeping it smooth becuase rendering a mesh over and over again is not a good idea what i should be doing is binding the mesh and rendering all instances of this mesh and then unbinding the mesh but libgdx doesnt allow you to do this???

com.badlogic.gdx.graphics.Texture extends com.badlogic.gdx.graphics.GLTexture which has a public field called glTarget. This looks like the ID you are looking for.

Thanks :slight_smile:

I bind the textures this way, is in the 5th link I posted:

public void render(ShaderProgram shader, PerspectiveCamera camera){
//Binds texture called normal to texture unit 1
      normal.bind(1);
//Tells the shader that texture uniform "u_norTexture" is in the unit 1
      shader.setUniformi("u_norTexture", 1);

//Binds texture called diffuse to texture unit 0
      diffuse.bind(0); 
//Tells the shader that texture uniform "u_diffTexture" is in the unit 0
      shader.setUniformi("u_diffTexture", 0); 
      
      mvpMatrix.set(camera.combined).mul(modelMatrix);
      shader.setUniformMatrix("u_mvpMatrix", mvpMatrix);
      mesh.render(shader, GL20.GL_TRIANGLES);
   }

The Fragment Shader (not tested):

#ifdef GL_ES
precision mediump float;
#endif

uniform sampler2D u_diffTexture;
uniform sampler2D u_norTexture;

void main() {	
	gl_FragColor = texture2D(u_diffTexture, v_texCoord);
}

The Vertex Shader:

attribute vec4 a_position;
attribute vec2 a_texCoord;

uniform mat4 u_mvpMatrix;

void main() {
	v_texCoord = a_texCoord;
	gl_Position = u_mvpMatrix * a_position;
}

Thanks dude, been trying for hour now nothing seems to be working could you send me full source so i can look at what i am doing wrong please thanks :slight_smile:

Could you explain to me how the VertexAttribs work (Usage)?

Also i have some questions

How would i keep this optimized as creatig a mesh for everything is not a good idea but then again i could reuse the mesh and change its texture?
How would i get the bottom left of the mesh for example lets say i have a rectangle (not cube) not if i was to use a transformation on position (10,0,0) how would i get the exact bottom left because i have had some problems with that and it only gets the middle any ideas?

Would this work for android… I know its a dumb question but i am just wondering? :slight_smile:

Hope i am not asking for much thanks this will help alot :slight_smile:

Good news i have figured it out I just removed all the unused code in the shaders and it worked … i must of had an error or something there now i am trying tileing and every time i times the texturecoords by a co-efficent it breaks and doesnt work

Any ideas?

String vertexShader = "attribute vec4 a_position;    \n" + 
                "attribute vec2 a_texCoord;\n" + 
                "uniform mat4 u_worldView;\n" + 
                "uniform mat4 trans;\n" + 
                "varying vec2 v_texCoords;" + 
                "void main()                  \n" + 
                "{                            \n" + 
                "   v_texCoords = a_texCoord * 10; \n" + 
                "   gl_Position =  u_worldView * (trans * a_position);  \n"      + 
                "}                            \n" ;
String fragmentShader = "#ifdef GL_ES\n" +
                  "precision mediump float;\n" + 
                  "#endif\n" + 
                  "varying vec2 v_texCoords;\n" + 
                  "uniform sampler2D u_texture;\n" + 
                  "void main()                                  \n" + 
                  "{                                            \n" + 
                  "  gl_FragColor = texture2D(u_texture, v_texCoords);\n" +
                  "}";

Change the texture coords in the mesh and not in the shader.

sizeX = lenght of the plane on X
xizeY = lenght of the plane on Y
texX and texY is some sort of coef that i was playing arround.

	public Plane(float sizeX, float sizeY, float texX, float texY){
		sizeX/=2.0f;
		sizeY/=2.0f;
		
		  mesh = new Mesh(true, 4, 6,
				  new VertexAttribute(Usage.Position, 3, "a_position"),
				  new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoord"));         
	 
	      mesh.setVertices(new float[] {-sizeX, -sizeY, 0f, 0f, texY,	//bottom-left
	    		  						 sizeX, -sizeY, 0f, texX, texY,	//bottom-right
	    		  						 sizeX,  sizeY, 0f, texX, 0f,	//top-right
	    		  						-sizeX,  sizeY, 0f, 0f, 0f});	//top-left
	      
	      mesh.setIndices(new short[] { 0, 1, 2, 3, 0, 2 });

I dont remenber exactly how this was done, check some terrain texturing tuts.

The usage thing is like a label to tell the functionality of that attribute, Ive never needed it. It may be usefull for some Libgdx wrappers.

I am still getting the same affect doing both ways

		float[] vertices = {
				-1f, 0, -1f,0*10,0*10,      // bottom left
                1f, 0, -1f,1*10,0*10,       // bottom right
                1f, 0, 1f,1*10,1*10,        // top right
                -1f, 0, 1f,0*10,1*10,
		};

Regarding the last image, it looks like you have the texture wrap mode set to ‘clamp’ rather than ‘repeat’. (Apologies if this has already been addressed and I missed it.)

How would i change this?

Look here.

Thanks ;D ;D ;D ;D ;D

Yay I was looking for that web, very very usefull and recommended.

And here is what was missing.

	private Texture loadTexture(String path, TextureWrap wrap, TextureFilter min, TextureFilter max){
		Texture tex = new Texture(path);
		tex.setWrap(wrap, wrap);
		tex.setFilter(min, max);
		return tex;
	}

http://libgdx.badlogicgames.com/nightlies/docs/api/