I want to use Alpha/Blend mode for future stuff (transactions mainly and possible image blending).
Well, I can't get it to work using LWJGL (GL1.1), I already tried other blend modes but didn't worked, nor changing the background or anything like that...
Screenshots:
- http://i.imgur.com/cHU4YGS.png - GL_BLEND always enabled, everything is transparent
- http://i.imgur.com/sPmPqne.png - GL_BLEND enabled on QUAD and text, I can see the line that is on disabled GL_BLEND
- i imgur com/nkda41v png - GL_BLEND disabled on everything but the text -> I need some reputation to post more than 2 links, sorry about that but I belive this image is important so i'll post it anyway. Just fill with dots
The results are the same with or without alpha argument on all these tests
Code:
` private void init() {
try {
Display.setDisplayMode(new DisplayMode(DEFAULT_WIDTH, DEFAULT_HEIGHT));
Display.setResizable(true);
Display.setVSyncEnabled(true);
Display.setTitle(DEFAULT_TITLE + " v" + VERSION);
Display.create();
updateMatrix();
} catch(LWJGLException e) {
e.printStackTrace();
}
Keyboard.enableRepeatEvents(true);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Font consolas = new Font("consolas", Font.PLAIN, 13);
font = new TrueTypeFont(consolas, antiAliasedFont);
}
private void updateMatrix() {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, DEFAULT_WIDTH, DEFAULT_HEIGHT, 0, 1, -1);
//glScaled((double) DEFAULT_WIDTH / (double) Display.getWidth(), (double) DEFAULT_HEIGHT / (double) Display.getHeight(), 0);
glViewport(0, 0, Display.getWidth(), Display.getHeight());
glMatrixMode(GL_MODELVIEW);
}
@Override
public void run() {
init();
Main main = Main.getMain();
while(!Display.isCloseRequested()) {
currentGraphicsTick++;
{
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0f, 0f, 0f, 1f);
if(Display.wasResized()) updateMatrix();
if(vsyncMode == 1) Display.setVSyncEnabled(true);
else if(vsyncMode == 2) Display.setVSyncEnabled(false);
if(Display.isActive()) {
glPushMatrix();
try { // Draw
float alpha = (float) Math.cos(Math.toRadians(currentGraphicsTick % 90));
System.out.println("Alpha: " + alpha);
glBegin(GL_LINE_STRIP);
{
float sin = (float) Math.abs(Math.sin(Math.toRadians(currentGraphicsTick % 360)));
new Color(0.7f, 0.7f, 0.7f, alpha).bind();
glVertex2f(DEFAULT_WIDTH * 0.03f, DEFAULT_HEIGHT * 0.05f);
glVertex2f(DEFAULT_WIDTH * 0.93f * sin, DEFAULT_HEIGHT * 0.95f * sin);
}
glEnd();
glBegin(GL_QUAD_STRIP);
{
new Color(0.5f, 0.5f, 0.5f, alpha).bind();
glVertex2i(0, 0);
glVertex2i(0, DEFAULT_HEIGHT);
glVertex2i(DEFAULT_WIDTH, 0);
glVertex2i(DEFAULT_WIDTH, DEFAULT_HEIGHT);
}
glEnd();
String[] split = main.getGameLoopThread().getDebugString().split("\n");
for(int i = 0; i < split.length; i++) {
font.drawString(1, 1 + (i * font.getLineHeight()), split[i], Color.white);
}
} catch(Throwable throwable) {
throwable.printStackTrace();
}
glPopMatrix();
}
Display.update();
Display.sync(TARGET_FPS);
}
}
Display.destroy();
closeRequested = true;
}
I already tried:
- Removing the 'alpha' argument from the Slick's Color constructor
- Using OpenGL's glColor with and without alpha argument
- Disabling/Enabling GL_BLEND in part of the code (I know some things wouldn't work, but you never know, right?)
- Used constants to the alpha variable (such as 0.3f, 0.5f, 0.7f, 1f) instead of making it variable through Math.sin/cos using the tick as the degree
- Using glRect(...)
- Changing the background
- Removing the glClearColor
- Removing glClear (nice effect, never did this lol)
What I expect to see was a fading moving LINE_STRIP:
On one side it moves from the (0, 0) to (width - 7%, height - 5%)
On the other it stand still on (width + 3%, height + 5%)
the rectangle would make it fade (the original idea would use the same color as the background, but it didn't on my tests because I want to see the rectangle)