0

Glasses off:

Glasses off

Glasses On:

Glasses On

I am having an issue trying to blend the lens of the glasses to be transparent with the object of the background. I have followed the back-to-front rule and set the alpha parameter to all the background shapes to 1.0 before drawing with glVertex2i like this : ex:

glColor4f(0.5294117647f, 0.80784313725f, 0.92156862745f,1);

Since my the glasses frame is filled under the glasses' lens, I started with frame > lens > background objects. Frame: glColor4f(0.219f, 0.203f, 0.270f,0.2); //20% opacity Lens: glColor4f(0.59607843137, 0.78039215686, 0.85098039215, 0.5); //50% opacity

Objective I want to show the background objects through the frame and lens.

I really appreciate if someone can help me with this.

Spektre
  • 49,595
  • 11
  • 110
  • 380
Alulu
  • 1
  • 1
    DO you draw the objets from the back to the front? – Rabbid76 Apr 13 '22 at 04:57
  • 1
    and do you have enabled `GL_BLENDING`? with correct `glBlendFunc` function? ... and yes the glasses should be rendered at last ... Also does your rendering context have alpha bits allocated? ... in case your scene is 3D add normals and lighting to enhance visual apearance. – Spektre Apr 13 '22 at 08:37
  • @Rabbid76, yes i followed back to front when rendering. – Alulu Apr 13 '22 at 12:03
  • @Spektre, Yes i have enabled GL_BLENDING & glBlendFun in my main. it looks like this: glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); and in render function: glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // RGBA // Canvas settings glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, 1280, 0, 862); // Set canvas to 1280x862 pixels. glClear(GL_COLOR_BUFFER_BIT); // Load frame buffer. DrawPOVOne(); DrawGlasses(); glutSwapBuffers(); glFlush(); glFinish(); still not blending. – Alulu Apr 13 '22 at 12:07
  • 1. you do not have depth? `glClear(GL_COLOR_BUFFER_BIT);` ??? if your scene is 2D and have disabled `GL_DEPTH_TEST` then its ok but if you are in 3D then you have to enable `GL_DEPTH_TEST` and also `glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);` 2. have you allocated alpha bits for the framebuffer? see [Getting a window's pixel format](https://stackoverflow.com/a/50248477/2521214) if not then either add them durring context creation or use `GL_SRC_COLOR` or `GL_SRC_ONE` ... instead of ALPHA – Spektre Apr 13 '22 at 13:00
  • @Spektre, I am only drawing 2d objects in my project. I tried to disable GL_DEPTH_TEST before drawing the background. the glasses still overlap without transparency. am really confused. – Alulu Apr 13 '22 at 13:16
  • if nothing helps create MCVE then so we can actually test it. It does not need to be whole code/scene ... just the rendering and its enough having 2 overlapping triangles ones opaque and one transparent ... with all the settings you got ... btw did you try the non alpha Blending modes based on color or constant in case you do not have alpha bits in your framebuffer? – Spektre Apr 13 '22 at 14:56

0 Answers0