@Override public void create() { rotationSpeed = 0.5f; mesh = new Mesh(true, 4, 6, new VertexAttribute(VertexAttributes.Usage.Position, 3,"attr_Position"), new VertexAttribute(Usage.TextureCoordinates, 2, "attr_texCoords")); texture = new Texture(Gdx.files.internal("data/Jellyfish.jpg")); mesh.setVertices(new float[] { -1024f, -1024f, 0, 0, 1, 1024f, -1024f, 0, 1, 1, 1024f, 1024f, 0, 1, 0, -1024f, 1024f, 0, 0, 0 }); mesh.setIndices(new short[] { 0, 1, 2, 2, 3, 0 }); cam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); xScale = Gdx.graphics.getWidth()/(float)TARGET_WIDTH; yScale = Gdx.graphics.getHeight()/(float)TARGET_HEIGHT; font = loadBitmapFont("default.fnt", "default.png"); scale = Math.min(xScale, yScale); cam.zoom = 1/scale; // cam.project(start_position); cam.position.set(0, 0, 0); batch = new SpriteBatch(); }
/** * Instantiates a new ShaderEffect. The ShaderEffect will NOT own shader * program, so it will not dispose it either! * * @param program * the ShaderProgram to use for this effect */ public ShaderEffect(ShaderProgram program) { this.program = program; if (meshRefCount++ <= 0) { mesh = new Mesh(VertexDataType.VertexArray, true, 4, 0, new VertexAttribute(Usage.Position, 2, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0")); // @formatter:off float[] verts = { // vertex texture -1, -1, 0f, 0f, 1, -1, 1f, 0f, 1, 1, 1f, 1f, -1, 1, 0f, 1f, }; // @formatter:on mesh.setVertices(verts); } }
public void rebuildModel(Chunk chunk) { // System.out.println("m"+c.x+" "+c.z); if (chunk != c) { System.out .println("On essais de build le model du mauvais chunk !"); return; } if (c.disposed) { return;// disposed... } Mesh ancienMeshSol = c.modelSol; c.modelSol = buildModelSol(); if (ancienMeshSol != null) { ancienMeshSol.dispose(); } c.changed = true; }
public void init() { final int numVertices = this.vertexResolution * this.vertexResolution; final int numIndices = (this.vertexResolution-1) * (this.vertexResolution-1) * 6; mesh = new Mesh(true, numVertices, numIndices, attribs); this.vertices = new float[numVertices * stride]; mesh.setIndices(buildIndices()); buildVertices(); mesh.setVertices(vertices); MeshPart meshPart = new MeshPart(null, mesh, 0, numIndices, GL30.GL_TRIANGLES); meshPart.update(); ModelBuilder mb = new ModelBuilder(); mb.begin(); mb.part(meshPart, material); model = mb.end(); modelInstance = new ModelInstance(model); modelInstance.transform = transform; }
public PositionalLight (RayHandler rayHandler, int rays, Color color, float distance, float x, float y, float directionDegree) { super(rayHandler, rays, color, directionDegree, distance); start.x = x; start.y = y; sin = new float[rays]; cos = new float[rays]; endX = new float[rays]; endY = new float[rays]; lightMesh = new Mesh(VertexDataType.VertexArray, false, vertexNum, 0, new VertexAttribute(Usage.Position, 2, "vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"), new VertexAttribute(Usage.Generic, 1, "s")); softShadowMesh = new Mesh(VertexDataType.VertexArray, false, vertexNum * 2, 0, new VertexAttribute(Usage.Position, 2, "vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"), new VertexAttribute(Usage.Generic, 1, "s")); setMesh(); }
/** Directional lights simulate light source that locations is at infinite distance. Direction and intensity is same everywhere. * -90 direction is straight from up. * * @param rayHandler * @param rays * @param color * @param directionDegree */ public DirectionalLight (RayHandler rayHandler, int rays, Color color, float directionDegree) { super(rayHandler, rays, color, directionDegree, Float.POSITIVE_INFINITY); vertexNum = (vertexNum - 1) * 2; start = new Vector2[rayNum]; end = new Vector2[rayNum]; for (int i = 0; i < rayNum; i++) { start[i] = new Vector2(); end[i] = new Vector2(); } setDirection(direction); lightMesh = new Mesh(VertexDataType.VertexArray, staticLight, vertexNum, 0, new VertexAttribute(Usage.Position, 2, "vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"), new VertexAttribute(Usage.Generic, 1, "s")); softShadowMesh = new Mesh(VertexDataType.VertexArray, staticLight, vertexNum, 0, new VertexAttribute(Usage.Position, 2, "vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"), new VertexAttribute(Usage.Generic, 1, "s")); update(); }
/** Creates chain light from specified vertices * * @param rayHandler not {@code null} instance of RayHandler * @param rays number of rays - more rays make light to look more realistic but will decrease performance, can't be less than * MIN_RAYS * @param color color, set to {@code null} to use the default color * @param distance distance of light * @param rayDirection direction of rays * <ul> * <li>1 = left</li> * <li>-1 = right</li> * </ul> * @param chain float array of (x, y) vertices from which rays will be evenly distributed */ public RavChainLight (RayHandler rayHandler, int rays, Color color, float distance, int rayDirection, float[] chain) { super(rayHandler, rays, color, distance, 0f); rayStartOffset = ChainLight.defaultRayStartOffset; this.rayDirection = rayDirection; vertexNum = (vertexNum - 1) * 2; endX = new float[rays]; endY = new float[rays]; startX = new float[rays]; startY = new float[rays]; this.chain = (chain != null) ? new FloatArray(chain) : new FloatArray(); lightMesh = new Mesh(VertexDataType.VertexArray, false, vertexNum, 0, new VertexAttribute(Usage.Position, 2, "vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"), new VertexAttribute(Usage.Generic, 1, "s")); softShadowMesh = new Mesh(VertexDataType.VertexArray, false, vertexNum * 2, 0, new VertexAttribute(Usage.Position, 2, "vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"), new VertexAttribute(Usage.Generic, 1, "s")); setMesh(); }
/** * Generates a convex hull based on the model as the shape */ public EntityConstructor(String name, Model model, float mass, boolean disableDeactivation) { Mesh modelMesh = model.meshes.get(0); btCollisionShape shape = new btConvexHullShape(modelMesh.getVerticesBuffer(), modelMesh.getNumVertices(), modelMesh.getVertexSize()); // btTriangleIndexVertexArray i = new btTriangleIndexVertexArray(model.meshParts); // btGImpactMeshShape shapeImp = new btGImpactMeshShape(i); // // shapeImp.setLocalScaling(new Vector3(1f, 1f, 1f)); // shapeImp.setMargin(0.05f); // shapeImp.updateBound(); // optimizing the shape // btShapeHull hull = new btShapeHull((btConvexShape) shape); // hull.buildHull(shape.getMargin()); // shape = new btConvexHullShape(hull); // btCompoundShape shape = new btCompoundShape(); // shape.addChildShape(new Matrix4(), shapeImp); createConstructionInfo(name, model, mass, shape, disableDeactivation); }
public void init() { final int numVertices = this.vertexResolution * vertexResolution; final int numIndices = (this.vertexResolution - 1) * (vertexResolution - 1) * 6; mesh = new Mesh(true, numVertices, numIndices, attribs); this.vertices = new float[numVertices * stride]; mesh.setIndices(buildIndices()); buildVertices(); mesh.setVertices(vertices); MeshPart meshPart = new MeshPart(null, mesh, 0, numIndices, GL20.GL_TRIANGLES); meshPart.update(); ModelBuilder mb = new ModelBuilder(); mb.begin(); mb.part(meshPart, material); model = mb.end(); modelInstance = new ModelInstance(model); modelInstance.transform = transform; }
/** * Creates Vector3 objects from the vertices of the mesh. The resulting array follows the ordering of the provided * index array. * * @param mesh * @param indices * @return */ private static Vector3[] createVertexVectors(Mesh mesh, short[] indices) { FloatBuffer verticesBuffer = mesh.getVerticesBuffer(); int positionOffset = mesh.getVertexAttributes().findByUsage(VertexAttributes.Usage.Position).offset / 4; int vertexSize = mesh.getVertexSize() / 4; Vector3[] vertexVectors = new Vector3[mesh.getNumIndices()]; for (int i = 0; i < indices.length; i++) { short index = indices[i]; int a = index * vertexSize + positionOffset; float x = verticesBuffer.get(a++); float y = verticesBuffer.get(a++); float z = verticesBuffer.get(a); vertexVectors[index] = new Vector3(x, y, z); } return vertexVectors; }
public static Model createInfiniteWaterPart(TypeInterpreter interpreter, int landscapeIndex, PlanetConfig planetConfig) { ModelBuilder modelBuilder = new ModelBuilder(); MeshBuilder builder = new MeshBuilder(); float waterHeight = interpreter.it.get(landscapeIndex).endValue; builder.begin(PlanetPart.VERTEX_ATTRIBUTES, GL20.GL_TRIANGLES); infiniteWaterHeight = waterHeight * planetConfig.landscapeHeight - 1; Vector3 corner01 = new Vector3(-INFINITE_WATER_SIZE, -INFINITE_WATER_SIZE, infiniteWaterHeight); Vector3 corner02 = new Vector3(INFINITE_WATER_SIZE, -INFINITE_WATER_SIZE, infiniteWaterHeight); Vector3 corner03 = new Vector3(INFINITE_WATER_SIZE, INFINITE_WATER_SIZE, infiniteWaterHeight); Vector3 corner04 = new Vector3(-INFINITE_WATER_SIZE, INFINITE_WATER_SIZE, infiniteWaterHeight); builder.rect(corner01, corner02, corner03, corner04, new Vector3(0, 0, 1)); Material waterMaterial = planetConfig.layerConfigs.get(landscapeIndex).material; Mesh mesh = builder.end(); modelBuilder.begin(); modelBuilder.part(PlanetPart.LANDSCAPE_PART_NAME + landscapeIndex, mesh, GL20.GL_TRIANGLES, waterMaterial); return modelBuilder.end(); }
/** * Creates a water plane. * @param chunk The chunk. */ private void createWaterPart(Chunk chunk, int landscapeIndex) { MeshBuilder builder = meshBuilders.get(landscapeIndex); float WATER_HEIGHT = interpreter.it.get(landscapeIndex).endValue; builder.begin(VERTEX_ATTRIBUTES, GL20.GL_TRIANGLES); float z = WATER_HEIGHT * planetConfig.landscapeHeight; float width = chunk.getWidth() * tileSize; float height = chunk.getHeight() * tileSize; Vector3 corner01 = new Vector3(0f, 0f, z); Vector3 corner02 = new Vector3(width, 0f, z); Vector3 corner03 = new Vector3(width, height, z); Vector3 corner04 = new Vector3(0f, height, z); builder.rect(corner01, corner02, corner03, corner04, new Vector3(0, 0, 1)); Material waterMaterial = planetConfig.layerConfigs.get(landscapeIndex).material; Mesh mesh = builder.end(); modelBuilder.node().id = LANDSCAPE_NODE_NAME + landscapeIndex; modelBuilder.part(LANDSCAPE_PART_NAME + landscapeIndex, mesh, GL20.GL_TRIANGLES, waterMaterial); }
private void buildMesh() { mesh = new Mesh(true, SIZE, 6, VertexAttribute.Position(), VertexAttribute.TexCoords(0)); mesh.setVertices(vertices); short[] indices = new short[6]; int v = 0; for (int i = 0; i < indices.length; i += 6, v += 4) { indices[i] = (short)(v); indices[i + 1] = (short)(v + 2); indices[i + 2] = (short)(v + 1); indices[i + 3] = (short)(v + 1); indices[i + 4] = (short)(v + 2); indices[i + 5] = (short)(v + 3); } mesh.setIndices(indices); }
public static Mesh build(float size, TextureRegion region) { Mesh mesh = new Mesh(true, SIZE, 6, VertexAttribute.Position(), VertexAttribute.TexCoords(0)); mesh.setVertices(verticies(size, region)); mesh.setAutoBind(false); short[] indices = new short[6]; int v = 0; for (int i = 0; i < indices.length; i += 6, v += 4) { indices[i] = (short)(v); indices[i + 1] = (short)(v + 2); indices[i + 2] = (short)(v + 1); indices[i + 3] = (short)(v + 1); indices[i + 4] = (short)(v + 2); indices[i + 5] = (short)(v + 3); } mesh.setIndices(indices); return mesh; }
public ImmediateModeRenderer20 (int maxVertices, boolean hasNormals, boolean hasColors, int numTexCoords, ShaderProgram shader) { this.maxVertices = maxVertices; this.numTexCoords = numTexCoords; this.shader = shader; VertexAttribute[] attribs = buildVertexAttributes(hasNormals, hasColors, numTexCoords); mesh = new Mesh(false, maxVertices, 0, attribs); vertices = new float[maxVertices * (mesh.getVertexAttributes().vertexSize / 4)]; vertexSize = mesh.getVertexAttributes().vertexSize / 4; normalOffset = mesh.getVertexAttribute(Usage.Normal) != null ? mesh.getVertexAttribute(Usage.Normal).offset / 4 : 0; colorOffset = mesh.getVertexAttribute(Usage.ColorPacked) != null ? mesh.getVertexAttribute(Usage.ColorPacked).offset / 4 : 0; texCoordOffset = mesh.getVertexAttribute(Usage.TextureCoordinates) != null ? mesh .getVertexAttribute(Usage.TextureCoordinates).offset / 4 : 0; shaderUniformNames = new String[numTexCoords]; for (int i = 0; i < numTexCoords; i++) { shaderUniformNames[i] = "u_sampler" + i; } }
/** Initializes the batch with the given amount of decal objects the buffer is able to hold when full. * * @param size Maximum size of decal objects to hold in memory */ public void initialize (int size) { vertices = new float[size * Decal.SIZE]; mesh = new Mesh(Mesh.VertexDataType.VertexArray, false, size * 4, size * 6, new VertexAttribute( VertexAttributes.Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute( VertexAttributes.Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE), new VertexAttribute( VertexAttributes.Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0")); short[] indices = new short[size * 6]; int v = 0; for (int i = 0; i < indices.length; i += 6, v += 4) { indices[i] = (short)(v); indices[i + 1] = (short)(v + 2); indices[i + 2] = (short)(v + 1); indices[i + 3] = (short)(v + 1); indices[i + 4] = (short)(v + 2); indices[i + 5] = (short)(v + 3); } mesh.setIndices(indices); }
@Deprecated public static Model createFromMesh (final Mesh mesh, int indexOffset, int vertexCount, int primitiveType, final Material material) { Model result = new Model(); MeshPart meshPart = new MeshPart(); meshPart.id = "part1"; meshPart.indexOffset = indexOffset; meshPart.numVertices = vertexCount; meshPart.primitiveType = primitiveType; meshPart.mesh = mesh; NodePart partMaterial = new NodePart(); partMaterial.material = material; partMaterial.meshPart = meshPart; Node node = new Node(); node.id = "node1"; node.parts.add(partMaterial); result.meshes.add(mesh); result.materials.add(material); result.nodes.add(node); result.meshParts.add(meshPart); result.manageDisposable(mesh); return result; }
/** End building the mesh and returns the mesh */ public Mesh end () { if (this.attributes == null) throw new RuntimeException("Call begin() first"); endpart(); final Mesh mesh = new Mesh(true, vertices.size / stride, indices.size, attributes); mesh.setVertices(vertices.items, 0, vertices.size); mesh.setIndices(indices.items, 0, indices.size); for (MeshPart p : parts) p.mesh = mesh; parts.clear(); attributes = null; vertices.clear(); indices.clear(); return mesh; }
@Override public void setMesh(Mesh mesh, Model model){ super.setMesh(mesh, model); vertexSize = mesh.getVertexSize()/4; positionOffset = mesh.getVertexAttribute(Usage.Position).offset/4; int indicesCount = mesh.getNumIndices(); if(indicesCount >0){ indices = new short[indicesCount]; mesh.getIndices(indices); triangleCount = indices.length/3; } else indices = null; vertexCount = mesh.getNumVertices(); vertices = new float[ vertexCount* vertexSize]; mesh.getVertices(vertices); }
/** Constructs a new PolygonSpriteBatch. Sets the projection matrix to an orthographic projection with y-axis point upwards, * x-axis point to the right and the origin being in the bottom left corner of the screen. The projection will be pixel perfect * with respect to the current screen resolution. * <p> * The defaultShader specifies the shader to use. Note that the names for uniforms for this default shader are different than * the ones expect for shaders set with {@link #setShader(ShaderProgram)}. See {@link SpriteBatch#createDefaultShader()}. * @param size The max number of vertices and number of triangles in a single batch. Max of 10920. * @param defaultShader The default shader to use. This is not owned by the PolygonSpriteBatch and must be disposed separately. */ public PolygonSpriteBatch (int size, ShaderProgram defaultShader) { // 32767 is max index, so 32767 / 3 - (32767 / 3 % 3) = 10920. if (size > 10920) throw new IllegalArgumentException("Can't have more than 10920 triangles per batch: " + size); mesh = new Mesh(VertexDataType.VertexArray, false, size, size * 3, new VertexAttribute(Usage.Position, 2, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0")); vertices = new float[size * VERTEX_SIZE]; triangles = new short[size * 3]; if (defaultShader == null) { shader = SpriteBatch.createDefaultShader(); ownsShader = true; } else shader = defaultShader; projectionMatrix.setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); }
@Override public void flush () { if (vertexIndex == 0) return; renderCalls++; totalRenderCalls++; int trianglesInBatch = triangleIndex; if (trianglesInBatch > maxTrianglesInBatch) maxTrianglesInBatch = trianglesInBatch; lastTexture.bind(); Mesh mesh = this.mesh; mesh.setVertices(vertices, 0, vertexIndex); mesh.setIndices(triangles, 0, triangleIndex); if (blendingDisabled) { Gdx.gl.glDisable(GL20.GL_BLEND); } else { Gdx.gl.glEnable(GL20.GL_BLEND); if (blendSrcFunc != -1) Gdx.gl.glBlendFunc(blendSrcFunc, blendDstFunc); } mesh.render(customShader != null ? customShader : shader, GL20.GL_TRIANGLES, 0, trianglesInBatch); vertexIndex = 0; triangleIndex = 0; }
@Override public void onSurfaceCreated (javax.microedition.khronos.opengles.GL10 gl, EGLConfig config) { eglContext = ((EGL10)EGLContext.getEGL()).eglGetCurrentContext(); setupGL(gl); logConfig(config); updatePpi(); Mesh.invalidateAllMeshes(app); Texture.invalidateAllTextures(app); Cubemap.invalidateAllCubemaps(app); ShaderProgram.invalidateAllShaderPrograms(app); FrameBuffer.invalidateAllFrameBuffers(app); logManagedCachesStatus(); Display display = app.getWindowManager().getDefaultDisplay(); this.width = display.getWidth(); this.height = display.getHeight(); this.mean = new WindowedMean(5); this.lastFrameTime = System.nanoTime(); gl.glViewport(0, 0, this.width, this.height); }
@Override public void getRenderables (Array<Renderable> renderables, Pool<Renderable> pool) { renderedChunks = 0; for (int i = 0; i < chunks.length; i++) { VoxelChunk chunk = chunks[i]; Mesh mesh = meshes[i]; if (dirty[i]) { int numVerts = chunk.calculateVertices(vertices); numVertices[i] = numVerts / 4 * 6; mesh.setVertices(vertices, 0, numVerts * VoxelChunk.VERTEX_SIZE); dirty[i] = false; } if (numVertices[i] == 0) continue; Renderable renderable = pool.obtain(); renderable.material = materials[i]; renderable.mesh = mesh; renderable.meshPartOffset = 0; renderable.meshPartSize = numVertices[i]; renderable.primitiveType = GL20.GL_TRIANGLES; renderables.add(renderable); renderedChunks++; } }
public void setupScene () { plane = new Mesh(true, 4, 6, new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute( Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE)); plane.setVertices(new float[] {-10, -1, 10, 0, 1, 0, 10, -1, 10, 0, 1, 0, 10, -1, -10, 0, 1, 0, -10, -1, -10, 0, 1, 0}); plane.setIndices(new short[] {3, 2, 1, 1, 0, 3}); texture = new Texture(Gdx.files.internal("data/badlogic.jpg"), Format.RGB565, true); texture.setFilter(TextureFilter.MipMap, TextureFilter.Nearest); cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); cam.position.set(0, 5, 10); cam.lookAt(0, 0, 0); cam.update(); controller = new PerspectiveCamController(cam); projector = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); projector.position.set(2, 3, 2); projector.lookAt(0, 0, 0); projector.normalizeUp(); projector.update(); }
@Override public void create () { String vertexShader = "attribute vec4 a_position; \n" + "attribute vec4 a_color;\n" + "attribute vec2 a_texCoord0;\n" + "uniform mat4 u_worldView;\n" + "varying vec4 v_color;" + "varying vec2 v_texCoords;" + "void main() \n" + "{ \n" + " v_color = vec4(1, 1, 1, 1); \n" + " v_texCoords = a_texCoord0; \n" + " gl_Position = u_worldView * a_position; \n" + "} \n"; String fragmentShader = "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n" + "varying vec4 v_color;\n" + "varying vec2 v_texCoords;\n" + "uniform sampler2D u_texture;\n" + "void main() \n" + "{ \n" + " gl_FragColor = v_color * texture2D(u_texture, v_texCoords);\n" + "}"; shader = new ShaderProgram(vertexShader, fragmentShader); if (shader.isCompiled() == false) { Gdx.app.log("ShaderTest", shader.getLog()); Gdx.app.exit(); } mesh = new Mesh(true, 4, 6, VertexAttribute.Position(), VertexAttribute.ColorUnpacked(), VertexAttribute.TexCoords(0)); mesh.setVertices(new float[] {-0.5f, -0.5f, 0, 1, 1, 1, 1, 0, 1, 0.5f, -0.5f, 0, 1, 1, 1, 1, 1, 1, 0.5f, 0.5f, 0, 1, 1, 1, 1, 1, 0, -0.5f, 0.5f, 0, 1, 1, 1, 1, 0, 0}); mesh.setIndices(new short[] {0, 1, 2, 2, 3, 0}); texture = new Texture(Gdx.files.internal("data/bobrgb888-32x32.png")); }
@Override public void create () { mesh = new Mesh(true, 3, 0, new VertexAttribute(Usage.Position, 3, "a_Position"), new VertexAttribute(Usage.ColorPacked, 4, "a_Color"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords")); float c1 = Color.toFloatBits(255, 0, 0, 255); float c2 = Color.toFloatBits(255, 0, 0, 255); float c3 = Color.toFloatBits(0, 0, 255, 255); mesh.setVertices(new float[] {-0.5f, -0.5f, 0, c1, 0, 0, 0.5f, -0.5f, 0, c2, 1, 0, 0, 0.5f, 0, c3, 0.5f, 1}); stencilMesh = new Mesh(true, 3, 0, new VertexAttribute(Usage.Position, 3, "a_Position"), new VertexAttribute( Usage.ColorPacked, 4, "a_Color"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords")); stencilMesh.setVertices(new float[] {-0.5f, 0.5f, 0, c1, 0, 0, 0.5f, 0.5f, 0, c2, 1, 0, 0, -0.5f, 0, c3, 0.5f, 1}); texture = new Texture(Gdx.files.internal("data/badlogic.jpg")); spriteBatch = new SpriteBatch(); frameBuffer = new FrameBuffer(Format.RGB565, 128, 128, false); stencilFrameBuffer = new FrameBuffer(Format.RGB565, 128, 128, false, true); createShader(Gdx.graphics); }
private void init(String tex0, float w, float h) { setTexture0(tex0); // Init comparator comp = new DistToCameraComparator<IRenderable>(); // Init vertices float[] vertices = new float[20]; fillVertices(vertices, w, h); // We wont need indices if we use GL_TRIANGLE_FAN to draw our quad // TRIANGLE_FAN will draw the verts in this order: 0, 1, 2; 0, 2, 3 mesh = new Mesh(VertexDataType.VertexArray, true, 4, 6, new VertexAttribute(Usage.Position, 2, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0")); mesh.setVertices(vertices, 0, vertices.length); mesh.getIndicesBuffer().position(0); mesh.getIndicesBuffer().limit(6); short[] indices = new short[] { 0, 1, 2, 0, 2, 3 }; mesh.setIndices(indices); quaternion = new Quaternion(); aux = new Vector3(); }
@Override protected void initVertices() { meshes = new MeshData[2]; maxVertices = MAX_VERTICES; // ORIGINAL LINES curr = new MeshData(); meshes[0] = curr; VertexAttribute[] attribs = buildVertexAttributes(); curr.mesh = new Mesh(false, maxVertices, 0, attribs); curr.vertices = new float[maxVertices * (curr.mesh.getVertexAttributes().vertexSize / 4)]; curr.vertexSize = curr.mesh.getVertexAttributes().vertexSize / 4; curr.colorOffset = curr.mesh.getVertexAttribute(Usage.ColorPacked) != null ? curr.mesh.getVertexAttribute(Usage.ColorPacked).offset / 4 : 0; }
private void initVertices(int index) { if (meshes[index] == null) { currext = new MeshDataExt(); meshes[index] = currext; curr = currext; maxVertices = MAX_VERTICES; currext.maxIndices = maxVertices + maxVertices / 2; VertexAttribute[] attribs = buildVertexAttributes(); currext.mesh = new Mesh(Mesh.VertexDataType.VertexArray, false, maxVertices, currext.maxIndices, attribs); currext.indices = new short[currext.maxIndices]; currext.vertexSize = currext.mesh.getVertexAttributes().vertexSize / 4; currext.vertices = new float[maxVertices * currext.vertexSize]; currext.colorOffset = currext.mesh.getVertexAttribute(Usage.ColorPacked) != null ? currext.mesh.getVertexAttribute(Usage.ColorPacked).offset / 4 : 0; currext.uvOffset = currext.mesh.getVertexAttribute(Usage.TextureCoordinates) != null ? currext.mesh.getVertexAttribute(Usage.TextureCoordinates).offset / 4 : 0; } else { currext = (MeshDataExt) meshes[index]; curr = currext; } }
@Override protected void initVertices() { meshes = new MeshData[1]; curr = new MeshData(); meshes[0] = curr; aux = new Vector3(); /** Init renderer **/ maxVertices = 3000000; VertexAttribute[] attribs = buildVertexAttributes(); curr.mesh = new Mesh(false, maxVertices, 0, attribs); curr.vertices = new float[maxVertices * (curr.mesh.getVertexAttributes().vertexSize / 4)]; curr.vertexSize = curr.mesh.getVertexAttributes().vertexSize / 4; curr.colorOffset = curr.mesh.getVertexAttribute(Usage.ColorPacked) != null ? curr.mesh.getVertexAttribute(Usage.ColorPacked).offset / 4 : 0; pmOffset = curr.mesh.getVertexAttribute(Usage.Tangent) != null ? curr.mesh.getVertexAttribute(Usage.Tangent).offset / 4 : 0; sizeOffset = curr.mesh.getVertexAttribute(Usage.Generic) != null ? curr.mesh.getVertexAttribute(Usage.Generic).offset / 4 : 0; }
private void init(float w, float h) { // Init comparator comp = new DistToCameraComparator<IRenderable>(); // Init vertices float[] vertices = new float[20]; fillVertices(vertices, w, h); // We wont need indices if we use GL_TRIANGLE_FAN to draw our quad // TRIANGLE_FAN will draw the verts in this order: 0, 1, 2; 0, 2, 3 mesh = new Mesh(VertexDataType.VertexArray, true, 4, 6, new VertexAttribute(Usage.Position, 2, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0")); mesh.setVertices(vertices, 0, vertices.length); mesh.getIndicesBuffer().position(0); mesh.getIndicesBuffer().limit(6); short[] indices = new short[] { 0, 1, 2, 0, 2, 3 }; mesh.setIndices(indices); quaternion = new Quaternion(); aux = new Vector3(); }
@Override protected void initVertices() { /** STARS **/ meshes = new MeshData[1]; curr = new MeshData(); meshes[0] = curr; aux1 = new Vector3(); maxVertices = 10000000; VertexAttribute[] attribs = buildVertexAttributes(); curr.mesh = new Mesh(false, maxVertices, 0, attribs); curr.vertices = new float[maxVertices * (curr.mesh.getVertexAttributes().vertexSize / 4)]; curr.vertexSize = curr.mesh.getVertexAttributes().vertexSize / 4; curr.colorOffset = curr.mesh.getVertexAttribute(Usage.ColorPacked) != null ? curr.mesh.getVertexAttribute(Usage.ColorPacked).offset / 4 : 0; pmOffset = curr.mesh.getVertexAttribute(Usage.Tangent) != null ? curr.mesh.getVertexAttribute(Usage.Tangent).offset / 4 : 0; additionalOffset = curr.mesh.getVertexAttribute(Usage.Generic) != null ? curr.mesh.getVertexAttribute(Usage.Generic).offset / 4 : 0; }
/** * Billboard quad render, for planets and stars. */ @Override public void render(ShaderProgram shader, float alpha, Mesh mesh, ICamera camera) { compalpha = alpha; float size = getFuzzyRenderSize(camera); Vector3 aux = aux3f1.get(); shader.setUniformf("u_pos", transform.getTranslationf(aux)); shader.setUniformf("u_size", size); shader.setUniformf("u_color", ccPale[0], ccPale[1], ccPale[2], alpha * opacity); shader.setUniformf("u_inner_rad", getInnerRad()); shader.setUniformf("u_distance", (float) distToCamera); shader.setUniformf("u_apparent_angle", (float) viewAngleApparent); shader.setUniformf("u_thpoint", (float) THRESHOLD_POINT() * camera.getFovFactor()); // Whether light scattering is enabled or not shader.setUniformi("u_lightScattering", (this instanceof Star && PostProcessorFactory.instance.getPostProcessor().isLightScatterEnabled()) ? 1 : 0); shader.setUniformf("u_radius", (float) getRadius()); // Sprite.render mesh.render(shader, GL20.GL_TRIANGLES, 0, 6); }
/** * Quad rendering */ @Override public void render(ShaderProgram shader, float alpha, Mesh mesh, ICamera camera) { double thpointTimesFovfactor = GlobalConf.scene.STAR_THRESHOLD_POINT * camera.getFovFactor() * .5e-1f; double thupOverFovfactor = Constants.THRESHOLD_UP / camera.getFovFactor(); double thdownOverFovfactor = Constants.THRESHOLD_DOWN / camera.getFovFactor(); double innerRad = 0.006 + GlobalConf.scene.STAR_POINT_SIZE * 0.008; float alph = alpha * this.opacity; /** GENERAL UNIFORMS **/ shader.setUniformf("u_thpoint", (float) GlobalConf.scene.STAR_THRESHOLD_POINT * camera.getFovFactor()); // Light glow always disabled with star groups shader.setUniformi("u_lightScattering", 0); shader.setUniformf("u_inner_rad", (float) innerRad); /** RENDER ACTUAL STARS **/ boolean focusRendered = false; for (int i = 0; i < N_CLOSEUP_STARS; i++) { renderCloseupStar(i, active[i], camera, shader, mesh, thpointTimesFovfactor, thupOverFovfactor, thdownOverFovfactor, alph); focusRendered = focusRendered || active[i] == focusIndex; } if (focus != null && !focusRendered) { renderCloseupStar(1, focusIndex, camera, shader, mesh, thpointTimesFovfactor, thupOverFovfactor, thdownOverFovfactor, alph); } }
/** * Billboard quad rendering */ @Override public void render(ShaderProgram shader, float alpha, Mesh mesh, ICamera camera) { // Bind texture if (clusterTex != null) { clusterTex.bind(0); shader.setUniformi("u_texture0", 0); } float fa = 1 - fadeAlpha; Vector3 aux = aux3f1.get(); shader.setUniformf("u_pos", transform.getTranslationf(aux)); shader.setUniformf("u_size", size); shader.setUniformf("u_color", col[0] * fa, col[1] * fa, col[2] * fa, col[3] * alpha * opacity * 4f); // Sprite.render mesh.render(shader, GL20.GL_TRIANGLES, 0, 6); }
/** * Billboard quad rendering */ @Override public void render(ShaderProgram shader, float alpha, Mesh mesh, ICamera camera) { compalpha = alpha; float size = getFuzzyRenderSize(camera); Vector3 aux = aux3f1.get(); shader.setUniformf("u_pos", transform.getTranslationf(aux)); shader.setUniformf("u_size", size); shader.setUniformf("u_color", cc[0], cc[1], cc[2], alpha * (1 - fadeOpacity)); shader.setUniformf("u_inner_rad", getInnerRad()); shader.setUniformf("u_distance", (float) distToCamera); shader.setUniformf("u_apparent_angle", (float) viewAngleApparent); shader.setUniformf("u_thpoint", (float) THRESHOLD_POINT() * camera.getFovFactor()); // Whether light scattering is enabled or not shader.setUniformi("u_lightScattering", 0); shader.setUniformf("u_radius", (float) getRadius()); // Sprite.render mesh.render(shader, GL20.GL_TRIANGLES, 0, 6); }
/** End building the mesh and returns the mesh */ public Mesh end() { if (this.attributes == null) throw new RuntimeException("Call begin() first"); endpart(); final Mesh mesh = new Mesh(true, vertices.size / stride, indices.size, attributes); mesh.setVertices(vertices.items, 0, vertices.size); mesh.setIndices(indices.items, 0, indices.size); for (MeshPart p : parts) p.mesh = mesh; parts.clear(); attributes = null; vertices.clear(); indices.clear(); return mesh; }
public ImmediateRenderer(int maxVertices, boolean hasNormals, boolean hasColors, int numTexCoords, ShaderProgram shader) { this.maxVertices = maxVertices; this.numTexCoords = numTexCoords; this.shader = shader; VertexAttribute[] attribs = buildVertexAttributes(hasNormals, hasColors, numTexCoords); mesh = new Mesh(false, maxVertices, 0, attribs); vertices = new float[maxVertices * (mesh.getVertexAttributes().vertexSize / 4)]; vertexSize = mesh.getVertexAttributes().vertexSize / 4; normalOffset = mesh.getVertexAttribute(Usage.Normal) != null ? mesh.getVertexAttribute(Usage.Normal).offset / 4 : 0; colorOffset = mesh.getVertexAttribute(Usage.ColorPacked) != null ? mesh.getVertexAttribute(Usage.ColorPacked).offset / 4 : 0; texCoordOffset = mesh.getVertexAttribute(Usage.TextureCoordinates) != null ? mesh.getVertexAttribute(Usage.TextureCoordinates).offset / 4 : 0; shaderUniformNames = new String[numTexCoords]; for (int i = 0; i < numTexCoords; i++) { shaderUniformNames[i] = "u_sampler" + i; } }
@Deprecated public static Model createFromMesh(final Mesh mesh, int indexOffset, int vertexCount, int primitiveType, final Material material) { Model result = new Model(); MeshPart meshPart = new MeshPart(); meshPart.id = "part1"; meshPart.offset = indexOffset; meshPart.size = vertexCount; meshPart.primitiveType = primitiveType; meshPart.mesh = mesh; NodePart partMaterial = new NodePart(); partMaterial.material = material; partMaterial.meshPart = meshPart; Node node = new Node(); node.id = "node1"; node.parts.add(partMaterial); result.meshes.add(mesh); result.materials.add(material); result.nodes.add(node); result.meshParts.add(meshPart); result.manageDisposable(mesh); return result; }
public Renderer20 (int maxVertices, boolean hasNormals, boolean hasColors, int numTexCoords, ShaderProgram shader) { this.maxVertices = maxVertices; this.numTexCoords = numTexCoords; this.shader = shader; VertexAttribute[] attribs = buildVertexAttributes(hasNormals, hasColors, numTexCoords); mesh = new Mesh(false, maxVertices, 0, attribs); vertices = new float[maxVertices * (mesh.getVertexAttributes().vertexSize / 4)]; vertexSize = mesh.getVertexAttributes().vertexSize / 4; normalOffset = mesh.getVertexAttribute(Usage.Normal) != null ? mesh.getVertexAttribute(Usage.Normal).offset / 4 : 0; colorOffset = mesh.getVertexAttribute(Usage.ColorPacked) != null ? mesh.getVertexAttribute(Usage.ColorPacked).offset / 4 : 0; texCoordOffset = mesh.getVertexAttribute(Usage.TextureCoordinates) != null ? mesh .getVertexAttribute(Usage.TextureCoordinates).offset / 4 : 0; }