PDA

View Full Version : DXDraw.Options: do3D Problems



kotai
13-12-2007, 11:26 AM
Hi

I have some problems adding do3D to the DXDraw options. The problems are that the function Picture.TransparentColor doesn't return the right color, when I turn an sprite or image into transparent then the borders are bad cut, and I'm not allowed to use backgroundsprites of more than 4096 pixels wide. Detailing:

1)PICTURE.TRANSPARENTCOLOR doesn't work

To turn the sprites and images transparent I used the next function:


DXImageList.Items[8].TransparentColor := DXImageList.Items[8].Picture.TransparentColor;
DXImageList.Items[8].Transparent := True;

But when I add DXDraw.Options := DXDraw.Options + [do3D] it stops working and all sprites and images are viewed into a square. I solved with the following change:


DXImageList.Items[8].TransparentColor := DXImageList.Items[8].Picture.Bitmap.Canvas.Pixels[ 0,DXImageList.Items[8].Height-1];
DXImageList.Items[8].Transparent := True;

http://www.miniracingonline.com/images/noticias/fondo.JPG

2)BORDERS CUT

Now that I have solved the transparency I realise that images and sprites doesn't cut the edges correctly, and some parts of the paint not transparent are not shown. In the case of images I tried with DXImageList.Items[62].Draw(...) and with DXImageList.Items[62].DrawAlpha(...) and the effect is the same. I don't know how to solve this error, it's just like the TransparentColor would be a set of similar colors and not only one, like it has a % of margin for similar colors.

http://www.miniracingonline.com/images/noticias/bordes.JPG

3) BACKGROUNDSPRITE.WIDTH > 4095
Another big problem is when I load the sprite for the background, if it's minor than 4096 it works well, but when it reaches 4095 or more pixels the image keeps its size (by example 6700 pixels) but only shows the first 4096 first pixels of the image stretching to the real size (6700 in the example).

http://www.miniracingonline.com/images/noticias/4096.JPG

The game admits images up to 8192x4096, so the height is not a problem, but the circuits with a width of more than 4096 pixels are bad shown. All this is with the 1.06c version of unDelphiX, with the 1.07f version the problem is bigger, the problem then is thar a background of more than 4095 pixels the background is all black with some random parts of graphics all around. But with the 1.07f is about 40fps faster.

http://www.miniracingonline.com/images/noticias/Dibujo3.JPG

http://www.miniracingonline.com/images/noticias/Dibujo4.JPG

http://www.miniracingonline.com/images/noticias/Dibujo5.JPG



I have some other random problems that alters the security options in the game, like CRC of files and clock cycle control, and some other times changing to full screen causes an AccesViolation.

The positive part of using do3D is that the FPS raise and I can use Alpha without lowering fps too much, if you use Alpha without do3D the performance is very very low.

Any idea about how to solve these problems??

Thanks in advance.

arthurprs
13-12-2007, 12:20 PM
pictures don't showing here

kotai
13-12-2007, 12:29 PM
My web :x don't load images first time.

Rigth mouse button and show image to see.

I think I have solved random problems like CRC of files and clock cycle control solved with SetPrecisionMode(pmDouble);

Thanks in advance. :twisted:

ijcro
16-12-2007, 02:36 PM
Hi, there is any problem with picture size. Limit for texture was setup to 2048x2048 px. When is picture bigger (like 4096x4096) picture is shows but mesh recount isn't good. In version 1.07f this was corrected to limit up texture size, but no shown.

But this is not perfect still. Now I preparing version 1.08 and there will be new texture manager with mirroring etc.

Solution for this can be - use texture size max 2048x2048 px, transparent color use balck or alphachannel in DIB32.

ijcro
16-12-2007, 02:37 PM
.

kotai
17-12-2007, 12:19 AM
The textures are shown in the right way until 4096x4096, when they pass that size is the problem. I tried with textures higher than 2048 and work right.

The problem of the transparent color and the edges of the images happen in sprites or little images. I tried with a black background and other colors but are always bad cut. All images and sprites are loaded in run-time from bmp files of 256 colours.

