LWJGL Forum

Programming => OpenGL => Topic started by: Yuri6037 on September 04, 2014, 12:28:21

Title: glColor4f with alpha value cause the opbject to not render.
Post by: Yuri6037 on September 04, 2014, 12:28:21
Hi all it's been a long time...

I'm now working on a 3D FPS game and i got a big problem. This has never happend before : the glColor4f is not working with alpha value.

I know we need glEnable(GL_BLEND) and a glBlendFunc, i already done that, but it's not working. The only thing i arrive to get is a complete black screen or the hud object to be not rendered.
So my code :
The 3D/2D switcher :
Code: [Select]
--SOLVED--
Now the main render loop (in my main game class)
Code: [Select]
--SOLVED--
Now the draw rect void
Code: [Select]
--SOLVED--
The color binder system
Code: [Select]
--SOLVED--
The game init code
Code: [Select]
--SOLVED--

WorldClient, Player and Camera classes are not needed, it's only related to the HUD rendering.

After that, i would like to ask you a question : is there any way to make a start3D2D and end3D2D functions like in GarrysMod ? So i can render my texts (that are 2D verticies) in the 3D world (that have only 3D verticies).

Anyway, in first i need the HUD part to be working before thinking of any start3D2D thing...


Thanks by advance,
Yuri6037
Title: Re: glColor4f with alpha value cause the opbject to not render.
Post by: abcdef on September 04, 2014, 15:09:38
This might be the problem

renderEngine.bindColor(new EngineColor(0, 0, 0, 200));

The alpha value should be between 0 and 1. Looks like you are setting the colour to 100% black (it will clamp 200 to 1, ie 100% alpha). If you do 1/200 you might get what you are after (although it will still be fairly dark)
Title: Re: glColor4f with alpha value cause the opbject to not render.
Post by: Yuri6037 on September 04, 2014, 18:59:31
Oh sorry i forgot, i have a color computing system (it's EngineColor), here is the source :
Code: [Select]
--SOLVED--

Title: Re: glColor4f with alpha value cause the opbject to not render.
Post by: Daslee on September 04, 2014, 19:59:41
Quote
public void drawRect(float x, float y, float width, float height){
        glPushMatrix();
        glTranslatef(x, y, 0);
        glTranslatef(0, 0, 0);
        glBegin(GL_QUADS);
        glVertex2f(0, 0);
        glVertex2f(width, 0);
        glVertex2f(width, height);
        glVertex2f(0, height);
        glEnd();
    }

First of all you push the matrix, but later do not pop the matrix, at least I can't see that part where you pop the matrix. And second thing is that you translate your rectangle to x, y coordinates, and then back to 0, 0 why?
Title: Re: glColor4f with alpha value cause the opbject to not render.
Post by: Yuri6037 on September 04, 2014, 21:18:12
Quote
--SOLVED--

First of all you push the matrix, but later do not pop the matrix, at least I can't see that part where you pop the matrix. And second thing is that you translate your rectangle to x, y coordinates, and then back to 0, 0 why?

Seriously am I stupid I forget the glPopMatrix. For the translations, I already had problems using translation in matrix.
I found that you need to call your final translations (translatef, rotatef, ...) before the actual translation (to move it on 0, 0, 0).

Anyway thanks, you've seen a possible bug with forget to pop the matrix, because I'm not currently at my computer, I will apply that later...
Title: Re: glColor4f with alpha value cause the opbject to not render.
Post by: Yuri6037 on September 05, 2014, 16:59:35
I solved my problem.