Use the wtl file dialog box to open the image and d3d rendering.

Source: Internet
Author: User

Demo download: http://download.csdn.net/detail/jiangcaiyang123/4061511

Procedure: Enter the Enter key: open the file, and press the up or down key to move the picture above.
The program is not satisfactory. I am only trying to elaborate on a technical point. Sorry.
Who said that wtl has little effect? Before I knew about the open-source interface library, using wtl became my only choice. Another reason is that I have never learned MFC. Generally, it is enough for us to select a file to load on the standard interface. If you have rich idea, you can use DirectX to implement the file dialog box. Of course, if you are a dxut programmer with at least half a year of experience, you can ask for help. I saw a customui program example written by dxut. I really want to know how it is implemented. It is a pity that the dxut framework has been adopted. It takes some effort to learn this framework.
Now, let's get down to the truth. One of the features of this example program is the combination of wtl/ATL and DirectX. Use a ready-made wtl file dialog box to select an image file. The image file format can be jpg or PNG. Of course, other images can also be used, as long as the image file is legal and not too large. Then, d3d is used to load the image to form a texture. Rendering textures use the simplest filtering method, so the image may seem a bit jagged.
The person who downloaded the demo program will find that the program can run independently and display two images. So how is this done? My approach is to embed two images into a resource program. vs allows us to do this. Then we must load images from resources. DirectX also allows us to do this, but there are some restrictions. I tried a lot of methods a few years ago, but they all failed. Until one time, I found the loading method in a post in gameres. Now let's take my demo program as an example to illustrate the loading steps. (My version is vs2005. Theoretically, all other versions should be valid .)

This is what I developed:

Click "add> resource", as shown in.

Select "import", as shown in.

Select All files. Click the. PNG file you want to download and click open. As shown in.

In the Custom Resource Type dialog box, enter rc_data and click OK. As shown in.

Now the image file we load has become a series of binary texts. As shown in.

Compile the. RC file, and the load code is not written.

When loading, use the d3dxcreatetexturefromresourceex () function. Of course, you can also use its simple version d3dxcreatetexturefromresourceex. The following describes how to use the function:

HR = d3dxcreatetexturefromresourceex (// create texture m_pdevice from resource, // direct3ddevice9 structure pointer null, // module handle makeintresource (idr_rcdata1), // name of the loaded image resource d3dx_default, // d3dx_default, // high d3dx_from_file, // MIP level 0, // usage d3dfmt_a8r8g8b8, // format d3dpool_managed, // memory pool format d3dx_default, // filter d3dx_default, // MIP filter 0, // key color (used as mask) & imageinfo, // source file information null, // color palette & m_ptexbackground );

Makeintresource is a macro used to specify the position in the program for loading image data. Idr_rcdata1 is included in resource. h and must be included using the # include statement.
After everything is ready, we can see that our program runs independently without any image files.

Pay attention to using wtl because I am not creating a wtl application, so we must manually process some header files. Atlbase. H, atlapp. H, and atldlgs. h must be included. The cfiledialog method is similar to that in MFC. The browseimagefile () function looks like this:

Void crenderbyfiledialog: browseimagefile (void) // browse and obtain the path of the image file {cfiledialog imagefiledlg (true, text (". jpg "), m_curimagefile.c_str (), ofn_hidereadonly | ofn_overwriteprompt, text (" JPG/JPEG file \ 0 *. JPG \ 0png file \ 0 *. PNG \ 0 all files \ 0 *. * "), null); If (idok = imagefiledlg. domodal () {m_curimagefile = imagefiledlg. m_szfilename ;}}

If you have not installed wtl, use the document I have previously written. Here is a detailed description of how to install wtl.

The following is the program:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.