I load the images in the next way:

DXImageList.Items.Find('Rev').Picture.LoadFromFile (ExtractFilePath(ParamStr(0)) + 'graficos\Revoluciones.bmp');
DXImageList.Items.Find('Rev').PatternHeight := DXImageList.Items.Find('Rev').Picture.Bitmap.Heigh t;
DXImageList.Items.Find('Rev').PatternWidth := DXImageList.Items.Find('Rev').Picture.Bitmap.Width ;
DXImageList.Items.Find('Rev').TransparentColor := DXImageList.Items.Find('Rev').Picture.Bitmap.Canva s.Pixels[0,DXImageList.Items.Find('Rev').PatternHeight-1];
DXImageList.Items.Find('Rev').Transparent := True;
DXImageList.Items.Find('Rev').Restore;

and show them on the screen like this:

DXDraw.BeginScene;
DXImageList.Items.Find('Rev').Draw(DXDraw.Surface, RevX,RevY,0);
DXDraw.EndScene;

but are bad cut:

http://www.miniracingonline.com/images/noticias/bordes.JPG

Is there any other way to make it work?

ijcro thanks in advance for new version 1.08

Kotai :P

ijcro
17-12-2007, 10:36 AM
Please send me pure picture for test. Thanks.

kotai
17-12-2007, 12:05 PM
You can download complete game in http://www.miniracingonline.com/descargar.php?Id=1 (13MB)

All images (bug it happens in every image and sprites) are in MiniRacingOnline/Graficos/ and all sprites are in MiniRacingOnline/Coches

This version is compiled with unDelphiX 1.06. You can change do3D options in MiniRacingOnline.ini, in section [Pantalla] add do3D=1 (default or not present is do3D=0)


[Pantalla]
doSelectDriver=1
doAllowReboot=1
do3D=0
doWaitVBlank=0
doAllowPalette256=0
doRetainedMode=0
doZBuffer=0


I upload EXE compiled with unDelphiX 1.07f : http://www.miniracingonline.com/descargas/exes/mro097c3.zip

Default circuit in game is Montmelo 6700x2400 pixels, when do3D=1 you can see the bug.
You can downlod a circuit minor than 4096 at http://www.miniracingonline.com/descargar.php?Id=GPHUNGRIA 3600 x 3800 pixels, in this case the bug in the background is not shown, but in sprites and images the bug still remains. You can download a circuit minor than 2048 at http://www.miniracingonline.com/descargar.php?Id=MINIIMOLA 1024 x 248 pixels in this casethe test limit texture was setup to 2048x2048 pixels

Thanks :roll:

ijcro
17-12-2007, 01:00 PM
Hello,

solution for this is very simply, mu must get out lines

DXImageList.Items.Find('Rev').PatternHeight := DXImageList.Items.Find('Rev').Picture.Bitmap.Heigh t;
DXImageList.Items.Find('Rev').PatternWidth := DXImageList.Items.Find('Rev').Picture.Bitmap.Width ;


Why?

Because image is not meshed, it contain one image only! When you set up the PatternHeight and the PatternWidth property, the texture will be proceed as meshed and subimages can be stretched like code remaping subtexture via subpatterns.

And for code clearing is better like this

procedure TForm1.FormCreate(Sender: TObject);
var
Q: TPictureCollectionItem;
begin
{be sure color table}
DXImageList.Items.MakeColorTable;
DXDraw.ColorTable := DXImageList.Items.ColorTable;
DXDraw.DefColorTable := DXImageList.Items.ColorTable;
DXDraw.UpdatePalette;
{switch for easy change mode}
HardwareSwitch := False; {initialize, start in software mode}
{when changed can be call FormKeyDown with 'space' parameter}
//*******************
Q := TPictureCollectionItem(DXImageList.Items.Add);
Q.Name := 'montmelo';
Q.Picture.LoadFromFile(ExtractFilePath(ParamStr(0) ) + 'montmelo.dib');
Q.Transparent := False;
Q := TPictureCollectionItem(DXImageList.Items.Add);
Q.Name := 'Rev';
Q.Picture.LoadFromFile(ExtractFilePath(ParamStr(0) ) + 'Revoluciones.bmp');
Q.TransparentColor := DXDraw.Surface.ColorMatch(Q.Picture.Bitmap.Canvas. Pixels[0,Q.PatternHeight-1]);
Q.Transparent := True;
DXImageList.Items.Restore;
//*****************
end;


