Menu

Color conversion – Function Tvector4f to TGLcolor

Help
Sergio
2017-05-20
2017-05-20
  • Sergio

    Sergio - 2017-05-20

    I am trying to use the code below to change the color of a transparente cube in RUNTIME using LHiddenLineShader5 (as in linning demo - greencube component) . If I set the color in design time it works but in runtime give the error Incompatible types: 'TGLColor' and 'TVector4f' Should I use a conversion function to convert the variable cores from 'TVector4f'to TGLcolor. If so, which function is this ?

    procedure TF_3DD.Make_a_Cube(cores:TVector; EmissColor:single; transparMode:integer);
    begin
    if cubi<>nil then cubi.free;
    Cubi := TGLCube(DC1.AddNewChild(TGLCube));
    with cubi do
    begin
    Material.MaterialLibrary := GLMaterialLibrary1 ;
    Material.LibMaterialName := 'LibMatHiddenLineShader5' ;
    GLMaterialLibrary1.Materials[2].Material.BlendingMode := bmTransparency;
    GLHiddenLineShader5.BackgroundColor:= cores; <<<<<<<<< do not work giving error 010 Incompatible types: 'TGLColor' and 'TVector4f'
    // Material.FrontProperties.Emission.Color:=cores ; // this Works if I call like this using Make_a_Cube( clrwhite , 0.3 , 0 );
    GLHiddenLineShader5.BackgroundColor.alpha:= EmissColor ; // like 0,3
    StructureChanged ;
    end;
    end;

     
  • Jerome.D (BeanzMaster)

    Hi
    Just add .DirectColor
    eg : Material.FrontProperties.Emission.Color := cores.DirectColor ;

    Cheers ;)

     
  • Sergio

    Sergio - 2017-05-23

    Hi Jerome I was doing some truals before replying you. Thank you for the DirectColor
    It works well in this way Material.FrontProperties.Emission.Colo.DirectColor := cores;

    However by some reason that I do not know how to correct the shaders are not working properly in runtime. So I used a "bad and long" solution in designtime with 4 shadres (instead of just one in runtime).
    The code is below and generated the attached figure.
    The only bad thing in the figure are the diagonals in each face. Years ago I could do it using shaders without the diagonal. Now I can not find this solution. Cheers

    procedure TF_3DD.Make_a_Cube(CubNum:integer;Est_or_Dyn:boolean;
    cubi:TGLCube;cubiName:string;
    position_X,position_Y,position_Z:single;
    CubeColor:TColorVector;EmissColor:single;
    cub_width,cub_height,cub_depth:single;
    dirX,dirY,dirZ,upX,upY,upZ,pitchAng,rollAng,turnAng:single;
    visivel:boolean; transparMode:integer);

    begin
    if cubi<>nil then cubi.free;
    Cubi := TGLCube(DC1.AddNewChild(TGLCube));
    with cubi do
    begin
    name:= cubiName;
    Position.AsVector := VectorMake(position_X,position_Y,position_Z);
    Material.MaterialLibrary := GLMaterialLibrary1 ;
    // GLHiddenLineShader1.BackgroundColor.DirectColor:= cubeColor ; <<< do not work for many cubes
    if cubNum = 1 then
    begin
    Material.LibMaterialName := 'LibMaterial1' ;
    GLMaterialLibrary1.Materials[2].Material.BlendingMode := bmTransparency;
    GLMaterialLibrary1.Materials[2].shader:= GLhiddenLineShader1;
    GLHiddenLineShader1.BackgroundColor.alpha:= EmissColor ; // like 0,3
    end;
    if cubNum = 2 then
    begin
    Material.LibMaterialName := 'LibMaterial2' ;
    GLMaterialLibrary1.Materials[3].Material.BlendingMode := bmTransparency;
    GLMaterialLibrary1.Materials[3].shader:= GLhiddenLineShader2;
    GLHiddenLineShader2.BackgroundColor.alpha:= EmissColor ; // like 0,3
    end;
    if cubNum = 3 then
    begin
    Material.LibMaterialName := 'LibMaterial3' ;
    GLMaterialLibrary1.Materials[4].Material.BlendingMode := bmTransparency;
    GLMaterialLibrary1.Materials[4].shader:= GLhiddenLineShader3;
    GLHiddenLineShader3.BackgroundColor.alpha:= EmissColor ; // like 0,3
    end;
    if cubNum = 4 then
    begin
    Material.LibMaterialName := 'LibMaterial4' ;
    GLMaterialLibrary1.Materials[5].Material.BlendingMode := bmTransparency;
    GLMaterialLibrary1.Materials[5].shader:= GLhiddenLineShader4;
    GLHiddenLineShader4.BackgroundColor.alpha:= EmissColor ; // like 0,3
    end;
    CubeDepth := cub_depth;
    CubeHeight := cub_height;
    Cubewidth := cub_width;
    Direction.AsVector := VectorMake(dirX,dirY,dirZ );
    Up.AsVector := VectorMake(upX,upY,upZ);
    pitchAngle:= pitchAng;
    rollAngle := rollAng;
    turnAngle := turnAng;
    visible:= visivel;
    StructureChanged ;
    end;
    end;

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.