How to preview DDS files
如何预览DDS文件,帮帮忙,谢谢
How to preview DDS files [Help me]
How to preview DDS files [Help me]
I came to the ancient oriental country - China
I will PureBasic called B++
I will PureBasic called B++
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: How to preview DDS files [Help me]
Do you mean code-up a viewer in PB? I don't know how to do that, but you can use Photoshop or The Gimp to view them, with DDS plugins.
http://www.gimp.org/
http://code.google.com/p/gimp-dds/
http://developer.nvidia.com/object/dds_ ... egacy.html
http://www.gimp.org/
http://code.google.com/p/gimp-dds/
http://developer.nvidia.com/object/dds_ ... egacy.html
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: How to preview DDS files [Help me]
There's also a small shareware program called MysticThumbs that adds dds (and many other) thumbnail previews to Windows explorer.
Re: How to preview DDS files [Help me]
Thank you
I have already solved the problem
This is my code
I have already solved the problem
This is my code
Code: Select all
;==================================
;[文件名称]: DDS加载实例3.pb
;[文件版本]: 0,0,0,3
;[函数前辍]: MPDX__
;[补充说明]: 运行DX插件加载显示DDS等图片,支持的文件格式: BMP, JPG, TGA, PNG, DDS, PPM, DIB, HDR 和 PFM
;[开发语言]: PureBasic4.20
;[测试平台]: WinXP(SP3)
;[开 发 者]: 迷路仟[QQ:714095563]
;[修订时间]: 2011.03.18
;==================================
;-
;- 自定义结构 ------------
Structure D3DDISPLAYMODE
Width.l
Height.l
RefreshRate.l
Format.l
EndStructure
Structure D3DXIMAGE_INFO
Width.l
Height.l
Depth.l
MipLevels.l
Format.l
ResourceType.l
ImageFileFormat.l;
EndStructure
Structure D3DPRESENT_PARAMETERS
BackBufferWidth.l
BackBufferHeight.l
BackBufferFormat.l
BackBufferCount.l
MultiSampleType.l
MultiSampleQuality.l
SwapEffect.l
hDeviceWindow.l
Windowed.l
EnableAutoDepthStencil.l
AutoDepthStencilFormat.l
flags.l
FullScreen_RefreshRateInHz.l
PresentationInterval.l
EndStructure
Structure D3DXMACRO
Name.s
Definition.s
EndStructure
Structure D3DImage_INFO
ImageID.l
Handle.l
Info. D3DXIMAGE_INFO
Texture.IDIRECT3DTEXTURE9
Buffer. IDIRECT3DVERTEXBUFFER9
FunUseD3D.IDIRECT3D9
FunDevice.IDIRECT3DDEVICE9
CurMODE. D3DDISPLAYMODE
EndStructure
;-
;- 接口函数 --------------
Import "d3d9.lib"
Direct3DCreate9(SDKVersion.l)
EndImport
Import "d3dx9.lib"
D3DXGetImageInfoFromFileA.l(pSrcFile.s, *pSrcInfo.D3DXIMAGE_INFO)
D3DXCreateTextureFromFileA(*pDevice.IDIRECT3DDEVICE9, pSrcFile.s, *ppTexture.IDIRECT3DTEXTURE9)
D3DXCreateTexture(*pDevice.IDIRECT3DDEVICE9, Width.l, Height.l, MipLevels.l, Usage.l, *Format.l, *Pool.l, *ppTexture.IDIRECT3DTEXTURE9)
EndImport
;-
;- 基本函数 --------------
; 加载DX插件
Procedure MPDX_OpenD3D9Device()
Global NewList _ListImage.D3DImage_INFO()
Global _CurImageID.l
AddElement(_ListImage())
_ListImage()\ImageID = -1
EndProcedure
; 卸载DX插件
Procedure MPDX_ClosetD3D9Device()
ForEach _ListImage()
If _ListImage()\FunDevice <> #Null : _ListImage()\FunDevice\Release() : _ListImage()\FunDevice = #Null : EndIf
If _ListImage()\FunUseD3D <> #Null : _ListImage()\FunUseD3D\Release() : _ListImage()\FunUseD3D = #Null : EndIf
Next
EndProcedure
; 加载图片
Procedure MPDX_LoadImage(ImageID, FileName$)
If _ListImage()\ImageID <> ImageID
ForEach _ListImage()
If _ListImage()\ImageID = ImageID : IsBeing = #True : Break : EndIf
Next
If IsBeing = #False
AddElement(_ListImage())
_ListImage()\ImageID = ImageID
_ListImage()\Handle = GadgetID(ImageID)
EndIf
EndIf
_ListImage()\FunUseD3D = Direct3DCreate9($20);创建D3D对象
If _ListImage()\FunUseD3D = #Null : ProcedureReturn #False : EndIf
Result = _ListImage()\FunUseD3D\GetAdapterDisplayMode(0,_ListImage()\CurMODE) ; 获取当前的显示模式
If Result : ProcedureReturn #False : EndIf
Result = _ListImage()\FunUseD3D\CheckDeviceType(0,1,_ListImage()\CurMODE\Format,_ListImage()\CurMODE\Format,#True) ;检查是否有匹配的显卡驱动支持该DisplayFormat和BackBufferFormat着色模式。
If Result : ProcedureReturn #False : EndIf
Rendering.D3DPRESENT_PARAMETERS
Rendering\SwapEffect = 1
Rendering\hDeviceWindow = _ListImage()\Handle
Rendering\BackBufferFormat = _ListImage()\CurMODE\Format
Rendering\EnableAutoDepthStencil = 1
Rendering\AutoDepthStencilFormat = $50
Rendering\Windowed = 1
_ListImage()\FunUseD3D\CreateDevice(0,1,hwnd,$40,Rendering,@_ListImage()\FunDevice) ;创建一个驱动、设置驱动器、驱动类型、和一些设置
D3DXGetImageInfoFromFileA (FileName$, @_ListImage()\Info)
D3DXCreateTextureFromFileA(_ListImage()\FunDevice, FileName$, @_ListImage()\Texture)
Buffer = _ListImage()\FunDevice\CreateVertexBuffer($50, 0, $102, 0, @_ListImage()\Buffer, #Null)
If Buffer = #True : End : EndIf
If _ListImage()\Buffer\Lock(0, $50, @Vertices.l, 0) = #True : End : EndIf
CopyMemory_(Vertices, ?VerticeData, $50)
_ListImage()\Buffer\Unlock()
_ListImage()\FunDevice\SetRenderState($89, #False)
EndProcedure
; 绘制图片
Procedure MPDX_DrawImage(ImageID)
If _ListImage()\ImageID <> ImageID
ForEach _ListImage()
If _ListImage()\ImageID = ImageID : IsBeing = #True : Break : EndIf
Next
If IsBeing = #False : ProcedureReturn #False : EndIf
EndIf
With _ListImage()\FunDevice
\Clear(0,0,3,0,1,0)
\BeginScene()
\SetSamplerState(1,6,2)
\SetSamplerState(1,5,2)
\SetTextureStageState(1,11,0)
\SetTextureStageState(1,1,4)
\SetTexture(1,_ListImage()\Texture)
\SetStreamSource(0, _ListImage()\Buffer,0,20)
\SetFVF($102)
\DrawPrimitive(5, 0, 2)
\EndScene()
\Present(0,0,0,0)
EndWith
EndProcedure
; 获取图片的宽度
Procedure MPDX_ImageWidth(ImageID)
If _ListImage()\ImageID = ImageID
ProcedureReturn _ListImage()\Info\Width
Else
ForEach _ListImage()
If _ListImage()\ImageID = ImageID
ProcedureReturn _ListImage()\Info\Width
EndIf
Next
_ListImage()\ImageID = ImageID
EndIf
EndProcedure
; 获取图片的高度
Procedure MPDX_ImageHeight(ImageID)
If _ListImage()\ImageID = ImageID
ProcedureReturn _ListImage()\Info\Width
Else
ForEach _ListImage()
If _ListImage()\ImageID = ImageID
ProcedureReturn _ListImage()\Info\Height
EndIf
Next
_ListImage()\ImageID = ImageID
EndIf
EndProcedure
; 获取图片的格型 返回值: 0=BMP,1=JPG,2=TGA,3=PNG,4=DDS,5=PPM,6=DIB,7=HDR,8=PFM
Procedure MPDX_ImageFormat(ImageID)
If _ListImage()\ImageID = ImageID
ProcedureReturn _ListImage()\Info\Width
Else
ForEach _ListImage()
If _ListImage()\ImageID = ImageID
ProcedureReturn _ListImage()\Info\ImageFileFormat
EndIf
Next
_ListImage()\ImageID = ImageID
EndIf
EndProcedure
;-
;- 测试函数 --------------
FileName_DDS$ = "F:\Buff_001.dds"
FileName_JPG$ = "F:\Buff_002.jpg"
hwnd.l = OpenWindow(0, 10, 10, 640, 480, "迷路DDS预览实例" )
If hwnd = 0 : End: EndIf
CreateGadgetList(hwnd)
ImageGadget(1,10,10,24,24,0 );
ImageGadget(2,50,10,100,100,0 );
MPDX_OpenD3D9Device()
MPDX_LoadImage(1, FileName_DDS$)
MPDX_DrawImage(1)
Debug "图片文件1:"
Debug "宽度:" + Str(MPDX_ImageWidth(1))
Debug "高度:" + Str(MPDX_ImageHeight(1))
Debug "格式:" + Str(MPDX_ImageFormat(1))
Debug ""
MPDX_LoadImage(2, FileName_JPG$)
MPDX_DrawImage(2)
Debug "图片文件2:"
Debug "宽度:" + Str(MPDX_ImageWidth(2))
Debug "高度:" + Str(MPDX_ImageHeight(2))
Debug "格式:" + Str(MPDX_ImageFormat(2))
While Not WindowEvent() = #PB_Event_CloseWindow
MPDX_DrawImage(1) ; 通过不断的刷新来让窗体持续显示图片
MPDX_DrawImage(2) ; 通过不断的刷新来让窗体持续显示图片
Wend
MPDX_ClosetD3D9Device()
DataSection
VerticeData:
Data.f -1, 1, 0, 0, 0, 1, 1, 0, 1, 0, -1, -1, 0, 0, 1, 1, -1, 0, 1, 1
I came to the ancient oriental country - China
I will PureBasic called B++
I will PureBasic called B++
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: How to preview DDS files [Help me]
Nice work! 

IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.