Drawing a partially transparent Pixmap to a Texture (libgdx) - java

Using libgdx, is there something we have to do to enable transparency drawing a Pixmap to a Texture? I've tried doing this before the texture's draw() call where I pass the Pixmap:
Gdx.gl.glClearColor(0.5f, 0.0f, 0.0f, 1.0f);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
Gdx.gl.glEnable(GL10.GL_BLEND);
But it's painting an opaque dark red (glClearColor) color instead of a transparent pixel.

I don't know the reason for the lack of transparency drawing to a Texture, but it appears that using Pixmaps exclusively (drawing a pixmap onto another larger pixmap) and only rendering to the Texture as a very last step was the solution.
Can't find information on it so I can only assume that drawing a transparent Pixmap to a Texture to blend with the Texture's background color isn't supported.

Related

OpenGL override scene transparency

I'm using GL11 in Java, and the current issue I'm facing is blending. I'm making a simple fade-out animation, and as shown in the image, the borders of the rectangle are darker because they've drawn over the background. How can I override an entire scene to be at one transparency level? Apologies if this doesn't make sense, I'm new to OpenGL.
My code:
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
DrawUserInterface(x, y); // Simple vertex rectangles

LibGDX - Basic 2D lighting, don't know what to do

It's my first time attempting to create a basic light system that uses a black texture with a white circle on top. I read various threads about the issue but I just don't know what I am doing wrong.
What I want is the ambient to be dark and the light to be well white but changing the spritebatch color to something darker will cause the light to be darker to EVEN if I reset the color when drawing the light texture
So this is what I want (did this by forcing the light texture draw 5 times but that isn't a solution, it's an hack):
This is what I get (only 1 light texture is drawn but isn't very visible):
This is what I get without darkening the spritebatch:
Main code:
Game.sb.begin();
//Make stuff darker
Game.sb.setColor(0.1f, 0.1f, 0.1f,1f);
sb.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
lvl.render();
//Reset color
Game.sb.setColor(1f, 1f, 1f,1f);
sb.setBlendFunction(GL20.GL_DST_COLOR, GL20.GL_SRC_ALPHA);
//This draws all lights by drawing a texture with the above blending function
lightM.render();
Game.sb.end();
Light object draw method:
Game.sb.setColor(c.r,c.b,c.g, 1f);
Utils.drawTexture(Assets.get("sprites/lightcircle2.png", Texture.class), pos, size, true);
Game.sb.setColor(1,1,1,1);
Am I making some kind of error with the setcolor? I been considering using a FrameBuffer but I am not sure if it will give me the light effect I want
By the way this is my light texture (it's CC0):
You can achieve your requirement by these ways :
By using Shaders. Here is a small video and article on that video.
By use FBO and Blending, Here is one of my answer on this topic.
You can use box2dlight, even without using box2dbody(if you don't want any shadows)
World world = new World(new Vector2(0,0),false);
RayHandler rayHandler = new RayHandler(world);
rayHandler.setCombinedMatrix(stage.getCamera().combined); //<-- pass your camera combined matrix
new PointLight(rayHandler,1000, Color.WHITE,radius,x_position,y_position);
And at last call rayHandler.updateAndRender(); after all your rendering in your render() method.

Check a prefect collision between rotating texture and a curve (libgdx)

I'm developing a game where there is a texture that the player need to move around the screen without touching the borders which are black lines and curves.
The figure rotates while the player moves it and the borders are fixed the entire game.
I need a good method to check a prefect collision between the border and the texture.
I tried to make a rectangle around the texture and check for black and green (texture color) pixels that are near each other inside the rectangle but it's too slow.

How to change color in lwjgl texture

I have the following texture:
The black pixels are characters, the background is transparent.
How do I change the black pixels of the characters to another color?
I use this texture as a bitmap for tekst rendering in lwjgl. Is there a way to change the black pixels to red?
I would appreciate an example.
As far as I am aware glColor* also applies for textures. If you change the black color of your font to white the given color would simply apply to this.

Color accuracy on the edge of textures

I'm making a game in lwjgl (java opengl) which contains a mesh of textured cubes within it.
I have already fixed the common error of texture coordinates being inaccurate on the edges, my coordinates are 100% accurate.
While moving through the scene, the pixels on the edges of my bright red quads flash teal(which happens to be my clear color) at overlaps with green quads only for a very short moment. There are definately other quads behind the overlaps colored green.
The problem is only with the near and far sides of the top of the cube.
Before you ask, there are NO blue pixels in my texture.
My min/mag filters fixed a brown line at the overlaps of green. but I think this could be part of the problem.
How can I get these pixels to either stay red, or go green?
Or to be more specific, how can I make the blend only use the nearest color and not do any combining?
Here are my params:
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glAlphaFunc(GL11.GL_GREATER, (float) 0.9);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glColor4f(255, 255, 255, 1.0f);
GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE);
GL11.glTexParameterf( GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
Wow, solved. From looking at screenshots, it's actually my eyes tricking me with teal phantoms, as the borders flash from red to white as the screen moves and the pixel estimation changes. Stare at red long enough, close your eyes, and you'll see teal. I'll be looking up some anti-aliasing guides or changing my filter to blend the colors.

Categories

Resources