Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: OpenGL Blur effect...

  1. #1

    OpenGL Blur effect...

    Hi all,

    Yet another problem lol

    Im trying to get a rubik's cube with a blur effect, how ever i get something else :s Its a nice effect and all, but not what i want...

    I looked at the examples from NeHe, sulaco and somewhere else i cant remember..

    What im getting is:




    My code is as follows:
    Code:
    procedure Box(const Pos: TVector3f);
    
      procedure renderPoint(Point: TVector3f);
      var
        p,n: TVector3f;
      begin
        p := Point;
        n := VectorNormalize(p);
        glNormal3fv(@n);
        glVertex3fv(@p);
      end;
    
    begin
      If bindEnv Then
      Begin
        glEnable(GL_TEXTURE_GEN_S);
        glEnable(GL_TEXTURE_GEN_T);
        glEnable(GL_BLEND);    
        _XMaterials.Bind(cubEnv, Nil);
      End Else
         _XMaterials.Bind(cubTex, Nil);
    
      glBegin(GL_QUADS);
      // front
        glTexCoord2f(0, 0); renderPoint(Vector3fMake(Pos[0],      Pos[1],      Pos[2]));
        glTexCoord2f(0, 1); renderPoint(Vector3fMake(Pos[0],      Pos[1]+Size, Pos[2]));
        glTexCoord2f(1, 1); renderPoint(Vector3fMake(Pos[0]+Size, Pos[1]+Size, Pos[2]));
        glTexCoord2f(1, 0); renderPoint(Vector3fMake(Pos[0]+Size, Pos[1],      Pos[2]));
    
        glTexCoord2f(0, 0); renderPoint(Vector3fMake(Pos[0]+Size, Pos[1],      Pos[2]));
        glTexCoord2f(0, 1); renderPoint(Vector3fMake(Pos[0]+Size, Pos[1]+Size, Pos[2]));
        glTexCoord2f(1, 1); renderPoint(Vector3fMake(Pos[0]+Size, Pos[1]+Size, Pos[2]+Size));
        glTexCoord2f(1, 0); renderPoint(Vector3fMake(Pos[0]+Size, Pos[1],      Pos[2]+Size));
    
        glTexCoord2f(0, 0); renderPoint(Vector3fMake(Pos[0],      Pos[1],      Pos[2]+Size));
        glTexCoord2f(0, 1); renderPoint(Vector3fMake(Pos[0],      Pos[1]+Size, Pos[2]+Size));
        glTexCoord2f(1, 1); renderPoint(Vector3fMake(Pos[0]+Size, Pos[1]+Size, Pos[2]+Size));
        glTexCoord2f(1, 0); renderPoint(Vector3fMake(Pos[0]+Size, Pos[1],      Pos[2]+Size));
    
        glTexCoord2f(0, 0); renderPoint(Vector3fMake(Pos[0]     , Pos[1],      Pos[2]));
        glTexCoord2f(0, 1); renderPoint(Vector3fMake(Pos[0]     , Pos[1]+Size, Pos[2]));
        glTexCoord2f(1, 1); renderPoint(Vector3fMake(Pos[0]     , Pos[1]+Size, Pos[2]+Size));
        glTexCoord2f(1, 0); renderPoint(Vector3fMake(Pos[0]     , Pos[1],      Pos[2]+Size));
    
        glTexCoord2f(0, 0); renderPoint(Vector3fMake(Pos[0]+Size, Pos[1]+Size, Pos[2]));
        glTexCoord2f(0, 1); renderPoint(Vector3fMake(Pos[0]+Size, Pos[1]+Size, Pos[2]+Size));
        glTexCoord2f(1, 1); renderPoint(Vector3fMake(Pos[0]     , Pos[1]+Size, Pos[2]+Size));
        glTexCoord2f(1, 0); renderPoint(Vector3fMake(Pos[0]     , Pos[1]+Size, Pos[2]));
    
        glTexCoord2f(0, 0); renderPoint(Vector3fMake(Pos[0]+Size, Pos[1]     , Pos[2]));
        glTexCoord2f(0, 1); renderPoint(Vector3fMake(Pos[0]+Size, Pos[1]     , Pos[2]+Size));
        glTexCoord2f(1, 1); renderPoint(Vector3fMake(Pos[0]     , Pos[1]     , Pos[2]+Size));
        glTexCoord2f(1, 0); renderPoint(Vector3fMake(Pos[0]     , Pos[1]     , Pos[2]));
      glEnd;
    
      If bindEnv Then
      Begin
        _XMaterials.UnBind(cubEnv, Nil);
        glDisable(GL_TEXTURE_GEN_S);
        glDisable(GL_TEXTURE_GEN_T);
      End Else
         _XMaterials.Bind(cubTex, Nil);
    end;
    
    procedure DCCube;
    begin
      glPushMatrix;
        Box(Vector3fMake(-11,-11,-11)); Box(Vector3fMake(  0,-11,-11)); Box(Vector3fMake( 11,-11,-11));
        Box(Vector3fMake(-11,-11,  0)); Box(Vector3fMake(  0,-11,  0)); Box(Vector3fMake( 11,-11,  0));
        Box(Vector3fMake(-11,-11, 11)); Box(Vector3fMake(  0,-11, 11)); Box(Vector3fMake( 11,-11, 11));
    
        Box(Vector3fMake(-11,  0,-11)); Box(Vector3fMake(  0,  0,-11)); Box(Vector3fMake( 11,  0,-11));
        Box(Vector3fMake(-11,  0,  0)); Box(Vector3fMake(  0,  0,  0)); Box(Vector3fMake( 11,  0,  0));
        Box(Vector3fMake(-11,  0, 11)); Box(Vector3fMake(  0,  0, 11)); Box(Vector3fMake( 11,  0, 11));
    
        Box(Vector3fMake(-11, 11,-11)); Box(Vector3fMake(  0, 11,-11)); Box(Vector3fMake( 11, 11,-11));
        Box(Vector3fMake(-11, 11,  0)); Box(Vector3fMake(  0, 11,  0)); Box(Vector3fMake( 11, 11,  0));
        Box(Vector3fMake(-11, 11, 11)); Box(Vector3fMake(  0, 11, 11)); Box(Vector3fMake( 11, 11, 11));
      glPopMatrix;
    end;
    
    procedure RenderDCCube_ENV;
    begin
      bindEnv := False;
      DCCube;
    
      glDisable(GL_BLEND);  
      glBlendFunc(GL_SRC_ALPHA, GL_ONE);  
    
      bindEnv := True;
      DCCube;
    end;
    
    procedure createTexture;
    var
      rX,rY,rZ: Integer;
    begin
      glBlendFunc(GL_SRC_ALPHA, GL_ONE);
      
      glPushAttrib(GL_ALL_ATTRIB_BITS);
      glViewport(0, 0, 128, 128);
      glClear(GL_COLOR_BUFFER_BIT Or GL_DEPTH_BUFFER_BIT);
    
      _XCameras[_XEngine.Camera].Render;
    
        glTranslatef(0, 0, Z);
        glRotatef(rot[0], 1, 0, 0);
        glRotatef(rot[1], 0, 1, 0);
        glRotatef(rot[2], 0, 0, 1);
    
        RenderDCCube_ENV;
    
        glMatrixMode(GL_PROJECTION);
        glPopMatrix;
    
        glMatrixMode(GL_MODELVIEW);
        If blrTex > 0 Then
        Begin
          glBindTexture(GL_TEXTURE_2D, blrTex);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
          glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 128, 128);
        End Else
        Begin
          glGenTextures(1, @blrTex);
          glBindTexture(GL_TEXTURE_2D, blrTex);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
          glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 128, 128, 0);
        End;
      glPopAttrib;
    end;
    
    procedure InitDCubes;
    begin
      glBlendFunc(GL_SRC_ALPHA, GL_ONE);
      cubTex := _XMaterials.Add(BASE_DIR+'data.src\cube.png');
      cubEnv := _XMaterials.Add(BASE_DIR+'data.src\Envmap.bmp');
    end;
    
    procedure PreRenderDCubes;
    begin
      glEnable(GL_DEPTH_TEST);
      createTexture;
    end;
    
    procedure RenderDCubes;
    var
      a1,a2: Single;
      i,rX,rY,rZ: Integer;
      aspect: Double;
    begin
      glEnable(GL_DEPTH_TEST);
      glTranslatef(0, 0, Z);
      glRotatef(rot[0], 1, 0, 0);
      glRotatef(rot[1], 0, 1, 0);
      glRotatef(rot[2], 0, 0, 1);
    
      RenderDCCube_ENV;
    
      glDisable(GL_LIGHTING);
      glDisable(GL_DEPTH_TEST);
    
      glBindTexture(GL_TEXTURE_2D, blrTex);
      glColor4f(1, 1, 1, 1/numSamples);
    
      _XEngine.Ortho(True);
    
      a1 := 1;
      a2 := 1/(numSamples-1)*blrDistance;
    
      For i := 0 To numSamples Do
      Begin
        a1 := a1+a2;
        glBegin(GL_QUADS);
          glTexCoord2f(0, 0); glVertex2f(-a1,-a1);
          glTexCoord2f(1, 0); glVertex2f( a1,-a1);
          glTexCoord2f(1, 1); glVertex2f( a1, a1);
          glTexCoord2f(0, 1); glVertex2f(-a1, a1);
        glEnd;
      End;
    
      _XEngine.Ortho(False);
    
      rot[0] := rot[0]+Sin(50/(_XEngine.Delta/200));
      rot[1] := rot[1]+Sin(60/(_XEngine.Delta/200));
      rot[2] := rot[2]+Sin(70/(_XEngine.Delta/200));
    
      If rot[0] > 360 Then rot[0] := 0;
      If rot[1] > 360 Then rot[1] := 0;
      If rot[2] > 360 Then rot[2] := 0;
    
      If rot&#91;0&#93; < 0 Then rot&#91;0&#93; &#58;= 360;
      If rot&#91;1&#93; < 0 Then rot&#91;1&#93; &#58;= 360;
      If rot&#91;2&#93; < 0 Then rot&#91;2&#93; &#58;= 360;
    end;
    Im guessing that its just rendering the blur as the textures of the cube instead, but i cant for the life of me work out how and why :s im sure i've missed something really dumb..

    Thanks
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  2. #2

    OpenGL Blur effect...

    I haven't touched OpenGL in quite awhile so I'm a bit rusty, but if I recall the most simple way to do a motion blur is to set the clear-scene color (the one you draw before each frame renders) to have an alpha value of about 0.8.

  3. #3

    OpenGL Blur effect...

    Thanks for the top

    I have managed to get it working after a re-write... and i changed the alpha of the clear colour and all seems to work good

    heres a screeny:



    Thanks again
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  4. #4

    OpenGL Blur effect...

    Awesome looking effect. I like it!

    You're welcome, I'm just glad I remembered how to do it.

  5. #5

    OpenGL Blur effect...

    Thanks

    I've updated it so that it looks like it is glowing on the inside of the cube, all i have to do now is think of a way that i can have it rotate throught the colours :?

    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  6. #6

  7. #7
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    OpenGL Blur effect...

    Very nice indeed.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  8. #8

    OpenGL Blur effect...

    Ooh! I know!

    Draw the whole thing in greyscale and then draw an additive color overlay! Voila! Rotating, colorized, blurred cubes!

    Though, if you don't want something else beneath/within the cube to be the same color that'd be a mess.

  9. #9

    OpenGL Blur effect...

    Thanks for all the comments

    heres a few more, i now have it bluring from white to red with a blue flash from with in




    It sort of looks like theres lightning with in the cube
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  10. #10

    OpenGL Blur effect...

    Awesome! If you wanted to get psychedelic with it, you could stretch a dynamic plasma texture over it... but that could make some folks sick. Heh.

Page 1 of 2 12 LastLast

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
  •