LibGDX 3D GL20 Wireframe

How do i render mesh wireframe in GL20 in GL10 you use glPolygonMode(GL20.GL_FRONT_AND_BACK, GL20…GL_LINE);

however, glPolygonMode doesn’t exist in GL20

Just because it’s not in GL20 doesn’t mean it’s not supported in OpenGL 2.0

GL11.glDrawArrays() is still used even in the most recent versions of OpenGL.

Is glDrawArrays efficient? More than mesh.render?

If so that would make some things a lot better for me.

I don’t know what mesh.render() is, but I suspect it uses glDrawArrays() or glDrawElements() underneath anyway.

Thanks that was helpful. So to answer a question that I had before that was never answered.

Can I use glDrawArrys and bind textures to make it a tile based 3D terrain?

I think you might be missing the point of glDrawArrays()

glDrawArrays is part of low-level OpenGL. It does exactly what it says. It draws arrays of data (VAs, VBOS, VAOs). Texture binding is done before calling glDrawArrays, and is separate from glDrawArrays().

‘mesh’ I assume is part of LibGDX, and is a higher-level abstraction of the normal process for drawing arrays in OpenGL.

You should probably check the LibGDX documentation/wiki before you start mixing low-level and high-level functions in order to avoid conflicting code (calling a low-level function that was already called within a high-level function and vice-versa).

To simply answer your question: Yes, glDrawArrays can be used to draw textured tiles-based 3D terrain, amongst many other things.

Yes I know the difference. And I just took a look at mesh.java in the github.

I don’t see how it draws the vertex arrays since none of the args are vertexes, I think I’m missing something.

can I get an example of how to use glDrawArrays?

this is what mesh.java looks like

[spoiler]

public void render (ShaderProgram shader, int primitiveType, int offset, int count, boolean autoBind) {
		if (!Gdx.graphics.isGL20Available()) throw new IllegalStateException("can't use this render method with OpenGL ES 1.x");
		if (count == 0) return;

		if (autoBind) bind(shader);

		if (isVertexArray) {
			if (indices.getNumIndices() > 0) {
				ShortBuffer buffer = indices.getBuffer();
				int oldPosition = buffer.position();
				int oldLimit = buffer.limit();
				buffer.position(offset);
				buffer.limit(offset + count);
				Gdx.gl20.glDrawElements(primitiveType, count, GL10.GL_UNSIGNED_SHORT, buffer);
				buffer.position(oldPosition);
				buffer.limit(oldLimit);
			} else {
				Gdx.gl20.glDrawArrays(primitiveType, offset, count);
			}
		} else {
			if (indices.getNumIndices() > 0)
				Gdx.gl20.glDrawElements(primitiveType, count, GL10.GL_UNSIGNED_SHORT, offset * 2);
			else
				Gdx.gl20.glDrawArrays(primitiveType, offset, count);
		}

		if (autoBind) unbind(shader);
	}

[/spoiler]

None of the args are vertices because they must be bound before calling glDrawArrays().



// The VBO is set up like this:
// VTCVTCVTC... etc. where V is vertex data (x, y), T is texcoord data (u, v) and C is colour data (r, g, b, a)

glBindBuffer(GL_ARRAY_BUFFER, buffer); // Bind the VBO

glVertexPointer(2, GL_FLOAT, 32, 0); // Tell OpenGL where to find the vertex data.
glTexCoordPointer(2, GL_FLOAT, 32, 8L); // Tell OpenGL where to find the texture coordinate data.
glColorPointer(4, GL_FLOAT, 32, 16L); // Tell OpenGL where to find the color data.

glDrawArrays(GL_TRIANGLES, 0, vc); // Draw the data

glBindBuffer(GL_ARRAY_BUFFER, 0); // Unbind the VBO

Please note that this uses some deprecated code (gl___Pointer). This code is for pre-OpenGL 2.0. After OpenGL 2.0, you should be using shaders and glVertexAttribPointer() instead.

This is just meant to be an example. It is a bad example, but shows how glDrawArrays() gets its data.

glPolygonMode doesn’t exist in LibGDX since it’s not part of OpenGL ES. If you want that function, you’d have to expose it yourself through LWJGL or whatever backend you choose.

You can just render the triangles with GL_LINES if you want something simple. In other instances it might be better to use barycentric coordinates, discussed here:
http://codeflow.org/entries/2012/aug/02/easy-wireframe-display-with-barycentric-coordinates/

Also note, it will be much easier to use the Mesh and VertexAttribute utilities instead of dealing with VBOs and calling glDrawArrays/etc directly. It is more robust and should also deal with any platform quirks that might crop up. See here:

Easier still is to use the 3D API for rendering meshes:
http://blog.xoppa.com/

I’ve been toying with meshes and shaders to make tile based terrain textures. However, I cannot figure out how to draw textures between certain vertices.

I’ve even though about using decals, but I held back because that would be sloppy.

I’ve been at it for days.