Java Code Examples for com.badlogic.gdx.graphics.glutils.ShaderProgram#NORMAL_ATTRIBUTE

The following examples show how to use com.badlogic.gdx.graphics.glutils.ShaderProgram#NORMAL_ATTRIBUTE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Renderer20.java    From fluid-simulator-v2 with Apache License 2.0 6 votes vote down vote up
static private String createVertexShader (boolean hasNormals, boolean hasColors, int numTexCoords) {
	String shader = "attribute vec4 " + ShaderProgram.POSITION_ATTRIBUTE + ";\n"
		+ (hasNormals ? "attribute vec3 " + ShaderProgram.NORMAL_ATTRIBUTE + ";\n" : "")
		+ (hasColors ? "attribute vec4 " + ShaderProgram.COLOR_ATTRIBUTE + ";\n" : "");

	for (int i = 0; i < numTexCoords; i++) {
		shader += "attribute vec2 " + ShaderProgram.TEXCOORD_ATTRIBUTE + i + ";\n";
	}

	shader += "uniform mat4 u_projModelView;\n";
	shader += (hasColors ? "varying vec4 v_col;\n" : "");

	for (int i = 0; i < numTexCoords; i++) {
		shader += "varying vec2 v_tex" + i + ";\n";
	}

	shader += "void main() {\n" + "   gl_Position = u_projModelView * " + ShaderProgram.POSITION_ATTRIBUTE + ";\n"
		+ (hasColors ? "   v_col = " + ShaderProgram.COLOR_ATTRIBUTE + ";\n" : "");

	for (int i = 0; i < numTexCoords; i++) {
		shader += "   v_tex" + i + " = " + ShaderProgram.TEXCOORD_ATTRIBUTE + i + ";\n";
	}
	shader += "   gl_PointSize = 1.0;\n";
	shader += "}\n";
	return shader;
}
 
Example 2
Source File: GameWorldRenderer.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
private void createBackPlane () {
	plane = new Mesh(true, 4, 4, new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE),
		new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE));

	// @formatter:off
	float size = 10f;
	float verts[] = {-size / 2, 0, size / 2, size / 2, 0, size / 2, size / 2, 0, -size / 2, -size / 2, 0, -size / 2};
	// float verts[] = {size, 0, size, size, 0, 0, 0, 0, 0, 0, 0, size};

	float normals[] = {0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0};
	// @formatter:on

	int vidx = 0, nidx = 0;
	int length = 6 * 4;
	float[] vertices = new float[length];
	for (int i = 0; i < length;) {
		vertices[i++] = verts[vidx++];
		vertices[i++] = verts[vidx++];
		vertices[i++] = verts[vidx++];
		vertices[i++] = normals[nidx++];
		vertices[i++] = normals[nidx++];
		vertices[i++] = normals[nidx++];
	}

	plane.setVertices(vertices);
	plane.setIndices(new short[] {0, 1, 2, 3});
}
 
Example 3
Source File: G3dtLoader.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
private static VertexAttribute[] createVertexAttributes (boolean hasNormals, int uvs) {
	VertexAttribute[] attributes = new VertexAttribute[1 + (hasNormals ? 1 : 0) + uvs];
	int idx = 0;
	attributes[idx++] = new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE);
	if (hasNormals) attributes[idx++] = new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE);
	for (int i = 0; i < uvs; i++) {
		attributes[idx++] = new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + i);
	}
	return attributes;
}