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 \|| \| \`__, ----------------------------------------------------------- |