/** Binds the material's texture to the OpenGL context and changes the glBlendFunc to the values used by it. */ public void set () { textureRegion.getTexture().bind(0); if (!isOpaque()) { Gdx.gl.glBlendFunc(srcBlendFactor, dstBlendFactor); } }
/** Binds the material's texture to the OpenGL context and changes the glBlendFunc to the values used by it. */ public void set () { textureRegion.getTexture().bind(0); if (!isOpaque()) { Gdx.gl.glBlendFunc(srcBlendFactor, dstBlendFactor); } }
/** Draws all the images defined for the specified cache ID. */ public void draw (int cacheID) { if (!drawing) throw new IllegalStateException("SpriteCache.begin must be called before draw."); Cache cache = caches.get(cacheID); int verticesPerImage = mesh.getNumIndices() > 0 ? 4 : 6; int offset = cache.offset / (verticesPerImage * VERTEX_SIZE) * 6; Texture[] textures = cache.textures; int[] counts = cache.counts; int textureCount = cache.textureCount; for (int i = 0; i < textureCount; i++) { int count = counts[i]; textures[i].bind(); if (customShader != null) mesh.render(customShader, GL20.GL_TRIANGLES, offset, count); else mesh.render(shader, GL20.GL_TRIANGLES, offset, count); offset += count; } renderCalls += textureCount; totalRenderCalls += textureCount; }
/** Draws all the images defined for the specified cache ID. */ public void draw (int cacheID) { if (!drawing) throw new IllegalStateException("SpriteCache.begin must be called before draw."); Cache cache = caches.get(cacheID); int verticesPerImage = mesh.getNumIndices() > 0 ? 4 : 6; int offset = cache.offset / (verticesPerImage * VERTEX_SIZE) * 6; Texture[] textures = cache.textures; int[] counts = cache.counts; int textureCount = cache.textureCount; for (int i = 0; i < textureCount; i++) { int count = counts[i]; textures[i].bind(); if (customShader != null) mesh.render(customShader, GL20.GL_TRIANGLES, offset, count); else mesh.render(shader, GL20.GL_TRIANGLES, offset, count); offset += count; } renderCalls += textureCount; totalRenderCalls += textureCount; }
public void render () { Gdx.gl20.glViewport(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight()); Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl20.glActiveTexture(GL20.GL_TEXTURE0); texture.bind(); Gdx.gl20.glActiveTexture(GL20.GL_TEXTURE1); texture2.bind(); shader.begin(); shader.setUniformi("s_texture", 0); shader.setUniformi("s_texture2", 1); mesh.render(shader, GL20.GL_TRIANGLES); shader.end(); }
@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.glBlendFuncSeparate(blendSrcFunc, blendDstFunc, blendSrcFuncAlpha, blendDstFuncAlpha); } mesh.render(customShader != null ? customShader : shader, GL20.GL_TRIANGLES, 0, trianglesInBatch); vertexIndex = 0; triangleIndex = 0; }
/** Draws the given {@link Pixmap} to the texture at position x, y. No clipping is performed so you have to make sure that you * draw only inside the texture region. Note that this will only draw to mipmap level 0! * * @param pixmap The Pixmap * @param x The x coordinate in pixels * @param y The y coordinate in pixels */ public void draw (Pixmap pixmap, int x, int y) { if (data.isManaged()) throw new GdxRuntimeException("can't draw to a managed texture"); bind(); Gdx.gl.glTexSubImage2D(glTarget, 0, x, y, pixmap.getWidth(), pixmap.getHeight(), pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels()); }
@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.glBlendFuncSeparate(blendSrcFunc, blendDstFunc, blendSrcFuncAlpha, blendDstFuncAlpha); } mesh.render(customShader != null ? customShader : shader, GL20.GL_TRIANGLES, 0, trianglesInBatch); vertexIndex = 0; triangleIndex = 0; }
/** Draws the given {@link Pixmap} to the texture at position x, y. No clipping is performed so you have to make sure that you * draw only inside the texture region. Note that this will only draw to mipmap level 0! * * @param pixmap The Pixmap * @param x The x coordinate in pixels * @param y The y coordinate in pixels */ public void draw (Pixmap pixmap, int x, int y) { if (data.isManaged()) throw new GdxRuntimeException("can't draw to a managed texture"); bind(); Gdx.gl.glTexSubImage2D(glTarget, 0, x, y, pixmap.getWidth(), pixmap.getHeight(), pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels()); }
public void load (TextureData data) { if (this.data != null && data.isManaged() != this.data.isManaged()) throw new GdxRuntimeException("New data must have the same managed status as the old data"); this.data = data; if (!data.isPrepared()) data.prepare(); bind(); uploadImageData(GL20.GL_TEXTURE_2D, data); unsafeSetFilter(minFilter, magFilter, true); unsafeSetWrap(uWrap, vWrap, true); Gdx.gl.glBindTexture(glTarget, 0); }
public void load (TextureData data) { if (this.data != null && data.isManaged() != this.data.isManaged()) throw new GdxRuntimeException("New data must have the same managed status as the old data"); this.data = data; if (!data.isPrepared()) data.prepare(); bind(); uploadImageData(GL20.GL_TEXTURE_2D, data); unsafeSetFilter(minFilter, magFilter, true); unsafeSetWrap(uWrap, vWrap, true); Gdx.gl.glBindTexture(glTarget, 0); }
Texture textureFromPixmap (Gdx2DPixmap pixmap) { Texture texture = new Texture(pixmap.getWidth(), pixmap.getHeight(), Format.RGB565); texture.bind(); Gdx.gl.glTexImage2D(GL20.GL_TEXTURE_2D, 0, pixmap.getGLInternalFormat(), pixmap.getWidth(), pixmap.getHeight(), 0, pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels()); return texture; }
@Override public void flush () { if (idx == 0) return; renderCalls++; totalRenderCalls++; int spritesInBatch = idx / 20; if (spritesInBatch > maxSpritesInBatch) maxSpritesInBatch = spritesInBatch; int count = spritesInBatch * 6; lastTexture.bind(); Mesh mesh = this.mesh; mesh.setVertices(vertices, 0, idx); mesh.getIndicesBuffer().position(0); mesh.getIndicesBuffer().limit(count); if (blendingDisabled) { Gdx.gl.glDisable(GL20.GL_BLEND); } else { Gdx.gl.glEnable(GL20.GL_BLEND); if (blendSrcFunc != -1) Gdx.gl.glBlendFuncSeparate(blendSrcFunc, blendDstFunc, blendSrcFuncAlpha, blendDstFuncAlpha); } mesh.render(customShader != null ? customShader : shader, GL20.GL_TRIANGLES, 0, count); idx = 0; }
@Override public void render () { // System.out.println( "render"); Gdx.gl.glViewport(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight()); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glEnable(GL20.GL_TEXTURE_2D); shader.begin(); shader.setUniformi("u_texture", 0); texture.bind(); vbo.bind(shader); ibo.bind(); Gdx.gl20.glDrawElements(GL20.GL_TRIANGLES, 3, GL20.GL_UNSIGNED_SHORT, 0); ibo.unbind(); vbo.unbind(shader); shader.end(); }
@Override public void render () { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glEnable(GL20.GL_TEXTURE_2D); texture.bind(); renderer.begin(projMatrix, GL20.GL_TRIANGLES); renderer.texCoord(0, 0); renderer.color(1, 0, 0, 1); renderer.vertex(-0.5f, -0.5f, 0); renderer.texCoord(1, 0); renderer.color(0, 1, 0, 1); renderer.vertex(0.5f, -0.5f, 0); renderer.texCoord(0.5f, 1); renderer.color(0, 0, 1, 1); renderer.vertex(0f, 0.5f, 0); renderer.end(); }
public void render () { Gdx.gl20.glViewport(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight()); Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl20.glActiveTexture(GL20.GL_TEXTURE0); texture.bind(); shader.begin(); shader.setUniformf("s_texture", 0); Gdx.gl20.glTexParameteri(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MIN_FILTER, GL20.GL_NEAREST); shader.setUniformf("u_offset", -0.6f); mesh.render(shader, GL20.GL_TRIANGLES); Gdx.gl20.glTexParameteri(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MIN_FILTER, GL20.GL_LINEAR_MIPMAP_LINEAR); shader.setUniformf("u_offset", 0.6f); mesh.render(shader, GL20.GL_TRIANGLES); shader.end(); } }
@Override public void render () { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glEnable(GL20.GL_TEXTURE_2D); camera.update(); currTexture = hwMipMap.isChecked() ? textureHW : textureSW; currTexture.bind(); currTexture.setFilter(TextureFilter.valueOf(minFilter.getSelected()), TextureFilter.valueOf(magFilter.getSelected())); shader.begin(); shader.setUniformMatrix("u_projTrans", camera.combined); shader.setUniformi("s_texture", 0); mesh.render(shader, GL20.GL_TRIANGLE_FAN); shader.end(); ui.act(); ui.draw(); }
@Override public void render () { GL20 gl = Gdx.gl20; gl.glViewport(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight()); Gdx.gl.glClearColor(0.7f, 0, 0, 1); gl.glClear(GL20.GL_COLOR_BUFFER_BIT); gl.glEnable(GL20.GL_TEXTURE_2D); shader.begin(); shader.setUniformi("u_texture", 0); texture.bind(); vbo.bind(shader); indices.bind(); gl.glDrawElements(GL20.GL_TRIANGLES, 3, GL20.GL_UNSIGNED_SHORT, indices.getBuffer().position()); indices.unbind(); vbo.unbind(shader); shader.end(); }
@Override public void render () { angle += Gdx.graphics.getDeltaTime() * 45; matrix.setToRotation(axis, angle); Mesh meshToDraw = Gdx.input.isButtonPressed(0) ? meshCustomVA : mesh; Gdx.gl20.glViewport(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight()); Gdx.gl20.glClearColor(0.2f, 0.2f, 0.2f, 1); Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl20.glEnable(GL20.GL_TEXTURE_2D); Gdx.gl20.glEnable(GL20.GL_BLEND); Gdx.gl20.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); texture.bind(); shader.begin(); shader.setUniformMatrix("u_worldView", matrix); shader.setUniformi("u_texture", 0); meshToDraw.render(shader, GL20.GL_TRIANGLES); shader.end(); }