DX8 Using .RES and CreateTextureFromResource
DX8 Using .RES and CreateTextureFromResource
DX8 Using .RES and CreateTextureFromResource
DX8 Using .RES and CreateTextureFromResource
DX8 Using .RES and CreateTextureFromResource
DX8 Using .RES and CreateTextureFromResource DX8 Using .RES and CreateTextureFromResource DX8 Using .RES and CreateTextureFromResource DX8 Using .RES and CreateTextureFromResource DX8 Using .RES and CreateTextureFromResource DX8 Using .RES and CreateTextureFromResource DX8 Using .RES and CreateTextureFromResource DX8 Using .RES and CreateTextureFromResource
DX8 Using .RES and CreateTextureFromResource DX8 Using .RES and CreateTextureFromResource
DX8 Using .RES and CreateTextureFromResource
Go Back  Xtreme Visual Basic Talk > > > > DX8 Using .RES and CreateTextureFromResource


Reply
 
Thread Tools Display Modes
  #1  
Old 09-10-2010, 11:56 AM
Mikekan13 Mikekan13 is offline
Newcomer
 
Join Date: Sep 2010
Posts: 6
Default DX8 Using .RES and CreateTextureFromResource


This is my first post.

I am trying to use a .RES file with a png file type to create a texture. How would I do this if for example my resource was Type:"PNG" Id: "TEST"

I have got this to work for bmp but not png yet. Here is the call for a bmp that works. Now how would I get it to work for a png since it is a custom resource?

Code:
Set Textures(TextureNum).D3DTexture = D3DX.CreateTextureFromResourceEx(Dev, App.hInstance, "TEST", D3DX_DEFAULT, _
D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, _
D3DX_FILTER_POINT, D3DX_FILTER_POINT, &HFF000000, ByVal 0, ByVal 0)

Last edited by Mikekan13; 09-10-2010 at 12:07 PM.
Reply With Quote
  #2  
Old 09-11-2010, 10:24 PM
surfR2911 surfR2911 is offline
Contributor
 
Join Date: Oct 2009
Posts: 719
Default DirectX and PNG

Is there any reason you need to use a resource file?
Is there any reason you need to use a png file?

When loading textures in DirectX (D3D) it is more common to use
CreateTextureFromFile function or the
CreateTextureFromFileEx function

Here is the DirectX4Vb tutorial page for using CreateTextureFromFile:
(it also mentions CreateTextureFromFileEx at the bottom of the page)
http://directx4vb.vbgamer.com/Direct...R_Lesson04.asp

Here is the tutorial for using CreateTextureFromFileEx with meshes
http://directx4vb.vbgamer.com/Direct...R_Lesson08.asp

