draw sprite doesn't work when inside VS (executable works fine)

This may be a known issue, but I haven't been able to find it
anywhere... and I'm a good googler =o)...

I have this code (directly taken from Microsoft) to draw a simple
sprite:

public Device device=null;
public Microsoft.DirectX.Direct3D.Sprite sprite=null;
public Texture tex=null;

public void InitGraphics()
{
PresentParameters p=new PresentParameters();
p.SwapEffect=SwapEffect.Discard;
p.Windowed=true;
device=new Device(0, DeviceType.Hardware, this,
CreateFlags.SoftwareVertexProcessing, p);
sprite=new Sprite(device);
tex=TextureLoader.FromFile(device, "F:\\eber\\charmed2.bmp");

}

public void doRender()
{
device.Clear(ClearFlags.Target, Color.White, 1.0f, 0);
device.BeginScene();
sprite.Begin(SpriteFlags.None);
sprite.Draw2D(tex, Rectangle.Empty, Rectangle.Empty, new
Point(10, 10), Color.Blue);
sprite.End();
device.EndScene();
device.Present();

}

static void Main()
{
Form1 frm = new Form1();
frm.InitGraphics();
frm.Show();
while (frm.Created)
{
frm.doRender();
Application.DoEvents();

}
}

it's all good... except, when running from Visual Studio, the sprite
doesn't show anywhere... if I run the generated executable, it shows up
fine...

what am I missing

I even tried this in a different IDE(Delphi 2005) with the exact same
results 

I'm using
- Windows 2000 SP 4
- Visual Studio 2003
- DirectX 9.0c
- December 2004 update (managed)

thanks in advance



Answer this question

draw sprite doesn't work when inside VS (executable works fine)

  • frapgn

    I can repro on my machine using the August 2005 DX SDK and the Beta 2 version of VS 2005.  Sooo...we're going to call this one a "bug".  Change from Sprite.Draw2D to Sprite.Draw.  That should work around the problem (it did for me at least).

  • kiln

    I believe that it is an imperfection of the Visual Studio, therefore nor everything it I execute in time drawing time

    []'s

  • bbroyles

    The December 2004 SDK release was 4 releases ago.  Would you upgrade to the June 2005 SDK and let us know if you still have the same problem

    P.S. -- You might also want to look at how the newer samples are written.  We no longer recommend using the Application.DoEvents-style of rendering.



  • John Gallardo - MSFT

    Have you tried this with the August 2005 SDK that was just released   There was an error in the Draw2D method that was just recently fixed.



  • Tom Waters

    P.S. -- You might also want to look at how the newer samples are written.  We no longer recommend using the Application.DoEvents-style of rendering.

    I'm very concerned about the PS there. I've been looking through the examples (specifically "EmptyProject" for this new way of doing things, which appears to be to be setting the OnIdle event.

    That's not so bad, even if it lacks a simple return value to tell the system to call the event until told otherwise like Borland Delphi has done since forever, but the amount of code in the SDK sample utilities files... talk about code obsfucation!

    Shouldn't Microsoft's aim be to make coding easier for programmers The tutorial that uses Application.DoEvents() (which is still in the June 2005 SDK mind you) was extremely easy to understand and use, and while it lacks all the frills and protections offered by the sdk's common utilities, it doesn't scare the pants off beginners.
     
    So then, why are you trying to make life hard for people I'm no beginner, but when I see the mess that is the SDK samples and think that is what you want beginners to think programming directx involves just get a simple window up, it gives me a headache. I've never used MFC for this same reason. I can code assembler with less headahces.

    Programming is simple, lets try and keep it that way.

  • Sergey M

    Using the August 2005 SDK, I was not able to repro the VS/exe differential.  However, I could not get that particular overload of Draw2D() to work at all, due to a compiler optimization bug (we think). 

    Try adding .ToArgb() to the end of that Draw2D call:
    sprite.Draw2D(tex, Rectangle.Empty, Rectangle.Empty, new Point(10, 10), Color.Blue.ToArgb());
    which will take you to a different overload that should work.

    We are continuing to look into this issue (including the VS/exe differential).

    edit:  there are a few other issues on this thread, such as undesired behavior from Draw2D generally (regarding placement from rotation); those are separate from the original issue.

  • blobz

    Thanks for the suggestion mattpic, I should have thought of trying another overload, but guess what: Now the sprite is drawn when launching from VS, but not when starting my executable manually @_@

    Just as my application starts I get a short glimpse of the offending sprite, seems like the first call to draw2D works while all subsequent ones fail.

    Hope you guys fix this in the next version of the SDK.

  • Prasad Khandekar

    Now it works for me like BlackTiger described it: the calls to Draw2D fail to render anything when inside VS, but starting the executable manually draws all sprites correctly.

    I don't have any more problems with it though; calling Draw2D DOES set the Transform on my Sprite object to what I want, and I can just draw the sprite using first Draw2D then Draw to make sure it's rendered in- and outside VS.

  • mbordoni

    same thing with the June 2005 SDK Tongue Tied
  • Shorin

    sure, I'll give it a try, I posted this problem awhile back on google groups (when that was the latest update) and never got an answer, was wondering if I would get an answer now

    I'll test with the latest SDK and report back
    thanks

  • birch9397

    will try and let you know my results
    ...at least it wasn't anything I was doing... or not doing

  • Kailash-Bisht

    I have yet to get Sprite.Draw2D to work properly myself. In my case, starting the project executable manually produces the same result: the sprite silently fails to render. I dicovered the problem last week, and yesterday I did a format and reinstall of WinXP, VS 2K3 and the June DirectX SDK, the problem is still there.

    This problem only occurs when using one of the oveloads of Draw2D that take a destination rectangle as an argument, the overload below renders the sprite(though not in the way I want it)


    Sprite.Draw2D(Texture srcTexture, Point rotationCenter, float rotationAngle, Point position, Color color)
     


    I'm currently using Sprite.Draw as a temporary placeholder, but i want some of my sprites to resize to fill the screen and for that it's easiest to use Draw2D which can take a destination rectangle.

    Has anyone succeded in drawing a sprite using one of the Draw2D overloads that take a destination rectangle If so, please post how you did it!


    As a side note, there is an error in the documentation for "How do I... " -> "Draw A Sprite".
    In the example code a System.Drawing.Point is declared with


    new Point(5.0f, 5.0f)
     
     

    and that's no good Big Smile


  • draw sprite doesn't work when inside VS (executable works fine)