SOLVED: DrawLine not working with Direct 3D

Started by Hernald, Mon 22/07/2013 02:06:19

Previous topic - Next topic

Hernald

The following code produces a short red line when the game is running in Direct Draw 5, but not with Direct 3D.
This is the case on two PCs. I've tried a few things, like using low number colours, drawing a triangle and copying and reloading the background
but without success. The room has two extra backgrounds, but I have specified the right one.
So any ideas?
Code: AGS

    DrawingSurface* redline = Room.GetDrawingSurfaceForBackground(0);
    DrawingSurface* backup = redline.CreateCopy();
    redline.DrawingColor=63488;               
    redline.DrawLine(cCD.x, cCD.y-4, oIceCube.X+3, oIceCube.Y-3, 1); 
    oIceCube.SetView(22);
    oIceCube.Animate(0, 20, eOnce, eBlock, eForwards);
    while (SoundFX.IsPlaying) Wait(1);
    redline.DrawSurface(backup);
    backup.Release();
    redline.Release();

Crimson Wizard

I made test, and found that with Direct3D the result is only drawn on screen after DrawingSurface is released.
EDIT: There's also a clue in manual:
Quote
Release (drawing surface)

Tells AGS that you have finished drawing onto this surface, and that AGS can now upload the changed image into video memory.
So it is rather Software renderer (DirectDraw5) that works formally incorrect ;).

In other words, you should try this:

Code: ags

    DrawingSurface* redline = Room.GetDrawingSurfaceForBackground(0);
    DrawingSurface* backup = redline.CreateCopy();
    redline.DrawingColor=63488;               
    redline.DrawLine(cCD.x, cCD.y-4, oIceCube.X+3, oIceCube.Y-3, 1); 
    redline.Release();
    <...>


Also, I must point out, that it is much simplier in this case to use Game.GetColorFromRGB function:
Code: ags

    redline.DrawingColor=Game.GetColorFromRGB(255,0,0);

Gilbert

Just a guess. Changes to a drawing surface are only guaranteed to be made when you Release() it. So, after drawing the line, you should release the surface, and when you revert it back to its backup, you need to get the surface again. So:
Code: AGS

    DrawingSurface* redline = Room.GetDrawingSurfaceForBackground(0);
    DrawingSurface* backup = redline.CreateCopy();
    redline.DrawingColor=63488;               
    redline.DrawLine(cCD.x, cCD.y-4, oIceCube.X+3, oIceCube.Y-3, 1); 
    redline.Release();  //Add this
    oIceCube.SetView(22);
    oIceCube.Animate(0, 20, eOnce, eBlock, eForwards);
    while (SoundFX.IsPlaying) Wait(1);
    redline = Room.GetDrawingSurfaceForBackground(0); //and this
    redline.DrawSurface(backup);
    backup.Release();
    redline.Release();


If you draw something on a drawing surface and do not release it and let the game's frames advance (like say, using Wait() ), you may get weird results as the stuff drawn may or may not be shown on it, yet. Possibly due to different implementation of the two display drivers you may get different results, so make sure you Release() the surface in the same frame once you have updated it, and if you want to draw more stuff in the next frame you need to get the surface and draw on it again. (Unless of course, the sprite aren't really shown on screen yet, in that case you don't need to Release() it in the same frame.)

Edit: Ninja'd by CW.

Hernald


SMF spam blocked by CleanTalk