• Content count

  • Joined

  • Last visited

Community Reputation

100 Neutral

About wondersonic2

  • Rank
  1. [SOLVED] Stencil usage and optimization

    The algorithm mentioned previously seems to work so far. BTW, I may remark that changing the projection matrix has impact regarding the area selected with glScissor. Said differently: one must call again glScissor (with the same parameters) after changing projection matrix. WS
  2. Ok, I've finally found some way to do that. First of all the 3D perspective view must be set as this: glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f, (float) SCREEN_HEIGHT / (float) SCREEN_WIDTH, 0f, 100.0f); The important thing here is the z near value: 0f Thus if the objects/camera move only on the X and/or Y axis, the dimension of objects in a given z plan are always the same size. Now during collision detection phase, I just draw the parts of 3D objects that can collide with 2D objects. For a ground square (with perspective), I can draw with limited z depth: normal rendering: draw depth from 1 to -1 inside collision detection method: draw depth from 1 to 0.5
  3. Hello, I need some precisions regarding the usage of the stencil buffer. Currently, I use it for collision detection (using occlusion query afterward) but I would like to optimize this part of my 2D engine by reducing the number of times I've to clear the stencil buffer. I imagine this is possible since there can be several bit plans. So at the initialization, I get a 8 bits stencil buffer => so 8 bit plans are available. Now, I'll use 7 of these bit plans for collision detection so I just need to clear the stencil once very 7 collision checks, right? However, what is the way to do that? Here is my algorithm: game loop ... update logic check collision render update display ... end game loop in the check collision method, I do: *static* stencil_refs_cursor = 0 *static* int[] stencil_refs = new int[]{1, 2, 4, 8, 16, 32, 64, 128} if fast bounding box check scissors area # to reduce the area for stencil clearing, drawing to stencil buffer, and occlusion query if (stencil_refs_cursor == 0) glClear(GL_STENCIL_BUFFER_BIT) int stencilRef = stencil_refs[stencil_refs_cursor++] if (stencil_refs_cursor == stencil_refs.length) stencil_refs_cursor = 0 glStencilFunc(GL_ALWAYS, stencilRef, stencilRef); glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); draw sprite A glStencilFunc(GL_EQUAL, stencilRef, stencilRef); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); # start occlusion query glBeginQuery(GL_SAMPLES_PASSED, occquery); ... end if fast boounding box check Am I playing correctly with the ref and mask parameters of glStencilFunc? Should I also use glStencilMask? Is my idea impossible? Thanks for your replies! WS [Edited by - wondersonic2 on June 24, 2010 9:25:41 AM]
  4. Quote:Original post by DensitY Quote:Original post by jyk I think the simplest solution would probably be to make the game fully 3-d, and just have the '2-d' part of the game all take place in the same plane (more or less, at least). I Echo this very much. It'll be easier to render your 2d objects as billboard quads with a fixed depth (Y = 0, I normally have Z pointing up). You can treat the collision etc the same as before (no change basically!). All you're changing is how its drawn. Your 3d artists can just work around the 2d game field being on Y = 0 and model around it. As a bonus they can create things like 3d tunnels for you to fly through and it'll all render correctly, without any special tricks. Hmmm and how do you then implement collision detection with say some 3D walls? :) Indeed, that's the point here ;) If you have some ideas, don't hesitate :)
  5. One idea, I just had: If I can't make the 3D background move at the speed of the 2D foreground tiles... I'm sure I can make the 2D foreground tiles move at the speed of the 3D foreground. I'll try tomorrow to implement this :)
  6. Quote:Original post by jyk I think the simplest solution would probably be to make the game fully 3-d, and just have the '2-d' part of the game all take place in the same plane (more or less, at least). I don't know what method you're using for collision detection, so I can't really comment directly on that. Whatever method you're using though, I'd be surprised if it couldn't be adapted to work alongside a 3-d perspective projection. Thanks for your reply. My collision detection process is explained here: http://code.google.com/p/tf4r/wiki/PixelPerfectCollisionDetection Now, I've seen with a friend who told me that implementing everything in 3D is maybe harder than 2D foreground + 3D background because in this case, and regarding the previous method for collision detection, I'll have to manage the rendering of the 3D background for common rendering and for collision detection (2 differents things). For example, for collision detection, I could use plane clipping but this clips the vertices (am I right?) since afterwards, I don't get anything displayed (and thus no collision possible); instead I would require some "pixel plane clipping" but I don't know how to do it now T-T.
  7. Quote:Original post by Grumple Hi Guys, I just ported some OpenGL rendering code that worked fine running on Windows XP/Visual Studio 2005 to Windows 7/Visual Studio Express 2010. The port was generally smoother than I had even hoped...it ran almost immediately with just some minor tweaking. However, I noticed one really strange issue; there is a small transparent gap at the edges of all my triangles. It looks to be just a single or few pixels wide, but it is affecting every triangle I render. I had never seen this on XP and non of my OpenGL config has changed. I admittedly haven't dug deep searching for the cause yet in code, but I'm hoping someone here has a quick and dirty answer? Thanks! Hello, do you have some screenshot? Regards, WS
  8. Hello, For the (open source) 2D game I'm working on, I wish to add some 3D backgrounds with perspective! You can see this effect here: http://www.youtube.com/watch?v=Z5M2XKGyV0w at the 3rd minute and 17th second: a 3D corridor with perspective. My game being a 2D shoot'em up, I already have pixel perfect (2D) collision detection. So I'm planning to have the corridor ground drawn in 2D (useful for collision detection) but the background will be a 3D object (3 textured quads). So far, I've successfully implemented orho2D and 3D perspective switch in my render method but now I wish to make these 2 elements (2D corridor ground and 3D background) move at the same speed and here comes my problem... Do you have any idea of the maths involved behind this? I guess, it's all about projection setup and efficient speed ratio between 2D and 3D world? After working on it during 2 days, I wonder if the simplest way wouldn't be to implement everything in 3D and to enhance my collision detection to work with 3D objects by clipping z-coordinates (display object surfaces only where z is 0). If so, what are the opengl commands to perform that? Thanks for your comments! I really need some light here :) Regards, WS [Edited by - wondersonic2 on June 15, 2010 3:34:15 AM]