Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Perspective transformation using Managed DirectX?

Posted on 2004-08-07
Last Modified: 2013-12-08
Hi there,

I'm fairly irrelevant to game graphics, but I do have a question that perfectly fits here. I want a function that given an Image and a trapezoid defined by a four points array (or similar), will transform the original image to fit the destination quadrilateral. Actually, gdiplus has something close to what I want, DrawImage, but the destination there is a parallelogram defined by three points (the fourth is computed from the other three). Btw, I'm a VB.NET developer (...), but C# code should be fine too.

Any help?
Thanks in advance
Question by:orbyone
  • 4
  • 3
LVL 17

Expert Comment

ID: 11747727
DirectX would make you jump through a LOT of hoops to get the result.  You're trying to do a standard quad-based image warp I assume?  There are samples (and likely even examples here on EE) out on the net that I've seen before.

If you REALLY want to go through DirectX, the ROUGH steps you'd need to do are:

- set up a direct3D context (there are some good sample with the DX SDK that start you off with basic rendering)
- load the Image into a D3D Texture object (the D3DX helper functions may help here)
- set up the viewport/camera transformation (in this case, it'll be a display-space camera)
- start rendering
- set the texture as active, and other rendering state
- render a triangle strip or fan with the four vertices in question
- finish rendering
- read pixels out of the backbuffer.

Fun, eh? ;)  As I said, lots of samples with DX SDK that should even start you off with a textured quad and all the proper setup, you just load your image, and need to read from the backbuffer the result.


Author Comment

ID: 11760368

thanks. I was a bit afraid it was going to be that complex. could someone help me find the right sample in the net for "standard quad-based image warp"? points will be rewarded for that.

LVL 17

Expert Comment

ID: 11768811
open source lib:

image displacement fns:

this guy's master thesis was on quad image warping, has sample code later on page:

this is different type of approach & effect, but might have useful tidbits:

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Author Comment

ID: 11770012
hi d,

I really appreciate your effort, it's still though not 100% what I'm looking for. I'm really looking for VB/C# source code, C/C++ is just chinese for me... If you do find a sample in VB/VB.NET or C#, it would be greatly appreciated

LVL 17

Expert Comment

ID: 11779317
the codeproject.com link WAS C#...

and from http://portal.vbcodesource.com/portal/modules/news/ :
"Finally, Visual Basic 2005 BETA1 is available for download for Non-MSDN subscribers!! I have been playing around with it for alittle while today and I really think I will like it. The .Net Framework 2.0 looks to have even more powerful features available. I was looking through the GDI+ classes and looks like there are some pretty nice change/additions. Looks like warping will be easy to do."

Sounds like from the C# example, and the above note, GDI+ stuff has the capabilities you want.  The codeproject C# sample should get you started for sure.



Author Comment

ID: 11805235

the C# project was indeed very interesting, but had no sample related to perspective transformation. The new .NET framework sounds promising, but after browsing the docs I could not find the appropriate function (e.g. new overloaded DrawImage function) that performs warping. If you can find this for me, I'll be more than happy to give you the points.

LVL 17

Accepted Solution

davebytes earned 500 total points
ID: 11824739
Yeah, I agree... After my more intense digging, it is only basic rotate/translate/scale.

I haven't found anything specifically C#/VB, unfortunately.  However, if you want to do a little bit of stretching (a lot of this is C, but I'd think you're likely able to handle the basic read-through...), I tried to find some old articles on projective texture mapping.  Some of them were way too complex, but gamedev.net has a lot (http://www.gamedev.net/reference/list.asp?categoryid=40#112) of potential articles.  Much of these are OLD (at least five years, some more, some less), since these are 'by hand' rendering approaches -- outdated in most cases by hardware rendering.

The ones I picked out for you were:

http://www.gamedev.net/reference/articles/article1083.asp (and the follow up article listed at the end)
http://www.gamedev.net/reference/articles/article335.asp (starts going into x86 ASM, but gave some good intro and pseudo-code)

Hope that helps.  If I find a decent primer to Direct X in VB/C#, will let you know.  You might want to go pick up a book if you want to go that route, as there's likely some good ones out there...


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question