Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Question about rendering transparent texture

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2017
    Posts
    7

    Question Question about rendering transparent texture

    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!
    Click image for larger version. 

Name:	left.jpg 
Views:	30 
Size:	5.0 KB 
ID:	2430


    Click image for larger version. 

Name:	right.jpg 
Views:	23 
Size:	5.2 KB 
ID:	2431

  2. #2
    Intern Contributor
    Join Date
    Dec 2016
    Posts
    54
    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/UCzx...ELz5h1dfCdkdfg

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2017
    Posts
    7
    Quote Originally Posted by OceanJeff40 View Post
    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/UCzx...ELz5h1dfCdkdfg
    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.

  4. #4
    Member Regular Contributor
    Join Date
    Jul 2012
    Posts
    420
    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 might help you. And this one talks about transparent textures.

  5. #5
    Member Regular Contributor
    Join Date
    May 2016
    Posts
    417
    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)

  6. #6
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,404
    Quote Originally Posted by tri_thinggg View Post
    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.

  7. #7
    Junior Member Newbie
    Join Date
    Jul 2017
    Posts
    7
    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!

  8. #8
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,404
    Quote Originally Posted by tri_thinggg View Post
    I read that GLFW and QGLWidget might get conflicts, is that true?
    It seems quite likely.

    Quote Originally Posted by tri_thinggg View Post
    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.

    Quote Originally Posted by tri_thinggg View Post
    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.

  9. #9
    Member Regular Contributor
    Join Date
    Jul 2012
    Posts
    420
    Quote Originally Posted by tri_thinggg View Post
    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.

    Quote Originally Posted by tri_thinggg View Post
    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.

    Quote Originally Posted by tri_thinggg View Post
    3. If so, should I rearrange all of the my codes in QT creator and using QTWidget instead of GLFW?
    You have another option. 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.

    Quote Originally Posted by tri_thinggg View Post
    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.

  10. #10
    Junior Member Newbie
    Join Date
    Jul 2017
    Posts
    7
    Quote Originally Posted by Silence View Post
    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. 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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •