From: Chad A. <ae...@ae...> - 2002-04-03 07:42:03
|
Your problem is that, with alpha blending, you can't use the z-buffer. :( When you draw your first polygon, you end up putting initial values in the z-buffer. When you try to draw the polygons behind the first polygon, they don't get drawn at all because the z-buffer says those pixels don't need to be touched anymore. The solution to your problem kinda sucks... when you draw alpha-blended polygons, you have to disable the z-buffer and manually sort your polygons from back to front. After drawing every solid polygon in the scene, you draw the alpha-blended ones from front to back. A simple way to do this with your cube is just take the midpoint of each face and sort by its distance from the viewer (or z value, if you're in view coordinates). If you have static, non-intersecting shapes, you can build a BSP tree. BSP trees let you quickly sort polygons from front-to-back, which makes drawing the translucent polys a simple tree traversal. You can pick up a book on graphics (Realtime Rendering is the one I recommend) for more information. > Ok, now I'm kinda fooling around with transparency (alpha blending) and I > can't get past this nagging characteristic of my program. Maybe someone knows > how to fix this: I started with a box with an open top and open bottom. All > of the four sides have alpha values of 0.5. When I rotated that box rotates, > though, the first polygon drawn is always opaque. So, I modified the box so > that there is a bottom side (also with an alpha value of 0.5), and now all > four of the walls are translucent, but the bottom is completely opaque, > despite the alpha values that I specified. Is this an OpenGL thing, or am I > missing something? I attached my code so you can see exactly what's > happening. (The program actually draws two boxes, but I'm only worried about > the one that has five sides) > > - Lou > > Name: Create_Window.cpp > Create_Window.cpp Type: Plain Text (text/plain) > Encoding: quoted-printable |
From: Lou H. <lh...@ia...> - 2002-04-11 16:56:52
|
Ok, but how do I sort the polygons if OpenGL draws them immediately when I call glVertex? The only way for me to sort polygons from back to front is if I know the transformed coordinates, but I don't know that until I call glVertex. Unless there's some other feature of OpenGL that I still don't know about (which there probably is). - Lou ----- Original Message ----- From: "Chad Austin" <ae...@ae...> To: "Lou Herard" <lh...@ia...> Cc: "gdd" <isu...@li...> Sent: Wednesday, April 03, 2002 2:42 AM Subject: Re: [isugamedev-devel] Alpha blending > Your problem is that, with alpha blending, you can't use the z-buffer. :( When > you draw your first polygon, you end up putting initial values in the z-buffer. > When you try to draw the polygons behind the first polygon, they don't get drawn > at all because the z-buffer says those pixels don't need to be touched anymore. > > The solution to your problem kinda sucks... when you draw alpha-blended > polygons, you have to disable the z-buffer and manually sort your polygons from > back to front. After drawing every solid polygon in the scene, you draw the > alpha-blended ones from front to back. > > A simple way to do this with your cube is just take the midpoint of each face > and sort by its distance from the viewer (or z value, if you're in view > coordinates). > > If you have static, non-intersecting shapes, you can build a BSP tree. BSP > trees let you quickly sort polygons from front-to-back, which makes drawing the > translucent polys a simple tree traversal. You can pick up a book on graphics > (Realtime Rendering is the one I recommend) for more information. > > > Ok, now I'm kinda fooling around with transparency (alpha blending) and I > > can't get past this nagging characteristic of my program. Maybe someone knows > > how to fix this: I started with a box with an open top and open bottom. All > > of the four sides have alpha values of 0.5. When I rotated that box rotates, > > though, the first polygon drawn is always opaque. So, I modified the box so > > that there is a bottom side (also with an alpha value of 0.5), and now all > > four of the walls are translucent, but the bottom is completely opaque, > > despite the alpha values that I specified. Is this an OpenGL thing, or am I > > missing something? I attached my code so you can see exactly what's > > happening. (The program actually draws two boxes, but I'm only worried about > > the one that has five sides) > > > > - Lou > > > > Name: Create_Window.cpp > > Create_Window.cpp Type: Plain Text (text/plain) > > Encoding: quoted-printable > |
From: Kevin M. <ke...@vr...> - 2002-04-11 17:15:35
|
fun... :) to sort, you would need to have a data struct of polygons, and you would need to do your own matrix math upon them... then once they are sorted relative to the distance they are away from you, you can traverse the newly sorted list and render each one. the fun part is making your own matrix class, but you can use the one in isugamedev/lib/math if you need... the polygon class can be struct poly { Vec4 color; // could make this [3] or not... Vec3 normal; // could make this [3] or not... Vec2 texcoord[3]; Vec3 point[3]; }; then make a list of them std::vector<poly> vec_of_polys; Matrix4f * Vec3f is defined in the isugamedev/lib/math project... to sort you can write your own, or the STL sort functions... :) kevin On Thu, 11 Apr 2002, Lou Herard wrote: > Ok, but how do I sort the polygons if OpenGL draws them immediately when I > call glVertex? The only way for me to sort polygons from back to front is > if I know the transformed coordinates, but I don't know that until I call > glVertex. Unless there's some other feature of OpenGL that I still don't > know about (which there probably is). > > - Lou > > ----- Original Message ----- > From: "Chad Austin" <ae...@ae...> > To: "Lou Herard" <lh...@ia...> > Cc: "gdd" <isu...@li...> > Sent: Wednesday, April 03, 2002 2:42 AM > Subject: Re: [isugamedev-devel] Alpha blending > > > > Your problem is that, with alpha blending, you can't use the z-buffer. > :( When > > you draw your first polygon, you end up putting initial values in the > z-buffer. > > When you try to draw the polygons behind the first polygon, they don't get > drawn > > at all because the z-buffer says those pixels don't need to be touched > anymore. > > > > The solution to your problem kinda sucks... when you draw alpha-blended > > polygons, you have to disable the z-buffer and manually sort your polygons > from > > back to front. After drawing every solid polygon in the scene, you draw > the > > alpha-blended ones from front to back. > > > > A simple way to do this with your cube is just take the midpoint of each > face > > and sort by its distance from the viewer (or z value, if you're in view > > coordinates). > > > > If you have static, non-intersecting shapes, you can build a BSP tree. > BSP > > trees let you quickly sort polygons from front-to-back, which makes > drawing the > > translucent polys a simple tree traversal. You can pick up a book on > graphics > > (Realtime Rendering is the one I recommend) for more information. > > > > > Ok, now I'm kinda fooling around with transparency (alpha blending) > and I > > > can't get past this nagging characteristic of my program. Maybe someone > knows > > > how to fix this: I started with a box with an open top and open bottom. > All > > > of the four sides have alpha values of 0.5. When I rotated that box > rotates, > > > though, the first polygon drawn is always opaque. So, I modified the > box so > > > that there is a bottom side (also with an alpha value of 0.5), and now > all > > > four of the walls are translucent, but the bottom is completely opaque, > > > despite the alpha values that I specified. Is this an OpenGL thing, or > am I > > > missing something? I attached my code so you can see exactly what's > > > happening. (The program actually draws two boxes, but I'm only worried > about > > > the one that has five sides) > > > > > > - Lou > > > > > > Name: Create_Window.cpp > > > Create_Window.cpp Type: Plain Text (text/plain) > > > Encoding: quoted-printable > > > > > > _______________________________________________ > ISUGameDev-devel mailing list > ISU...@li... > https://lists.sourceforge.net/lists/listinfo/isugamedev-devel > -- @--@---@---@----@-----@------@------@-----@----@---@---@--@ Kevin Meinert __ _ __ http://www.vrac.iastate.edu/~kevn \ || \| \ / ` Virtual Reality Applications Center \ ||.-'|--\\ Howe Hall, Iowa State University, Ames Iowa \|| \| \`__, ----------------------------------------------------------- |
From: Lou H. <lh...@ia...> - 2002-04-12 16:25:31
Attachments:
Create_Window.cpp
|
Ok, guys, I did some fishing online, and I found out how to enable tranparency without having to sort polygons. It does include setting the glDepthMask variable to GL_FALSE. That way, when OpenGL goes to draw "behind" something, it looks in the color buffer also, and it blends properly. And sorry, I haven't gotten Tortoise CVS yet, but I will today, infact probably right now. But you'll still have to deal with an email attachment. MWAH-HA-HA-HA-HAAAAAAA (evil grin) - Lou |
From: Kevin M. <ke...@vr...> - 2002-04-12 16:32:12
|
unfortunately this wont work when you have a complex scene (like walls dividing rooms). then you wont know if your geom is in front or behind a wall for example... really, you do have to do the sort. but the sort is easy with std::sort... need code? I have some. kevin On Fri, 12 Apr 2002, Lou Herard wrote: > Ok, guys, I did some fishing online, and I found out how to enable > tranparency without having to sort polygons. It does include setting the > glDepthMask variable to GL_FALSE. That way, when OpenGL goes to draw > "behind" something, it looks in the color buffer also, and it blends > properly. And sorry, I haven't gotten Tortoise CVS yet, but I will today, > infact probably right now. But you'll still have to deal with an email > attachment. MWAH-HA-HA-HA-HAAAAAAA (evil grin) > > - Lou > -- @--@---@---@----@-----@------@------@-----@----@---@---@--@ Kevin Meinert __ _ __ http://www.vrac.iastate.edu/~kevn \ || \| \ / ` Virtual Reality Applications Center \ ||.-'|--\\ Howe Hall, Iowa State University, Ames Iowa \|| \| \`__, ----------------------------------------------------------- |