CARVIEW |
Select Language
HTTP/2 302
date: Sat, 26 Jul 2025 04:44:48 GMT
content-type: text/html; charset=utf-8
content-length: 0
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
location: https://gist.github.com/mattdesl/4393861
cache-control: no-cache
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
set-cookie: _gh_sess=zHBq82LFwHxIg8nYfNPW40LTJ5xEqMaoeZXxgxeE3%2FfJRTMYfDDWHGo5coQC61P8nxqUM3u0XS1x0Z30GG%2FOUK96LnDCkbAq1QKQaiFJXClVsoZoGyy6iDDHCn8wuTUQjdPnv6awSNJIythCVvOnps5VqjERyGf4DQRxqo5MttB9gwKIsxGmTOmE917kDpFSLeKqPtcF69vkhgvpjJM7r2Sxn%2FG9%2FF%2Bn9PGes%2BeSO9P8kuUWXzEWZ7TaOMoYhNAAn6qq%2FYmLQpO%2BhVwbeILdpQ%3D%3D--1kJWJiPSee%2Bp9WyA--RQ9sqtOVDh%2FJIHE6GWiGzg%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.1720327076.1753505087; Path=/; Domain=github.com; Expires=Sun, 26 Jul 2026 04:44:47 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Sun, 26 Jul 2026 04:44:47 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: 9724:1C79A4:17C49D:23363B:68845D3F
HTTP/2 200
date: Sat, 26 Jul 2025 04:44:48 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
etag: W/"9395612bec29aecb4827540ae049e3ce"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
x-github-request-id: 9724:1C79A4:17C4E0:23368E:68845D3F
FBOTestLibGDX.java · GitHub
Show Gist options
Save mattdesl/4393861 to your computer and use it in GitHub Desktop.
{{ message }}
Instantly share code, notes, and snippets.
Last active
October 10, 2024 22:05
-
Star
7
(7)
You must be signed in to star a gist -
Fork
1
(1)
You must be signed in to fork a gist
-
Save mattdesl/4393861 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.badlogic.gdx.ApplicationListener; | |
import com.badlogic.gdx.Gdx; | |
import com.badlogic.gdx.backends.lwjgl.LwjglApplication; | |
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; | |
import com.badlogic.gdx.graphics.GL10; | |
import com.badlogic.gdx.graphics.OrthographicCamera; | |
import com.badlogic.gdx.graphics.Pixmap.Format; | |
import com.badlogic.gdx.graphics.Texture; | |
import com.badlogic.gdx.graphics.g2d.SpriteBatch; | |
import com.badlogic.gdx.graphics.g2d.TextureRegion; | |
import com.badlogic.gdx.graphics.glutils.FrameBuffer; | |
public class FBOTest implements ApplicationListener { | |
public static void main(String[] args) { | |
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration(); | |
cfg.useGL20 = true; | |
cfg.width = 640; | |
cfg.height = 480; | |
cfg.resizable = false; | |
new LwjglApplication(new FBOTest(), cfg); | |
} | |
Texture atlas; | |
TextureRegion track, thumb; | |
FrameBuffer fbo; | |
TextureRegion fboRegion; | |
SpriteBatch batch; | |
OrthographicCamera cam; | |
@Override | |
public void create() { | |
atlas = new Texture(Gdx.files.internal("data/slider.png")); | |
if (Gdx.gl20 == null) | |
throw new IllegalStateException( | |
"this demo uses GL20 for non-power-of-two and glBlendFuncSeparate"); | |
// ideally you would use a texture packer like in LibGDX | |
track = new TextureRegion(atlas, 0, 0, 64, 256); | |
thumb = new TextureRegion(atlas, 65, 0, 64, 128); | |
// for this demo we'll make our frame buffer the same size as our screen | |
// if our device doesn't support NPOT textures, we might get an error | |
// here | |
// also if the screen resizes we'll need to accomodate for that... | |
// the reason we make it the same size is so that we don't need to | |
// upload a new projection | |
// matrix to our SpriteBatch when rendering to the FBO | |
fbo = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), | |
Gdx.graphics.getHeight(), false); | |
// this will just be the size of our slider track | |
fboRegion = new TextureRegion(fbo.getColorBufferTexture(), 0, 0, | |
track.getRegionWidth(), track.getRegionHeight()); | |
fboRegion.flip(false, true); // FBO uses lower left, TextureRegion uses | |
// upper-left | |
batch = new SpriteBatch(); | |
cam = new OrthographicCamera(Gdx.graphics.getWidth(), | |
Gdx.graphics.getHeight()); | |
cam.setToOrtho(false); | |
renderSlider(); | |
} | |
protected void renderSlider() { | |
// make our offscreen FBO the current buffer | |
fbo.begin(); | |
// we need to first clear our FBO with transparent black | |
Gdx.gl.glClearColor(0f, 0f, 0f, 0f); | |
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); | |
// start our batch | |
batch.begin(); | |
// render some sprites to our offscreen FBO | |
float x = 0; | |
float y = 0; | |
int val = 40; // example value amount | |
// use -1 to ignore.. somebody should fix this in LibGDX :\ | |
batch.setBlendFunction(-1, -1); | |
// setup our alpha blending to avoid blending twice | |
Gdx.gl20.glBlendFuncSeparate(GL10.GL_SRC_ALPHA, | |
GL10.GL_ONE_MINUS_SRC_ALPHA, GL10.GL_ONE, GL10.GL_ONE); | |
// draw sprites | |
batch.setColor(1f, 1f, 1f, 1f); | |
batch.draw(track, x, y); | |
batch.draw(thumb, x, y + val); | |
// end (flush) our batch | |
batch.end(); | |
// unbind the FBO | |
fbo.end(); | |
// now let's reset blending to the default... | |
batch.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); | |
} | |
@Override | |
public void render() { | |
// nice smooth background color | |
float L = 233 / 255f; | |
Gdx.gl.glClearColor(L, L, L, 1f); | |
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); | |
// whenever the slider moves we will need to call renderSlider() to | |
// update the offscreen texture | |
// render the offscreen texture with "premultiplied alpha" blending | |
batch.setBlendFunction(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA); | |
batch.begin(); | |
// due to our different blend funcs we need to use RGBA to specify opacity | |
// tinting becomes unavailable with this solution | |
float a = 0.5f; | |
batch.setColor(a, a, a, a); | |
batch.draw(fboRegion, 0, 0); | |
batch.end(); | |
} | |
@Override | |
public void resize(int width, int height) { | |
cam.setToOrtho(false, width, height); | |
batch.setProjectionMatrix(cam.combined); | |
} | |
@Override | |
public void pause() { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void resume() { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void dispose() { | |
// TODO Auto-generated method stub | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can’t perform that action at this time.