M109uk
07-05-2007, 12:23 PM
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:
http://www.pulse-soft.oneuk.com/images/stories/prj_devilscube/blur_attempt1.jpg
(http://www.pulse-soft.oneuk.com/images/stories/prj_devilscube/blur_attempt1.jpg)
My code is as follows:
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[0] < 0 Then rot[0] := 360;
If rot[1] < 0 Then rot[1] := 360;
If rot[2] < 0 Then rot[2] := 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
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:
http://www.pulse-soft.oneuk.com/images/stories/prj_devilscube/blur_attempt1.jpg
(http://www.pulse-soft.oneuk.com/images/stories/prj_devilscube/blur_attempt1.jpg)
My code is as follows:
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[0] < 0 Then rot[0] := 360;
If rot[1] < 0 Then rot[1] := 360;
If rot[2] < 0 Then rot[2] := 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