0
\$\begingroup\$

I want to create a pause menu where everything in the background gets darker. I've looked up a bunch of possible solutions (even the second page on google) but it doesn't seem to work. I do already have something in my code that makes a single texture darker when hovered over, by calling: GL11.glColor3f(alpha, alpha, alpha); before drawing vertices. What I want to achieve is everything getting darker, so when hovering over a texture it should be even darker than before so it is still darker than the rest in the background when that has been made darker because of a pause menu that pops up.

Another thing I noticed is that glColorMask(true, false, false, true); does not get overridden and blends colours everywhere, so I was wondering if there is a version of this method that puts a transparent black overlay so everything becomes darker. I have enabled blending.

-Edit-

One solution I came up with (not just now) is multiplying alpha in every glColor3f function with a variable that is smaller than 1 so everthing gets relatively smaller, but I worry about this being uneffective and badly mantainable

\$\endgroup\$
2
\$\begingroup\$

GL11.glColor3f(alpha, alpha, alpha); won't work for 2 reasons:

  1. It's opaque. You'd need GL11.glColor4f(alpha, alpha, alpha,alpha);
  2. It affects the next object to be rendered, not everything already rendered.

It would be easier to render a semi-transparent quad over the whole screen (with a slightly higher z-depth) prior to drawing the menu. This will cut down on the amount of code necessary to achieve the effect, GPU-time its probably slightly worse, but only slightly.

\$\endgroup\$
  • \$\begingroup\$ I now call this method before drawing anything but it doesn't appear: public static void DrawQuad(float x, float y, float width, float height) { glColor4f(.3f, .3f, .3f, .3f); glBegin(GL_QUADS); glVertex3f(x, y, 1); //Top left corner glVertex3f(x + width, y, 1); //Top right corner glVertex3f(x + width, y + height, 1); //Bottom right corner glVertex3f(x, y + height, 1); //Bottom left corner glEnd(); } For all the other things I use glVertex2f does that have something to do with it? \$\endgroup\$ – The Coding Wombat Jan 15 '16 at 20:21
  • \$\begingroup\$ I would have to check my own quad-drawing code, which is on another computer. I practically stole Minecraft's GUI setup and Tessellator "GL-helper" class. It was a much cleaner way of doing the menus than what I'd been doing in Unity prior (second camera in orthographic mode). It was a huge hassle to translate the calls, though. Not as much GL access as in Java. \$\endgroup\$ – Draco18s Jan 15 '16 at 20:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.