Page 20 of 20 FirstFirst ... 10181920
Results 191 to 198 of 198

Thread: Garland's Quest

  1. #191
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25
    The 3D water is still killing me. I figured out how to have the water actually move with them map, but I'll be damned if I can figure out how to have it draw within a set confines of a viewport.

    Any 3D OpenGL experts out there?
    Jason McMillen
    Pascal Game Development
    Co-Founder





  2. #192
    Quote Originally Posted by WILL View Post
    The 3D water is still killing me. I figured out how to have the water actually move with them map, but I'll be damned if I can figure out how to have it draw within a set confines of a viewport.

    Any 3D OpenGL experts out there?
    If you want to clip the water within a rectangular part of the screen (viewport), you can use code like this (origin at top left of screen):

    Code:
    procedure TxeGraphics.SetClippingRect_2d(x,y,w,h: Word);var
      xeMax    : Integer;
      xeMin    : Integer;
      glMax    : Integer;
      glMin    : Integer;
      scissorY : Integer;
    begin
      if (x = 0) and (y = 0) and (w = FWidth) and (h = FHeight) then
      begin
        glDisable(GL_SCISSOR_TEST);
        Exit;
      end;
    
    
      glEnable(GL_SCISSOR_TEST);
    
    
      // in 2d mode, OpenGL y-coords are 0 at bottom, FHeight - 1 at top
      glMax := FHeight - 1;
      glMin := 0;
      // in 2d mode, xe y-coords are 0 at top, FHeight - 1 at bottom
      xeMax := 0;
      xeMin := FHeight - 1;
    
    
      scissorY := glMin + (glMax - glMin) * ((y - xeMin) div (xeMax - xeMin));
    
    
      glScissor(x,scissorY,w,h);
    end;
    If you want a non-rectangular clipping region, you need to use the stencil buffer I believe....
    Games:
    Seafox


    Pages:
    Syntax Error Software itch.io page

    Online Chess
    http://gameknot.com/#paul_nicholls

  3. #193
    I prefer the stencil do restrict rendering to a given region of the screen. Scissor has some drawbacks, for example that you need to specify it's region in window coordinates and (as Paul said) you're restricted to a single rectangular region. So some time ago I removed all scissor-stuff from my GUI and replaced it with stenciling. It's a bit more code but offers more freedom and allows you to clip out any shape you want and even do CSG on your shapes to clip out complex areas (it even allows you to cut out threedimensional areas, see here) :

    Code:
    // Clear the stencil buffer (usually done at start of rendering)
    glClear(GL_STENCIL_BUFFER_BIT);
    
    // We fill the stencil buffer now with the shape that we want our stuff be drawn in
    glDepthFunc(GL_ALWAYS);                           // Don't care about depth values for our stencil shape
    glColorMask(False, False, False, False);          // We don't want to see the shape, so we disable rendering to the color buffer
    glEnable(GL_STENCIL_TEST);                        // Activate stencil
    glStencilFunc(GL_ALWAYS, 1, 1);                   // Write to stencil, no matter what's currently in place and set it to 1  
    glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);        // Control behaviour of stencil writing, for our scenario, only the last value matters. GL_REPLACE means that our shape sets the buffer to 1 where it's drawn 
    
    // Draw the shape in which you want your stuff below drawn here
    // Can be of any complexity, you could even create a chess-board cutout, a real 3D-coutout, etc.
    // You can do a simple GL_QUAD, GL_TRIANGLE or render a 3D-model here
    DrawPlainRect(0, 0, 0, Width, Height);
    
    // Now we're going to render our scene / objects so that they're only visible where the stencil was set by our shape
    glColorMask(True, True, True, True);              // Needs to be enabled again, as we want to see our object
    glStencilFunc(GL_EQUAL, 1, 1);                    // Now we only want to draw where the stencil buffer is 1 (as set by our shape), the rest of our screen contains zero
    glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);           // No change to the stencil buffer
    glEnable(GL_STENCIL_TEST);                        // Activate it
    glDepthFunc(GL_LEQUAL);                           // Restore our normal depth test
    
    // Render anything here you want to have stencilled out
    
    glDisable(GL_STENCIL_TEST);
    See the comments for how the stencil actually works. It's pretty complex and not only limited to restricting rendering to a certain area. You can even use it to count pixels and stuff.

    And though this is a bit more code than the scissor stuff, it's extremly flexible. E.g. by just replacing glStencilFunc(GL_EQUAL, 1, 1) with glStencilFunc(GL_NOTEQUAL, 1, 1) for rendering your scene, you'd render only "outside" of the stencil shape

  4. #194
    Very cool Sascha! I wasn't sure how to use the stencil buffer myself before, only the theory, so that code will be very helpful
    Games:
    Seafox


    Pages:
    Syntax Error Software itch.io page

    Online Chess
    http://gameknot.com/#paul_nicholls

  5. #195
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25
    Wow, that's pretty cool Sascha.

    I should get you to write a couple of basic tutorials on using the Stencil functions for the upcoming 4th issue of Pascal Gamer mag. Just something to get people started maybe.

    Unfortunately I've given up on 3D water as I'm realizing that thats not where my strengths lay. So sticking to what I know and that's 2D. Doesn't mean the water will look bad, actually I've been focusing on that alone lately trying to come up with something rather nice for once. I found some great textures and I took some of my caustics lighting tiles and tried layering them together. With a few alpha tricks and the nice pretty lighting animation below it. It looks pretty decent.


    Screen Shot 2013-01-06 at 6.32.46 PM.jpg Screen Shot 2013-01-06 at 6.39.04 PM.jpg

    What do you guys think?
    Jason McMillen
    Pascal Game Development
    Co-Founder





  6. #196
    Looks ok from here, could you try making a video of it animating?
    Games:
    Seafox


    Pages:
    Syntax Error Software itch.io page

    Online Chess
    http://gameknot.com/#paul_nicholls

  7. #197
    Looks verry nice.
    And since you are using layering why not try and make water tiles semitransparent and then render the botom textures below, closer to shore more visible the botom texture is. This way you could get the impresion of increasing water depth which would look realy nice.
    Also since you are using layering you might wanna go and use larger textures whose dimensions are actually bigger than tile dimensions. This way the textures will look less repetive (you can clearly see repetive paterns in water texture in the left picture).

  8. #198
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25
    Well I am using 2 layers really.

    The first is the caustic lighting effect animation consisting of 36 frames with some coloring thrown in.

    The second is a 1:1 scale seamless texture that I found, scalled down to the 80x80 size required, added a bit of an alpha mask and put it all together in-game.

    The caustic lighting cycles through it's animation and on top I draw the water surface texture with an alpha value that goes up and down just slightly as to give it a nice animated effect.

    I'll see about posting a video of it sometime soon.

    The real fun stuff is what I've been up to lately. Graphics is nice an all, but I've finally been adding 2 things I've been dying to do for a while now; Message Scrolls and Hidden Objects inside of Objects. Hint: Magic gets them out.

    I think that this will give a lot more to the gameplay and allow me to tell a bit more of the story as you play through it.
    Jason McMillen
    Pascal Game Development
    Co-Founder





Page 20 of 20 FirstFirst ... 10181920

Bookmarks

Posting Permissions

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