Regards

kotai
17-12-2007, 05:55 PM
Hi

Deleting the lines to adjust the PatternHeight and PatternWidth doesn't solve the problem, it continues cuttin bad the edges.

In the image 'revoluciones.bmp' I can quit the pattern but in other images there are different patterns and I have to put the size of every pattern.

I will try tonight the ColorMatch, and I'll tell you how it goes.

Thanks

kotai
18-12-2007, 01:45 AM
Hi

I test colormatch and delete patternHeigh and PatternWidth but bug persist.

I send you (for email) source code of other game to test cuttin bad edges in sprites and images when do3D is activate.

Sprite have a green pixels arround to see diference between do3D and not do3D. Image "Revoluciones.bmp" of MiniRacingOnline are put to see borders cut at images.

In this game not load big textures to background, only for test cuttin edges.

Thanks.

ijcro
18-12-2007, 08:36 AM
Hello
I saw sent pictures. I think that this no problem of option doD3D but problem in picture. Green color of background is RGB=$00FF00 but some pixels around pictures have tone or nuance of green color (or the same color but in other palette entry - 8 bit palette). When I tried color change in PSP, all pixels was succesfully changed but contoures was in tone green still.

I think, that picture has missing the mask for alphachannel too.

kotai
18-12-2007, 09:33 AM
The green pixels of different color I have put meaningfully in order that you saw the difference better on having put do3D since the sprite is extended by 2 and the cut of the edges was not obvious very much.
In the folder "/personajes" you have the image without the green pixels, but it is difficult more of estimating the bad cuttin edges.

Also there is the image "Revoluciones.bmp" from MiniRacingOnline in the one that appreciates better the evil cuts away of the edges

Tries you with another sprite with more detail (or reduces the size of the current one to the half) to estimate better the bad cut of the edges.

Regards. :roll:

ijcro
18-12-2007, 11:13 AM
Eh, sorry.

I saw into images indiana and indiana.OK and there is palette difference.

Indiana contain 250 color entry and Indiana.OK contain 12 entry color only. It is primary problem.

When you convert (no resize, no jpeg!) indiana.OK to 256 color image to name indiana all will be OK.

kotai
18-12-2007, 12:32 PM
I save images (indiana.bmp and revoluciones.bmp) in 256 colors standar windows pallette and not solve bug :cry:

Some another solution?

Thanks.

ijcro
18-12-2007, 03:20 PM
Do you try image that I sent to your email?

I tried with them and image shows as well in your game... :wink:

kotai
18-12-2007, 04:42 PM
Yes I tried but bug continue:

http://www.miniracingonline.com/images/noticias/Dibujo.GIF

In sprite indiana.bmp not see clearly because it has little detail since it is extended x 2 (zoom x 2) but if you observe well you can see the differences in the contours.

Regards

ijcro
18-12-2007, 10:02 PM
Yes.
But now, for simple, you can try pure blitting disable option

{$Define DrawHWAcc}

in DelphiXcfg.inc and recompile all project with DelphiX source code.

After them will be used for Draw() functions DDS accelerates through Blt() function surface to surface - byte to byte.

Some enhacements as new functions but doesn't need works properly :(

Or

