Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Clipping Planes!

SephirothSephiroth Fayetteville, NC, USAMember Posts: 1,035
Hey, I toyed with [b]gluLookAt()[/b] for all of five minutes and then implemented it into my game engine. All of my problems are now fixed! The game runs AWESOME in debug on my machine, but OpenGL seems to crash the living crap out of my 3dfx card's OpenGL driver. I have found this problem to be a clipping problem. I have been all through the OpenGL Red Book, and they explain nothing about clipping in there, other than how to setup six extra clipping planes, relative to the camera, not screen. How can I write a clipping routine for my engine that will clip just the edges of the window it's running in? If I can get this done I can research collision detection and then release an actual playable demo! So, does anybody know how to clip to a window, preferably without using much GPU/CPU power so it will render faster once texturing is finished? Thanks in advance for the help.

-[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

Comments

  • gautamgautam Member Posts: 642
    Not sure but shouldn't GL_CULLFACE(look up on culling) do that for you ??

  • SephirothSephiroth Fayetteville, NC, USAMember Posts: 1,035
    : Not sure but shouldn't GL_CULLFACE(look up on culling) do that for you ??
    :
    :
    Cull is used to draw or not draw the backside of poly's. That saves a TON of GPU/CPU power when drawing complex images and you only need to texture the visible polys. I need to clip polys that are outside the view and what-not.

    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

  • MutilateMutilate Member Posts: 22
    Well...it depends from what u mean by clipping.
    If u mean only find out if a poly is inside or outside the screen then I know the answer:
    Just check if all the point are outside one, and only one, clipping plane. by only one I mean that u need to check the points against only one clipping plane at the time, because u may have all point out of the screen and still have to draw a part of the poly. But u dont need to draw the poly if all point are out against one of the six clipping plane.
    I check this way: if rP=(rPx,rPy,rPz) is the camera-relative point and pP=(pPx,pPy) is his projection.
    check against the near Z plane: if rPz>NZ_Plane -> Poly have to be draw
    check against the far Z plane: if rPz Poly have to be draw
    check against the right line of the screen: if pPx>RS_Line -> Poly have to be draw
    check against the left line of the screen: if pPx Poly have to be draw
    check against the upper line of the screen: if pPy>US_Line -> Poly have to be draw
    check against the bottom line of the screen: if pPy>BS_Line -> Poly have to be draw

    If u can get the camera-relative's and the projected coordinates, u have to check against the plane normal whit a dot product.
    plane center (a point in the plane): PC=(PCx,PCy,PCz), one poly's point P=(Px,Py,Pz), plane normal vector NV=(NVx,NVy,NVz)
    if (Px-PCx)*Nx+(Py-PCy)*Ny+(Pz-PCz)*Nz > 0 -> Poly have to be draw

    But if by clipping you mean also tear apart the poligon that are partially outside (and therefore inside) the screen... I know the answer too but it would take me a lot more space to answer.

    I dont know a lot about opengl and stuff, but you should try to use it cause this should be included in the hardware acceleration (GPU).to

    Mutilate
  • SephirothSephiroth Fayetteville, NC, USAMember Posts: 1,035
    Actually it WAS the near clip plane that caused the exception 10H, but I got to talk with some OpenGL gurus at www.opengl.org and found out that the exception was a divide by zero! So, Borland doesn't turn off division by zero errors by default, which was a problem. I continued talking with them and found out that I can force a div by zero to return 0 rather than crash by using "_control87()", and now the engine runs PERFECTLY!
    Ugh, now for collision detection...

    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

Sign In or Register to comment.