Another "Using Textures in Direct3D" tutorial using CreateTextureFromFileEx
(which also mentions that the 11th parameter can be used as a color key if that's what you need)
http://www.gamedev.net/reference/art...rticle1606.asp

The official MSDN CreateTextureFromResourceEx page (for C++) says that the function supports .png for the D3DXIMAGE_FILEFORMAT parameter:
http://msdn.microsoft.com/en-us/libr...02(VS.85).aspx

However, there is no native support for png files in VB6.

You can use GDI+ to load/manipulate png graphics, or an third party control (not easy to get it into DirectX though), or use a third party library like FreeImage to load them into DirectX or if you are using D3D, into a DX hybrid engine.
Note: Loading an image to a DirectX surface is not that far apart from loading an image into a texture if you use techniques for accessing texture memory:
Quote:
Direct3D only allows us to copy between surfaces (Direct3DSurface8), not textures (Direct3DTexture8) - so the first step to copying between the textures is to convert them to a surface. Strictly speaking we're not going to convert them or copy them to surfaces, we're going to make a surface point at a specific level in the texture. These surfaces can then be used in copy operations, and the results will be directly mirrored onto the texture - which we can then render from. Using this method of referencing a texture through a surface can also be used to make a texture a render target (for special effects).
So, in short, even if you find code to extract png graphics (with alpha intact) as a custom resource out of a res file VB6 natively doesn't support them.

I don't know why you want to use the strange png-tucked-inside-a-res-file arrangement.
If it is to "protect" you graphics you might find this Directx4VB article interesting (...it's going to be some extra work):
http://directx4vb.vbgamer.com/Direct..._HideFiles.asp

If is because you are using png files for alpha (or opacity) gradients you might want to look at texture blending.

Last edited by surfR2911; 09-11-2010 at 10:47 PM.
Reply With Quote
  #3  
Old 09-11-2010, 11:09 PM
Mikekan13 Mikekan13 is offline
Newcomer
 
Join Date: Sep 2010
Posts: 6
Default

I want to use the resources because it keeps the project neat and clean. You don't have to have a million images in a folder. I am aware that visual basic does not recognize a png but directx8 does and you can easily use the CreateTextureFromFile and pass it a png and it works just fine. So If I store a png as a custom resource why cant I pass that to directx. I just dont know how to point to it. So I just need to know how to tell the createtexturefromresource where the custom resource is.
Reply With Quote
  #4  
Old 09-12-2010, 02:16 PM
OnErr0r's Avatar
OnErr0rDX8 Using .RES and CreateTextureFromResource OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,771
Default

You'll need the PNG resource as a CUSTOM type with the resource editor addin in order for the API to find it.
__________________
Quis custodiet ipsos custodues.
Reply With Quote
  #5  
Old 09-12-2010, 02:50 PM
Mikekan13 Mikekan13 is offline
Newcomer
 
Join Date: Sep 2010
Posts: 6
Default

I have tried it as CUSTOM and it still does not work
Reply With Quote
  #6  
Old 09-12-2010, 04:58 PM
OnErr0r's Avatar
OnErr0rDX8 Using .RES and CreateTextureFromResource OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,771
Default

Just to clarify, you should be clicking the "Add Custom Resource" button. This creates the correct kind of resource for the API. If that doesn't work for you, then you have one or more parameters incorrect.

Btw, App.hInstance doesn't provide the information the API needs in the IDE. Any testing you do will need to be performed in a compiled EXE.
__________________
Quis custodiet ipsos custodues.
Reply With Quote
  #7  
Old 09-12-2010, 10:10 PM
Mikekan13 Mikekan13 is offline
Newcomer
 
Join Date: Sep 2010
Posts: 6
Default

Quote:
Originally Posted by OnErr0r View Post
Just to clarify, you should be clicking the "Add Custom Resource" button. This creates the correct kind of resource for the API. If that doesn't work for you, then you have one or more parameters incorrect.

Btw, App.hInstance doesn't provide the information the API needs in the IDE. Any testing you do will need to be performed in a compiled EXE.
I am clicking add custom resource, the parameters are fine because it works for a bmp and I know I must compile to test. So is it safe to assume this is just impossible then?
Reply With Quote
  #8  
Old 09-13-2010, 08:09 AM
OnErr0r's Avatar
OnErr0rDX8 Using .RES and CreateTextureFromResource OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,771
Default

I've seen people mention using an integer resource ID rather than string. Let the res editor chose a number and leave it unedited. Then use "#101" (substituting your ID for 101) in the function call. This is what the MAKEINTRESOURCE macro returns.

If that still doesn't work you may have to switch to LoadResData(101, "CUSTOM") and CreateTextureFromMemory
__________________
Quis custodiet ipsos custodues.
Reply With Quote
  #9  
Old 09-13-2010, 03:46 PM
Mikekan13 Mikekan13 is offline
Newcomer
 
Join Date: Sep 2010
Posts: 6
Default

Ya I tried the #101 method. Would it be faster to do the load from memory method or to have all my resources in a custom file type that I open as temporary and then create the texture from file.
Reply With Quote
Reply

Tags
createtexturefromresource, d3d, directx, res, resources


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
DX8 Using .RES and CreateTextureFromResource
DX8 Using .RES and CreateTextureFromResource
DX8 Using .RES and CreateTextureFromResource DX8 Using .RES and CreateTextureFromResource
DX8 Using .RES and CreateTextureFromResource
DX8 Using .RES and CreateTextureFromResource
DX8 Using .RES and CreateTextureFromResource DX8 Using .RES and CreateTextureFromResource DX8 Using .RES and CreateTextureFromResource DX8 Using .RES and CreateTextureFromResource DX8 Using .RES and CreateTextureFromResource DX8 Using .RES and CreateTextureFromResource DX8 Using .RES and CreateTextureFromResource
DX8 Using .RES and CreateTextureFromResource
DX8 Using .RES and CreateTextureFromResource
 
DX8 Using .RES and CreateTextureFromResource
DX8 Using .RES and CreateTextureFromResource
 
-->