anything is break and SetColorKey no works well with intolerance color. :(

kotai
19-12-2007, 03:13 AM
Perfect.

Delete line {$Define DrawHWAcc} all graphis are ok and I can load circuits > 4096 pixels and and I can use Alpha without lowering fps too much.

Only one problem not solved deleting {$Define DrawHWAcc}: The first time that shows sprite on screen the game freezes a second when DXSpriteEngine.Draw is done (without do3D no freezes). I try to load all the sprites before entering to the circuit, but there is some as the cars ghost that cannot be created until an event happens and when it happens game freezes a second.

Some solution?

Thanks.

ijcro
20-12-2007, 10:09 PM
At first time when image has to showed, is processed some operations at background than do convert image to regular texture and it consume a few time depend by size etc. I vote simplest way for building textures at first use point. So, it can be simple too but interface of DelphiX is unchanged (really 95% old techniques manner is the same). Dummy operation for loading is unsupported and I no plan it in near future.

For enhancements in next version 1.08 I planning some new functions for drawing like mirroring/flipping, better works with static sprite via DXSpriteEngine.Items, better link to DXImageList and many new editors. Complete is editor for TBackgroundSprite for map creating and storing into Delphi form or to file very simplest. TImageSpriteEx is now deprecated, sorry. Editor for create font layout with masking to alpha channel is done and editor for image glue to one for direct support in sprites is done too. And added will be restructure tool for images (when sub images are in one line), color changes and etc. And now I make a new tool for drawing all in one line with predefined path (with effect like blurring, rotating, flipping, mirroring, waving and more), all stored in TDXDraw. And new effect editor for shine effect like supernova. And more, and more… But all will not be done in Christmas day, sorry, but in new year I plan new release…

Regards

kotai
31-12-2007, 12:30 PM
Hi again

Finally I managed to solve almost every problem removing the line {$Define DrawHWAcc}. The graphics show in the right way but some problems still remain:

*If I use undelphix 1.07 when it loads the images with alpha it stays stopped for a moment. I tried to load them all at the beginning, but everytime that in the menu of the game i change a Timage or Canvas (activating an option to change the graphic of the button) is like it looses the memory of the sprites with alpha loaded, and it stops again a time when I try to re-paint then again. The result is tha before entering the circuit I have to load all sprites and takes about 15 seconds doing it. If I use the version 1.06 it doesn't stop and I get the same performance than 1.07 version.

*The problem with the cutting edges was solved removing the line {$Define DrawHWAcc} but only in the images without alpha, in the images with alpha the problem remains and edges are bud cut.

*Double precission, activating do3D I had problems with some calculation beacuse of DirectDraw puts the precission mode in simple.I can solve it doing SetPrecisionMode(pmDouble) after the DirectDraw.Inicialize, but it doesn't work in all computers. I think is a problem with permissions, but I didn't try. The solution will be to indicate to the DirectDraw before initializing not to change to simple precission mode, it can be done putting the flag D3DCREATE_FPU_PRESERVE in the call Direct3D.CreateDevice, but I cannot find that call. Where do I indicate that flag??

As you told me, the limit in the textures is 2048 pixels (when do3d activated) but if I remove the {$Define DrawHWAcc} line then the limit is only for sprites with alpha and only for people with ATI VGA's. The cars in my game are 36x36 pixels and 60 positions that were together in a simple line, the textures were 2160x36. Without alpha it works perfectly, but activating alpha the people with NVIDIA VGA's as no problems, but with ATI the cars shows cut. I solved putting 2 lines of 30 cars : 1080x72 pixels.

I have the following problems:

* Cutting edged with sprites with Alpha.
* Add the flag D3DCREATE_FPU_PRESERVE in the call Direct3D.CreateDevice
* Stop of some seconds the first time I paint a sprite with alpha with undelphi 1.07 (With 1.06 works well).

Regards...

kotai
07-01-2008, 05:49 PM
Double precission problem solved: I put flag DDSCL_FPUPRESERVE in SetCooperativeLevel function

procedure TCustomDXDraw.SetCooperativeLevel;
var
Flags: Integer;
Control: TWinControl;
begin
Control := FForm;
if Control = nil then
Control := Self;
if doFullScreen in FNowOptions then
begin
Flags := DDSCL_FULLSCREEN or DDSCL_EXCLUSIVE or DDSCL_ALLOWMODEX or DDSCL_FPUPRESERVE;
if doNoWindowChange in FNowOptions then
Flags := Flags or DDSCL_NOWINDOWCHANGES;
if doAllowReboot in FNowOptions then
Flags := Flags or DDSCL_ALLOWREBOOT;
end else
Flags := DDSCL_NORMAL or DDSCL_FPUPRESERVE;
DDraw.DXResult := DDraw.IDraw.SetCooperativeLevel(Control.Handle, Flags);
end;
Now, only 2 problems:

* Cutting edged with sprites with Alpha.
* Stop of some seconds the first time I paint a sprite with alpha with undelphi 1.07 (With 1.06 works well).

Kotai.

ijcro
08-01-2008, 02:26 PM
I want say: Very good work! Thanks! :wink:


Double precission problem solved: I put flag DDSCL_FPUPRESERVE in SetCooperativeLevel function.

Please you can try before drawing this function for setting texture filter like:


DXDraw.TextureFilter(Ord(D2D_POINT)); //reset default settings from D2D_LINEAR
DXImageList.Items.Find('Rev').Draw(DXDraw.Surface, mX, mY, 0);

harrypitfall
20-01-2008, 05:28 AM
There is a strange loop hole inside dxdraws, but i found a way to fix this WITH hardware acceleration.

DXDraws.pas, line 1812, I add:

Var
DefaultTextureFilter: TD2DTextureFilter = D2D_POINT;

D2D_FLATCUBIC and D2D_GAUSSIANCUBIC get good results too, and D2D_LINEAR and D2D_ANISOTROPIC get that strange image cutting...

And after this, i change every stance of D2D_LINEAR to DefaultTextureFilter, you can enabled hardware acceleration again.

This way, you can swicth to optimal ways that you like, since there is no event to put the texturefilter correctly, (the loophole, every oninitiate have D2D object nullified... ack)

I also have my own dxsprite unit, with animation corrected and pixel check working perfectly too.

EDITED: Another good solution, is add a property onto tdxcustomdraw, "TextureFilter" of type TD2DTextureFilter. so, you can select it and will be use correctly inside creations...

ijcro
21-01-2008, 01:36 PM
when you use

DXDraw.TextureFilter(Ord(D2D_POINT));
before any command for drawing you can control texture filtering for texture different by source.
Default value is D2D_LINEAR in DXDraws unit. Property is not defined there for global change the texture filter.

I will change default value to D2D_POINT in next version 1.08. :)

