Transparent materials on laptops in Delphi 7

WHAT I TRY TO DO

I am trying to draw some graphs in Timage. These graphics that I draw consist of ordered layers with Foodfills and lines. I use several buffers to provide sequencing and double buffering.

WHAT TO DO

procedure DrawScene(); var ObjLength,LineLength,Filllength,Obj,lin,angle,i:integer; Npoints : array[0..1] of Tpoint; Objmap:TBitmap; wholemap:TBitmap; begin wholemap := TBitmap.Create; wholemap.Width:=area; wholemap.height:=area; ObjLength:=length(Objects); for Obj:=0 to (ObjLength-1) do if objects[Obj].Visible then begin // create object bitmap if Objects[obj].Tag='FBOX' then begin Objmap := TBitmap.Create; Objmap.Width:=area; Objmap.height:=area; Objmap.Transparent:=true; Objmap.Canvas.Rectangle((objects[obj].Boundleft-4)+objects[obj].Position.x,area-((objects[obj].boundtop+4)+objects[obj].Position.y),(objects[obj].boundright+4)+objects[obj].Position.x,area-((objects[obj].boundbottom-4)+objects[obj].Position.y)); end; //draw object LineLength:=length(objects[Obj].Lines)-1; angle:=objects[Obj].Rotation; for lin:=0 to (LineLength) do begin for i:=0 to 1 do begin Npoints[i] := PointAddition(RotatePoint(objects[obj].Lines[lin].Point[i],angle),objects[obj].Position,false); end; Objmap:=DrawLine(Npoints[0].x,Npoints[0].y,Npoints[1].x,Npoints[1].y,objects[obj].Lines[lin].Color,Objmap); end; Filllength:=length(objects[Obj].Fills)-1; for i:=0 to Filllength do begin Npoints[0]:=PointAddition(RotatePoint(objects[Obj].Fills[i].Point,objects[Obj].Rotation),objects[Obj].Position,false); Objmap:=fillpoint( Npoints[0].x, Npoints[0].y,objects[Obj].Fills[i].color,Objmap); end; //write object to step frame wholemap.Canvas.Draw(0,0,Objmap); Objmap.Free; end; // write step frame to Visible Canvas mainwindow.bufferim.Canvas.Draw(0,0,wholemap); mainwindow.RobotArea.Picture.Graphic:=mainwindow.bufferim.Picture.Graphic; wholemap.Free; end; 

WHAT I EXPECT

I expect that each image object will be on top of each other, with each image level being a complete image for this layer. In my example, this is a robot with a flag behind it. first a flag is formed, and then a robot.

WHAT I GET (on PC)

on pc, I get what I expect, and everything seems to be correct.

WHAT I GET (on laptop)

On almost every laptop and some PCs, I see only a robot. I put some statuses to see if he draws a flag, and he does it. the game can even interact with the flag in the correct order. Further investigation showed me that it showed only the last image drawn by me "drawscene", and when the images were drawn directly on the whole universe, which is in the open air (this cannot be done to overlap the reasons for filling the layers)

WHAT I THINK NOW

therefore, I realized that the Timage.transparent Timage property does not work or is calculated differently on some machines.

I did a test to prove it, and made a red canvas. then to the canvas that I painted on 0,0 I Timage with the property transparent = true, with only one point in the middle to the red canvas. resuly was a white canvas with a dot in the middle.

I suppose, and the results show that machines with very basic graphics drivers seem to handle zero or transparent white, since more powerful machines seem to handle zero or transparent transparent.

this seems a bit unfortunate because the Timage.Transparent property was true.

EDIT: UPDATE !!! It seems that on ATI video cards, if the color is β€œzero”, it is interpreted in the PF24bit format and, therefore, there is no alpha channel and transparency.

on Nvidia cards, it accepts this as PF32bit and treats null as transparent.

An obvious way to get around this woulf is to install the bitmapp on PF32bit, but this still doesn't work. Then I suggested that maybe this is not enough, and I have to make sure that the SET background is transparent and not left as null .. but there are no tools (which I see) inside Timage to set the color with alpha. all canvas painting functions require Tcolor, which is 24-bit RGB, and one TcolorRef with 32-bit RGBA will do .... is there a way to paint with alpha 0?

WHAT I THINK WHAT I NEED TO KNOW

How to make the Transparent property work on all machines or a way to make laptops not insert transparent like white Or a way to achieve the same result.

Anyone have any solutions or ideas?

+4
source share
3 answers

I use the graphics library (AggPas) to help with drawing graphics, and one of the things I noticed is that I always need the Bitmap.PixelFormat = pf32bit line to make it paint transparency.

Having said that, I am using TransformImage from the AggPas library to copy an image with a transparent background to another, and AggPas only accepts pf24bit or pf32bits in pixel format (otherwise it does not attach to the bitmap)

+2
source

I have seen similar behavior on different machines in the past (several years ago).

They were caused by different graphics cards and drivers. Either NVideo or ATI got the wrong results, but I forgot which ones.

It can be played on laptops as well as on ordinary PCs.

So: what graphics cards and drivers do you use?

- Jeroen

+2
source

I would explicitly set the bitmap format to pf32bit for each bitmap you created to ensure that the problem does not convert colors from 32 to 16 bits (if this is the native resolution of the video of the created bitmaps), which can interfere with how transparency works. Also, I was lucky to have used transparency color in the past.

Another option β€” perhaps the best in the long run β€” is to instead set the alpha channel on images (i.e. use PNG files) and use the GDI AlphaBlend () function to draw graphics.

+1
source

Source: https://habr.com/ru/post/1315891/


All Articles