PDA

View Full Version : Question about rendering transparent texture



tri_thinggg
07-31-2017, 11:30 AM
Hi everyone, I'm new to OpenGL and have a problem when I try to render a transparent texture of a container with a bunch of smaller boxes.

I added the alpha channel for the transparent texture (cardboard with crossing tapes on) using GIMP and set the alpha value 0.25.

As you can see from the attachment, I got something similar but not good enough. When I turn the view position from the top right corner of the box, the LEFT and BOTTOM sides are not rendered properly, no tapes show up. When I turn the view to the top left corner, then RIGHT and BOTTOM are wrong again.

Could anyone help me please? Any comments/hints/ suggestions would be appreciate! Thank you so much!
2430


2431

OceanJeff40
07-31-2017, 12:44 PM
Is this related to back face culling?

Let me know if that's the issue.

Jeff

P.S. I might as well put in a shameless plug for my youtube channel, which has some basic opengl and openframeworks tutorials.

https://www.youtube.com/channel/UCzx8alrxVELz5h1dfCdkdfg

tri_thinggg
07-31-2017, 01:54 PM
Is this related to back face culling?

Let me know if that's the issue.

Jeff

P.S. I might as well put in a shameless plug for my youtube channel, which has some basic opengl and openframeworks tutorials.

https://www.youtube.com/channel/UCzx8alrxVELz5h1dfCdkdfg

Hi, Thank you for your reply.

I think it may be the problem because the render indices of whichever incorrect rendered side are always reversed because of the orientation of view. How should I solve this question then? I read something about blending and alpha test but not sure how I should use them.

Silence
07-31-2017, 11:41 PM
Sort. Render opaque meshes first. Then render you non opaque meshes from back to front (the more far first, the nearest last).

For more information, this tutorial (http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-10-transparency/) might help you. And this one (https://learnopengl.com/#!Advanced-OpenGL/Blending) talks about transparent textures.

john_connor
08-01-2017, 01:45 AM
there are different ways / techniques to achieve transparency. what Silence stated is 1 solution, another is a bit bore difficult, called "Order-Independent-Transparency" (OIT), it allows you to skip the otherwise required depth-sorting of transparent shapes. however, any approach requires backface culling to be disabled, because they are still visible when covered by transparent (front) faces:

glDisable(GL_CULL_FACE);

by default, culling is disabled, which means that you've enabled it somewhere in your code (if that's the issue)

GClements
08-01-2017, 03:22 AM
I think it may be the problem because the render indices of whichever incorrect rendered side are always reversed because of the orientation of view. How should I solve this question then? I read something about blending and alpha test but not sure how I should use them.
Blending must be enabled to get the appearance of translucency. Without it, each fragment that's rendered simply overwrites the corresponding pixel in the framebuffer.

Alpha testing isn't relevant here. It's used when you want to use a texture's alpha channel as a binary mask.

You need to render primitives in a defined order. Decreasing distance (back to front) is usually simpler, as it doesn't require the framebuffer to have an alpha channel. Actually, you need to render the fragments in a defined order; sorting the primitives is one solution, but more advanced techniques sort the fragments. In the general case you need to use a topological sort, and you may need to explicitly break cycles. In some cases, you may be able to get away with sorting by the greatest/least/average Z coordinate of the primitive's vertices.

You can't use depth-testing because a nearer primitive will completely prevent the rendering of a farther primitive, but translucency requires rendering both.

tri_thinggg
08-02-2017, 11:17 AM
Thank for all of you! I solved the problem using sorting.
And, now I have a new problem:/

I finished the coding part for my Opengl rendering project in VS 2015 and I used glew, glfw, glm these libraries with spearated camera headerfile and shader headerfile. Right now, the dimension of these cubes are hard-coded in the main.cpp.

1. Is there any way for me to integrate my code with QT creator to let users input cube dimensions using keyboard, and the UI will receive these data and send to render new cubes?

2. I read that GLFW and QGLWidget might get conflicts, is that true?