Thank you

harrypitfall
21-01-2008, 04:25 PM
ijcro... is you that manages the undelphix ???

Will be very nice if you add this floating point fix, and the d2d_point texture filtering by default.
I also have my own spriteengine, with some extra sprites and more event driven (non design supported), and a DXMusic component that also can play mp3 files (and report when the music ends)

cronodragon
21-01-2008, 10:55 PM
What if you disable the transparent color mask, and use a format with alpha channel like .png?

Regards!
-Marco

kotai
05-03-2008, 01:25 AM
Perfect, I put D2D_POINT in DXDraws and work ok.

I used undelphix 1.06 and not 1.07 by stop of some seconds the first time I paint a sprite with alpha with undelphi 1.07 (With 1.06 works well).

I solved other problem, texture with alpha have limit 1024x1024 px for ATI. I have a NVIDIA and limit are 2048 x 2048 but people with ATI say me a problem and I solve it limit texture (with BlendMode := bmBlend) to 1024 x 1024.

Kotai.

ijcro
05-03-2008, 07:42 PM
OK, I will do some changes. New version is tested now.
I did large changes in DXSpriteEngine, I hope that it will be OK. And some default values has been changed too.

Limit of textures can be problem when image has size 4096 px in software mode. I solved it with new property editor for resructuralize of the sub-images (bigger image has to cuted or resized as force). Size is handled by constant named maxVideoBlockSize - it can be set down to 1024 px.

Any useable code is welcome for better (un)DelphiX, thank you!

Regards