Is it Possible to Draw Transparent Boxes in GL11 Quads? - java

I'm wondering, can I draw transparent boxes in GL11 in JWJGL? I'm also wondering if I can draw these so I can have the screen turn red when you die but you can still see the background.

I used this for alpha/transparency:
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA,GL11.GL_ONE_MINUS_SRC_ALPHA);
You have to render everything behind the box first. Render the background before the box or you'll have an x-ray.

Related

Scrolling background sides appearance of a line

in my game (using libgdx) i use a scrolling background the scrolling Background it's work good for some backgrounds like this :
Good one
but when i draw my own background using inkscape or photoshope if i use a line in the sides of the background or something like shadow the probelm of a black line appear , except if i use a picture with one color and drawing in the middle . that's mean the problem is from the picture but why in the others background it's work good (There is no problem in the code and measurements)???
Appearance of a line
If code would be attached, would be great. But looks like, when drawing sprite, need draw one pixel less at the beginning, or draw one pixel more end in the end of sprite.

(Libgdx) make everything in stage and spritebatch dark

I'm developing a LibGDX game.
I came to a point where I would like to have all elements in my stage (several labels, buttons etc.) but also the things i draw onto the main spritebatch to get dark and not touchable for when a popup opens in which the user can interact.
Making the stage not respond to user input was very simple, by taking it out of the inputprocessor.
But how to make everything in the stage and the spriteBatch dark so that it becomes obvious to the user that he has to interact with the popup first.
I want it to be somewhat like this
but with a LibGDX stage and spritebatch.
if you add 1x1 pixel transparent black image which is stretched to screen size before your popup, you dont need to change inputprocessor. Touchables of the actors under your transparent image automatically disabled. So you dont need to end and begin spritebatch again which is not good for performance.
So you can do this without changing spritebatch or using additional gl glear call by only adding a transparent area.

Paint Scrollbale Infinite Generating Grid

I am trying to draw a grid of rectangles and I want to be able to draw them off the screen in all directions and then be able to scroll this, changing which are actually in the screen without having to redraw every frame.

Trouble with Java Graphics2D

In my game, I'm using different kinds of objects that implement the Paint interface including GradientPaint for the background. When I try to paint the background, it mostly leaves a grey border on the right and bottom sides of the screen; I don't want that border there. How can I get rid of it?
I notice that when I set my JFrame to be resizable instead of not, the background paints okay as want, but then people will be able to resize the window and distort the visuals needed to play the game.
What I am using to draw graphics is the outdated AWT, using both Graphics and Graphics2D. All the backgrounds I'm painting consist of either one, two, or four Rectangle2D.Float objects, with the appropriate sizes. For a full background, it would be 0, 0, gamePanel.getPreferredSize().width and gamePanel.getPreferredSize().height.

Drawing shapes with transparent colors much slower than opaque colors in Java

I am currently working on making a Java videogame with a few friends. It is a top-down RPG that is drawn with tiles of different types. I just added a day/night cycle to the game, and found that using transparent colors to draw to the screen is very slow. I recently learned how to make colors transparent by adding an alpha-value after the RGB values, and it works very well, but as I said, it is slow. I tried switching between transparent colors and opaque colors and discovered that the lag is because of the transparency. Basically, after a tile is drawn, it calls the method for getting the desired transparency factor, makes a new color, and calls g.fillRect() over the tile. This is done for every tile on screen.
I would like to know if there is another way to have a transparent overlay without just drawing the overlay over the whole window, because we want to be able to add light sources that replace the transparency for specific tiles. The tiles are drawn to the screen from a spritesheet. Any suggestions are welcomed.

Categories