3. If so, should I rearrange all of the my codes in QT creator and using QTWidget instead of GLFW?

4. Also, my project involves different 2 threads. Is there anything I need to pay attention to when integrating my code with QT GUI?


Thank you so much again!

GClements
08-02-2017, 12:01 PM
I read that GLFW and QGLWidget might get conflicts, is that true?

It seems quite likely.



3. If so, should I rearrange all of the my codes in QT creator and using QTWidget instead of GLFW?

If you're going to be using Qt, you should use QGLWidget rather than GLFW.



4. Also, my project involves different 2 threads. Is there anything I need to pay attention to when integrating my code with QT GUI?

Use QThread rather than creating threads using native APIs (pthread_create(), CreateThread(), etc). Don't call Qt methods from a thread other than the main thread unless the documentation specifies the method as being thread-safe. Ensure that an OpenGL context isn't current in more than one thread at a time.

Silence
08-03-2017, 12:34 AM
1. Is there any way for me to integrate my code with QT creator to let users input cube dimensions using keyboard, and the UI will receive these data and send to render new cubes?!

You don't need QtCreator to program with Qt. VS will work as well too.


2. I read that GLFW and QGLWidget might get conflicts, is that true?

Qt already provides what GLFW provides. So use one or the other, but not both. It will be the same for glew. And AFAIR Qt also provides vectors and matrices.


3. If so, should I rearrange all of the my codes in QT creator and using QTWidget instead of GLFW?

You have another option (https://github.com/ocornut/imgui). Other GUI libraries like this one exist. So if you want to move this way, choose carefully the right one. Also note that these libraries might become slow if your user interface will become heavy. If not, then they will certainly run more fast, use less CPU, require less dependencies and less effort for the transition than moving to Qt. Also, and as a side-note, read carefully about the Qt licenses.


4. Also, my project involves different 2 threads. Is there anything I need to pay attention to when integrating my code with QT GUI?

Most probably the Qt OpenGL widget will run on the main thread.

tri_thinggg
08-03-2017, 07:32 AM
You don't need QtCreator to program with Qt. VS will work as well too.



Qt already provides what GLFW provides. So use one or the other, but not both. It will be the same for glew. And AFAIR Qt also provides vectors and matrices.



You have another option (https://github.com/ocornut/imgui). Other GUI libraries like this one exist. So if you want to move this way, choose carefully the right one. Also note that these libraries might become slow if your user interface will become heavy. If not, then they will certainly run more fast, use less CPU, require less dependencies and less effort for the transition than moving to Qt. Also, and as a side-note, read carefully about the Qt licenses.



Most probably the Qt OpenGL widget will run on the main thread.

Thank you so much for your help!
One more quick question is that is there any difference if I use QGLWidget or QOpenGLWidget? I read that QOpenGLWidget is more updated than QGLWidget? Which one should I use then? I'm using Qt 5.9 and OpenGL 3.3 version.

Thank you so much again for your help!

tri_thinggg
08-03-2017, 07:33 AM
It seems quite likely.


If you're going to be using Qt, you should use QGLWidget rather than GLFW.


Use QThread rather than creating threads using native APIs (pthread_create(), CreateThread(), etc). Don't call Qt methods from a thread other than the main thread unless the documentation specifies the method as being thread-safe. Ensure that an OpenGL context isn't current in more than one thread at a time.

Thank you so much for your reply!
One more quick question is that is there any difference if I use QGLWidget or QOpenGLWidget? I read that QOpenGLWidget is more updated than QGLWidget? Which one should I use then? I'm using Qt 5.9 and OpenGL 3.3 version.

Thank you so much again for your help!

GClements
08-03-2017, 11:51 AM
One more quick question is that is there any difference if I use QGLWidget or QOpenGLWidget? I read that QOpenGLWidget is more updated than QGLWidget? Which one should I use then? I'm using Qt 5.9 and OpenGL 3.3 version.
QGLWidget is deprecated in Qt 5; use QOpenGLWidget instead.

tri_thinggg
08-03-2017, 11:57 AM
Thank you so much!