Libgdx GL20 methods

So I started doing some work with libgdx opengl.

The problem I find is that the glmethods don’t have same arguments. Also, some variables are poorly named and there is no doc on the web at least…

For example,


Gdx.gl20.glVertexAttribPointer(indx, size, type, normalized, stride, ptr);

Why is index called indx?? That just confuses me…
What is ptr? Is it pointer to my buffer? If so, then whats the point of having a pointer there, because even though I tell the pointer to my buffer, I still get exception that I need to bind a buffer if I want to use offsets.

Is there like any doc for GL20 methods? All I can see in the doc is method names…

It isn’t documented because it is OpenGL.
https://www.google.com/search?q=glVertexAttribPointer

Hmm… I think I messed something up. I thought there wasn’t supposed to be a pointer value in this opengl method. Sorries.

I guess this thread should be moved to debugging.

ok. Got any ideas why this doesn’t display anything?


public class IsoMap {

	private ShaderProgram isoShader;

	private int vertexHandle = 0;

	public IsoMap() {
	}

	public void create() {
		isoShader = new ShaderProgram(Gdx.files.internal("shaders/VertexIso.txt"), Gdx.files.internal("shaders/FragmentIso.txt"));

		createBuffers();

		float x = 100, y = 100, width = 100, height = 100;
		float z = 0;

		int size = 3 * 3;

		FloatBuffer buffer = BufferUtils.newFloatBuffer(size);
		buffer.put(x).put(y).put(z);
		buffer.put(x).put(y + height).put(z);
		buffer.put(x + width).put(y).put(z);

		buffer.flip();

		bind(vertexHandle);
		Gdx.gl20.glBufferData(GL20.GL_ARRAY_BUFFER, size, buffer, GL20.GL_STATIC_DRAW);
		bind(0);

		String log = isoShader.getLog();
		if (log.length() > 0) System.out.println(log);
	}

	private void createBuffers() {
		IntBuffer intBuffer = BufferUtils.newIntBuffer(1);
		Gdx.gl20.glGenBuffers(1, intBuffer);
		vertexHandle = intBuffer.get(0);
	}

	public void draw() {
		isoShader.begin();

		Matrix4 projectionMatrix = new Matrix4().setToOrtho(Gdx.graphics.getWidth(), 0, Gdx.graphics.getHeight(), 0, -1, 1);
		isoShader.setUniformMatrix(isoShader.getUniformLocation("u_projTrans"), projectionMatrix, false);

		isoShader.enableVertexAttribute("a_position");

		bind(vertexHandle);
		Gdx.gl20.glVertexAttribPointer(isoShader.getAttributeLocation("a_position"), 3, GL20.GL_FLOAT, false, 0, 0);
		bind(0);

		Gdx.gl20.glDrawArrays(GL20.GL_TRIANGLES, 0, 3);

		isoShader.disableVertexAttribute("a_position");

		isoShader.end();
	}

	private static final void bind(int buffer) {
		Gdx.gl20.glBindBuffer(GL20.GL_ARRAY_BUFFER, buffer);
	}
}


attribute vec3 a_position;

uniform mat4 u_projTrans;

void main() {
	gl_Position = vec4(a_position, 1) * u_projTrans;
}


#ifdef GL_ES
precision mediump float;
#endif

void main() {
    gl_FragColor = vec4(1.0,1.0,1.0,1.0);
}

Okay I fixed it. Had to change to this:


Matrix4 projectionMatrix = new Matrix4().setToOrtho(0, Gdx.graphics.getWidth(), 0, Gdx.graphics.getHeight(), -1, 1);
isoShader.setUniformMatrix(isoShader.getUniformLocation("u_projTrans"), projectionMatrix, true);

at line 44 or something