Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / DirectX equivalent of dbPasteImage?

Author
Message
Robert The Robot
17
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 22nd Sep 2011 18:20
I've been trying to port some DBP code over to C++ for a plugin (keep reading ), and I thought I'd take the plunge and try some DirectX programming.

I'm trying to find a fast way of pasting an image on screen, using the DirectX libraries (can't use GDK unfortunately as I want a plugin for DBPro).



This code works but:
1) a 50x50 pixel image is pasted as 64x64 - a suspicious "power of two". How do I paste it at actual size, and not stretched up to a texture size?

2) The code runs slower than DBP's own PasteImage command. I thought the whole point of C++ was that it would be faster than DBP itself - so what have I done wrong?

3) most importantly - most of this code came from SvenB's image kit plugin. I don't really know what the render state settings/flags actually mean. Help??

We spend our lives chasing dreams. Dark Basic lets us catch some of them.
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 22nd Sep 2011 21:12
Doing all those state changes every loop will definitely slow you down. You should only do those once. The default for DX is power of 2. I'm not sure how to get arround that, but I would use sprites instead of pasting images. Sprites can be done in bulk and will be much faster than images.

--Do all your state changes outside of the render loop unless it is absolutely necessary.
--Clear the background.
--Render all your 3D (or background) objects.
--Put all your sprites in (there's a kindof "buffer" for them)>
--Render.

The fastest code is the code never written.
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 22nd Sep 2011 21:27 Edited at: 22nd Sep 2011 21:29
1) i think the coordinates system is -1,1 at topleft and 1,-1 at bottomright, try to use this for coords
2) Hmm, i don't know how GDK pastes images, but if you wan't better performance, you can drop colour element in the structure, and change the FVF accordingly also, since you will use a texture, this could slightly improve it, might not even be a noticeable change, i haven't used dx9 for long so i can't give any more advice
3) basically, you're telling Direct3D how to render your stuff via DrawPrimitive/etc.. methods, for example:


there, you set the FILLMODE to SOLID - this will make it render your stuff flat, you could make it render wireframe via this flag, then you set DITHERENABLE to false, dunno what's that really, first time i see it, then you disable lighting, this is for better performance, then you disable culling, so back-facing triangles will still get rendered, disable fog, disable some z-buffer stuff, that's all, as the name says "render state", its how the device should render

oh also - you could use the ID3DXSprite9, i believe the plugin used this method in order to allow usage of pixel shaders for special effects, and as Hawkblood said, try to eliminate useless state changes

Matty H
16
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 22nd Sep 2011 21:42
Quote: "I'm trying to find a fast way of pasting an image on screen, using the DirectX libraries (can't use GDK unfortunately as I want a plugin for DBPro)."


Are you aware that you can use dbPro commands in your plugin?

You probably are, but that quote makes me think you may not be

Robert The Robot
17
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 23rd Sep 2011 12:15 Edited at: 23rd Sep 2011 12:16
Thanks guys, you've given me a lot of food for thought.

Quote: "Are you aware that you can use dbPro commands in your plugin?"

Yes, but my plugin is a GUI system that works by rendering images on screen in a manner that mimics Windows behaviour. I found that in DBP, "Paste Sprite" ran faster than "Paste image" but that meant tying up image and Sprite resources and including a whole extra library in the compiled exe - I figured there had to be a way of making my plugin more standalone. I was also curious!

Quote: "oh also - you could use the ID3DXSprite9"

I did try something like this:



but I was quite surprised to find it ran slower than the paste image method I outlined above. Are there DirectX states I need to set to improve the sprite drawing? It also drew the 50x50 image at 64x64 as well.

Quote: "Doing all those state changes every loop will definitely slow you down. You should only do those once."

I'm wondering, actually - could I get away with not doing them at all? You see, I just want to slip these drawing commands in on top of whatever DBP is showing. In GDK, it would be kind of like this:



except that I replace dbPasteImage with custom code that means my library can be standalone.

We spend our lives chasing dreams. Dark Basic lets us catch some of them.
Brendy boy
19
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 23rd Sep 2011 15:25
why don't you look at dbpro source code to see the directx code behind the PASTE IMAGE command

Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 23rd Sep 2011 16:11

This will cause only one sprite to be drawn at a time. If you begin the sprite and then draw ALL your sprites, then end, it will be faster (batch).

The fastest code is the code never written.
Robert The Robot
17
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 24th Sep 2011 12:24
wh
Quote: "y don't you look at dbpro source code to see the directx code behind the PASTE IMAGE command"

My first thought was "you can get the DBP source code?????", then I found the TGC newsletter article about it .

I've traced the code, and ironically DBP sprites aren't drawn using DirectX sprites. It's actually done using a (much, much faster) version of the "Paste image" I posted earlier! I want to play about with it a little more, check I'm doing things right, but I think it's going to work brilliantly!

We spend our lives chasing dreams. Dark Basic lets us catch some of them.
TechLord
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 24th Sep 2011 18:00 Edited at: 24th Sep 2011 18:36
Its all about Render Targets. The Enhanced_DGDK Image class for DGDK Open Source Project (formerly Project-Trio, currently Super 3D Game Platform).



Enhanced_DGDK Image.h


Enhanced_DGDK Image.cpp


Robert The Robot
17
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 25th Sep 2011 12:42 Edited at: 25th Sep 2011 12:43
Ok, this appears to be the function I've been after - courtesy of a slight mod of the DBP sprite render code. I've disabled diffuse colours in the rendering, but left in the D3DFVF_DIFFUSE in the FVF value as this appears to be slightly faster.

I hadn't realised how interesting DBP sprites were - "Paste Sprite" just copies the single sprite to screen at once, while "Sprite" called outside the program loop sets up all images to be rendered in one go. This code, with my own image management, seems to run marginally faster than sprites themselves - still haven't figured out why.




Just one final question - every time I render a batch of images, I call this at the start:
LPDIRECT3DDEVICE9 m_pD3D = dbGetD3DDevice();
m_pD3D->SetRenderTarget(0, g_pGlob->pCurrentBitmapSurface);
Do I really have to do either of these? Once a program is running, is there any way the D3D device pointer could change? And isn't setting the render Target to be whatever DBPro has set as the current surface just like setting soemthing that is already set?

@TechLord
Thanks for the code, I'll be a while sifting through it but there's definitely some useful stuff in there for me!

We spend our lives chasing dreams. Dark Basic lets us catch some of them.
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 25th Sep 2011 16:37
You have to set the render target, but you should have a global pointer to the device that you would only call once in your program.

The fastest code is the code never written.
Robert The Robot
17
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 4th Oct 2011 22:05
Ok, sorry to dredge this up again but I'm again faced with a choice of methods for drawing 2D images. I want to put maybe 1000 on screen per frame, and as before, keep it as fast as possible!

Currently I do this (it's a mix of C++ and pseudo-code):


Now for some possible alternatives:


or



or even (and I haven't got a clue about this one yet!)



So, four possible choices. I'm trying to set them up and run tests, but as I've said I don't know that much about DirectX and I'm fumbling my way. I was wondering, which would you pick and why? And which are definite non-starters (so I don't waste time studying them!)?

We spend our lives chasing dreams. Dark Basic lets us catch some of them.
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 5th Oct 2011 04:18
Your third option is the best you can hope for. I wouldn't use 3D objects to do what you are wanting, I'd use sprites in a batch.

The fastest code is the code never written.

Login to post a reply

Server time is: 2024-11-19 07:23:53
Your offset time is: 2024-11-19 07:23:53