such as the CreateTeapot function - http://msdn.microsoft.com/en-us/library/windows/desktop/bb172798(v=vs.85).aspx
Is there an equivalent in DX10? If so, how do I use it?
In DX9 you..
Declared:
LPD3DXMESH meshTeapot;
Initialised:
D3DXCreateTeapot(device, &meshTeapot, NULL);
Drew:
meshTeapot->DrawSubset(0);
Released:
meshTeapot->Release();
Is there an equivalent set of methods for drawing primitives? (to be honest the sphere is of more interest to me than the teapot!)
The D3DX library changed quite a bit from DirectX9 to DirectX11. Many of the helper functions were removed, including the shape drawing ones. However, DirectX11's DXUT library contains many of those functions you are looking for. In the DXUTOptional project, there is a DXUTShaped.h file, which contains DXUTCreateTeapot(). Here are all of the shape creation functions it supports...
HRESULT WINAPI DXUTCreateBox( ID3D10Device* pDevice, float fWidth, float fHeight, float fDepth, ID3DX10Mesh** ppMesh );
HRESULT WINAPI DXUTCreateCylinder( ID3D10Device* pDevice, float fRadius1, float fRadius2, float fLength, UINT uSlices, UINT uStacks, ID3DX10Mesh** ppMesh );
HRESULT WINAPI DXUTCreatePolygon( ID3D10Device* pDevice, float fLength, UINT uSides, ID3DX10Mesh** ppMesh );
HRESULT WINAPI DXUTCreateSphere( ID3D10Device* pDevice, float fRadius, UINT uSlices, UINT uStacks, ID3DX10Mesh** ppMesh );
HRESULT WINAPI DXUTCreateTorus( ID3D10Device* pDevice, float fInnerRadius, float fOuterRadius, UINT uSides, UINT uRings, ID3DX10Mesh** ppMesh );
HRESULT WINAPI DXUTCreateTeapot( ID3D10Device* pDevice, ID3DX10Mesh** ppMesh );
You can find the DXUT library where you installed the DirectX SDK. Mine is at
"C:\Program Files (x86)\Microsoft DirectX SDK (August 2009)\Samples\C++\DXUT11"
If you do not want to use DXUT in your project, you can just look at the source code in the DXUTOptional project and adapt it for you own purposes. All of DXUT's source code is available in the DXUTCore and DXUTOptional projects.
Good luck!
Related
I am using a biometrics SDK. And I converted the headers to delphi to consume the dll.
It looks something like this:
const
{VrBio_EventType}
VRBIO_CAPTURE_EVENT_UNPLUG = $001; {Fingerprint scanner unplugged from the computer.}
VRBIO_CAPTURE_EVENT_PLUG = $002; {Fingerprint scanner plugged on the computer.}
VRBIO_CAPTURE_EVENT_REMOVED = $004; {Finger removed from the fingerprint scanner.}
VRBIO_CAPTURE_EVENT_PLACED = $008; {Finger placed on the fingerprint scanner.}
VRBIO_CAPTURE_EVENT_IMAGE_FRAME = $10; {A fingerprint frame was captured on the fingerprint scanner.}
VRBIO_CAPTURE_EVENT_IMAGE_CAPTURED = $020; {A fingerprint image was captured on the fingerprint scanner.}
VRBIO_CAPTURE_EVENT_FAKE_FINGER_DETECTED = $400; {A false finger has been detected on the sensor}
VRBIO_CAPTURE_EVENT_FAKE_FINGER_REMOVED = $800; {A false finger has been removed from the sensor}
type
(* Stores the parameters of the ISO 19794-4 image format. #see VGetReaderProperties #see VrBio_ReaderProperty
typedef struct
{
/** #see VrBio_ISO197944CompressionMode*/
int compressionMode;
/** #see VrBio_ISO197944ImpressionType*/
int impressionType;
/** #see VrBio_ISO197944FingerPosition*/
int fingerPosition;
}VrBio_ISO197944Parameters;
*)
PISO197944Parameters = ^TISO197944Parameters;
TISO197944Parameters = record
compressionMode: Integer; { #see VrBio_ISO197944CompressionMode}
impressionType: Integer; { #see VrBio_ISO197944ImpressionType}
fingerPosition: Integer; { #see VrBio_ISO197944FingerPosition}
end;
(* Represents a biometric image. #see VrBio_CaptureEventCallback \ref VSyncCapture
struct VrBio_BiometricImage
{
/** Image width.*/
int width;
/**Image height*/
int height;
/**Image resolution in dpi. For the obsolete functions, use pixels/cm.*/
int resolution;
/**Number of channels in the image. Fingerprint images should always be grayscale, so this value is always 1.*/
int channels;
/**Biometric modality.
* Always use VRBIO_BIOMETRIC_MODALITY_FINGERPRINT.
* \ref VrBio_BiometricModality.
*/
int biometricModality;
/**Scanner type.
* \ref VrBio_ScannerType.
*/
int scannerType;
/**Formato de imagem: Formato da imagem.
*\ ref VrBio_ImageFormat.*/
int imageFormat;
/**Size of the buffer*/
int bufferSize;
/**Compression rate. Valid for images that allow compression.
* \ref VrBio_CompressionRate
*/
int compressionRate;
/**Quality of the fingerprint image.
* \ref VrBio_FingerQuality
*/
int fingerQuality;
/** Only valid if the image if imageFormat is \ref VrBio_ImageFormat::VRBIO_IMAGEFORMAT_ISO19794_4
*\ref VrBio_ISO197944Parameters
*/
VrBio_ISO197944Parameters* ISO197944_parameters;
/** Buffer storing the pixels of the image.
The position(x,y,c) of a pixel is y*width*channels+x*channels+c.
*/
unsigned char* buffer;
/**Reserved for future use*/
void* reserved;
};
typedef struct VrBio_BiometricImage VrBio_BiometricImage;
*)
PBiometricImage = ^TBiometricImage;
TBiometricImage = record
width: Integer; { Image width. }
height: Integer; { Image height }
resolution: Integer; { Image resolution in dpi. For the obsolete functions, use pixels/cm.}
channels: Integer; { Number of channels in the image. Fingerprint images should always be grayscale, so this value is always 1. }
biometricModality: Integer; { Biometric modality. Always use VRBIO_BIOMETRIC_MODALITY_FINGERPRINT. \ref VrBio_BiometricModality. }
scannerType: Integer; { Scanner type. \ref VrBio_ScannerType. }
imageFormat: Integer; { Formato de imagem: Formato da imagem. \ ref VrBio_ImageFormat. }
bufferSize: Integer; { Size of the buffer }
compressionRate: Integer; { Compression rate. Valid for images that allow compression. \ref VrBio_CompressionRate }
fingerQuality: Integer; { Quality of the fingerprint image. \ref VrBio_FingerQuality }
ISO197944_parameters: PISO197944Parameters; { Only valid if the image if imageFormat is \ref VrBio_ImageFormat::VRBIO_IMAGEFORMAT_ISO19794_4 \ref VrBio_ISO197944Parameters }
buffer: PByte; { Buffer storing the pixels of the image. The position(x,y,c) of a pixel is y*width*channels+x*channels+c. }
reserved: Pointer; { Reserved for future use }
end;
(*
#include "VTypes.h"
#ifdef WIN32
#define DLLIMPORT extern "C" __declspec(dllimport) int __stdcall
#else
#define DLLIMPORT extern "C"
#endif
*)
{ Callback function that receives events..
typedef void (*VrBio_CaptureEventCallback) (
int eventType,
const char* readerName,
VrBio_BiometricImage* image,
const void* userData)
}
TCaptureEventCallback = procedure(eventType: Integer; readerName: PAnsiChar; image: PBiometricImage; userData: Pointer); stdcall;
{ Function responsible for initializing the SDK. This function MUST be called before calling any other method, except \ref VInstallLicense
DLLIMPORT VStartSDK(VrBio_CaptureEventCallback eventCallback);
}
function VStartSDK(eventCallback: TCaptureEventCallback): Integer; stdcall;
{ Function responsible for finalizing the SDK. This function should be called when the SDK is not needed in the application anymore.
DLLIMPORT VStopSDK();
}
function VStopSDK(): Integer; stdcall;
{ Function responsible for starting the capture on a specific fingerprint reader.
After calling this function, the application is able to receive events.
DLLIMPORT VStartReader(const char* readerName);
}
function VStartReader(readerName: PAnsiChar): Integer; stdcall;
Using it looks like this:
implementation
{$R *.dfm}
procedure EventCallback(eventType: Integer; readerName: PAnsiChar; image: PBiometricImage; userData: Pointer); stdcall;
begin
case eventType of
VRBIO_CAPTURE_EVENT_UNPLUG: Form1.Memo1.Lines.Add('Leitor desconectado!');
VRBIO_CAPTURE_EVENT_REMOVED: Form1.Memo1.Lines.Add('Dedo removido!');
VRBIO_CAPTURE_EVENT_PLACED: Form1.Memo1.Lines.Add('Dedo detectado!');
VRBIO_CAPTURE_EVENT_IMAGE_FRAME: Form1.Memo1.Lines.Add('Frame capturado!');
VRBIO_CAPTURE_EVENT_IMAGE_CAPTURED: Form1.Memo1.Lines.Add('Imagem capturada!');
VRBIO_CAPTURE_EVENT_FAKE_FINGER_DETECTED: Form1.Memo1.Lines.Add('Dedo falso detectado!');
VRBIO_CAPTURE_EVENT_FAKE_FINGER_REMOVED: Form1.Memo1.Lines.Add('Dedo falso removido!');
VRBIO_CAPTURE_EVENT_PLUG:
begin
VStartReader(readerName);
Form1.Memo1.Lines.Add('Leitor conectado!');
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
VStartSDK(EventCallback);
end;
My questions:
I can use the application and get the Plug, Unplug and Placed events, but when I get the Image Captured event I have an acces vilation.
In the events that are working the EventCallback parameter image is nil. Is the TBiometricImage record conversion correct?
How can I convert the TBiometricImage buffer to a TBitmap and display the captured image in a TImage?
when I get the Image Captured event I have an acces vilation. In the events that are working the EventCallback parameter image is nil. Is the TBiometricImage record conversion correct?
The individual fields are declared fine, but double check that the alignment and padding of your Delphi records match the same alignment and padding used by the structs in C/C++.
Also, more importantly, the VrBio_CaptureEventCallback typedef in C/C++ is declared without any calling convention specified, so it will use the compiler's default convention, which is usually __cdecl instead of __stdcall (can be configured in the compiler settings). In Delphi, you declared TCaptureEventCallback to use stdcall instead of cdecl. You have to make sure you match the calling conventions correctly (the exported DLL functions do use stdcall, so you are OK there).
How can I convert the TBiometricImage buffer to a TBitmap and display the captured image in a TImage?
The SDK documentation does not explain how to process the various image formats. However, just looking at the struct declaration, the buffer field points at the actual image data, and the imageFormat field indicates the format of that data (there is a VrBio_ImageFormat enum that you have not translated yet). So, you would have to look at the imageFormat first to know how to interpret the buffer.
I do see a VConvertImage() function available. So you should be able to convert images to BMP format, if they are not already. Based on the samples in the SDK, it looks like the buffer data might be a standard BMP file format, so you could try copying the buffer to a TMemoryStream and then use the TBitmap.LoadFromStream() method.
There are also GIF and JPG image formats available, which could be handled by TGIFImage and TJPEGImage, respectively, or even TWICImage, if you wanted to display scanned GIF/JPG images without having to convert them to BMP first. There is also a RAW image format available (which apparently your images are using), but there is no standard VCL TGraphic class to handle RAW images, but I think there might be some 3rd party classes floating around if you look around.
Otherwise, you might try converting the image data to BMP, if needed, and then pass the buffer to the Win32 API CreateBitmap/Indirect() or CreateDibSection() function, and then assign the resulting HBITMAP to the TBitmap.Handle property if successful.
How can I get a window position (x,y) created by using OpenCV?
I can create a named window: namedWindow("my window");
I can move this window: moveWindow("my window", x, y);
But how can I get current position's coordinates of this window?
Also, there is function void loadWindowParameters("my window");, which can as written:
loads size, location, flags, trackbars value, zoom and panning
location of the window window_name
But does it load these parameters to where? Declaration of this function does not return anything - get only window name and return void.
Until the feature request for this feature gets done, if you need this functionality and can't wait, you can implement it yourself. You'll need the opencv source code, then you'll have to edit some opencv files and rebuild part of opencv.
I followed the source code for moveWindow() as a model.
That's what I did:
add to opencv/sources/modules/highgui/source/window_w32.cpp this function (I added it just below the cvMoveWindow definition):
CV_IMPL void cvGetWindowRect( const char* name, int &x, int &y, int &width, int &height)
{
CV_FUNCNAME( "cvGetWindowRect" );
__BEGIN__;
CvWindow* window;
RECT rect;
if( !name )
CV_ERROR( CV_StsNullPtr, "NULL name" );
window = icvFindWindowByName(name);
if(!window)
EXIT;
GetWindowRect( window->frame, &rect );
x = rect.left;
y = rect.top;
width = rect.right - rect.left;
height = rect.bottom - rect.top;
__END__;
}
and add its declaration in opencv/sources/modules/highgui/include/opencv2/highgui_c.h :
CVAPI(void) cvGetWindowRect( const char* name, int &x, int &y, int &width, int &height);
This alone would allow you to use the cvGetWindowRect from C/C++ to get the window rect. But if you want to use the C++ interface or the python interface (as I do) you can edit two files more:
add to opencv/sources/modules/highgui/source/window.cpp this function:
void cv::getWindowRect( const String& winname, CV_OUT int &x, CV_OUT int &y, CV_OUT int &width, CV_OUT int &height)
{
cvGetWindowRect(winname.c_str(), x, y, width, height);
}
and add its declaration in opencv/sources/modules/highgui/include/opencv2/highgui.hpp :
CV_EXPORTS_W void getWindowRect( const String& winname, CV_OUT int &x, CV_OUT int &y, CV_OUT int &width, CV_OUT int &height);
Then you'll have to rebuild the opencv_highgui project (I do this for windows with Visual Studio 2015). If you need the python bindings then rebuild the opencv_python3 project too. The CV_EXPORTS_W and CV_OUT macros are needed to expose the function and recognize the output parameters when building the python bindings. From python you'll get a 4-tuple as return value, ->eg:
>>> cv2.getWindowRect("my window")
(1024, 0, 817, 639)
For the python bindings you'll have to copy the new cv2.cp35-win_amd64.pyd and opencv_highgui300.dll to the PythonEnv\Lib\site-packages.
How can I retrieve the texture width, height, number of mipmap levels of the texture which has been already created in DirectX? what is the API for it?
Use ID3D10Texture2D::GetDesc, Assume pTexture is a valid pointer to ID3D10Texture2D, then
D3D10_TEXTURE2D_DESC texDesc;
pTexture->GetDesc(&texDesc);
Here is the information you can get from texDesc
typedef struct D3D10_TEXTURE2D_DESC {
UINT Width;
UINT Height;
UINT MipLevels;
UINT ArraySize;
DXGI_FORMAT Format;
DXGI_SAMPLE_DESC SampleDesc;
D3D10_USAGE Usage;
UINT BindFlags;
UINT CPUAccessFlags;
UINT MiscFlags;
} D3D10_TEXTURE2D_DESC;
Delphi syntax:
procedure Move(const Source; var Dest; Count: Integer);
C++ syntax:
extern PACKAGE void __fastcall Move(const void *Source, void *Dest, int Count);
I have used Function Move in Delphi long time ago,
recently I want to call it in C++ Builder 6,
I wrote it as the same as I did in Delphi,
the error appearance --> "Expression Syntax".
Dose anyone know how to call it?
or there is other function works similar to it?
BYTE src[] = "Source Data";
BYTE dst[11];
Move(src, dst, sizeof(dst));
It is better to use memmove in C++:
memmove(dst, src, sizeof(dst));
This is my program to display a .x mesh. I am able to display the mesh tiger.x but not able to display ball.x. What is the difference between the two meshes? Is there something I should handle in the code? But I am able to view both the meshes using standard mesh viewers like the one which come with DirectX SDK.
Thanks.
but not able to display ball.x.
The question is unclear. Does the mesh load? Does it contain vertices/faces? Or maybe it crashes app? Or loading fails?
What is the difference between the two meshes?
The difference is that the second mesh (ball.x) doesn't include "templates".
I.e. this part:
template Header {
<3D82AB43-62DA-11cf-AB39-0020AF71E433>
WORD major;
WORD minor;
DWORD flags;
}
template Vector {
<3D82AB5E-62DA-11cf-AB39-0020AF71E433>
FLOAT x;
FLOAT y;
FLOAT z;
}
template Coords2d {
<F6F23F44-7686-11cf-8F52-0040333594A3>
FLOAT u;
FLOAT v;
}
template Matrix4x4 {
<F6F23F45-7686-11cf-8F52-0040333594A3>
array FLOAT matrix[16];
}
template ColorRGBA {
<35FF44E0-6C7C-11cf-8F52-0040333594A3>
FLOAT red;
FLOAT green;
FLOAT blue;
FLOAT alpha;
}
template ColorRGB {
<D3E16E81-7835-11cf-8F52-0040333594A3>
FLOAT red;
FLOAT green;
FLOAT blue;
}
template IndexedColor {
<1630B820-7842-11cf-8F52-0040333594A3>
DWORD index;
ColorRGBA indexColor;
}
template Boolean {
<4885AE61-78E8-11cf-8F52-0040333594A3>
WORD truefalse;
}
template Boolean2d {
<4885AE63-78E8-11cf-8F52-0040333594A3>
Boolean u;
Boolean v;
}
template MaterialWrap {
<4885AE60-78E8-11cf-8F52-0040333594A3>
Boolean u;
Boolean v;
}
template TextureFilename {
<A42790E1-7810-11cf-8F52-0040333594A3>
STRING filename;
}
template Material {
<3D82AB4D-62DA-11cf-AB39-0020AF71E433>
ColorRGBA faceColor;
FLOAT power;
ColorRGB specularColor;
ColorRGB emissiveColor;
[...]
}
template MeshFace {
<3D82AB5F-62DA-11cf-AB39-0020AF71E433>
DWORD nFaceVertexIndices;
array DWORD faceVertexIndices[nFaceVertexIndices];
}
template MeshFaceWraps {
<4885AE62-78E8-11cf-8F52-0040333594A3>
DWORD nFaceWrapValues;
Boolean2d faceWrapValues;
}
template MeshTextureCoords {
<F6F23F40-7686-11cf-8F52-0040333594A3>
DWORD nTextureCoords;
array Coords2d textureCoords[nTextureCoords];
}
template MeshMaterialList {
<F6F23F42-7686-11cf-8F52-0040333594A3>
DWORD nMaterials;
DWORD nFaceIndexes;
array DWORD faceIndexes[nFaceIndexes];
[Material]
}
template MeshNormals {
<F6F23F43-7686-11cf-8F52-0040333594A3>
DWORD nNormals;
array Vector normals[nNormals];
DWORD nFaceNormals;
array MeshFace faceNormals[nFaceNormals];
}
template MeshVertexColors {
<1630B821-7842-11cf-8F52-0040333594A3>
DWORD nVertexColors;
array IndexedColor vertexColors[nVertexColors];
}
template Mesh {
<3D82AB44-62DA-11cf-AB39-0020AF71E433>
DWORD nVertices;
array Vector vertices[nVertices];
DWORD nFaces;
array MeshFace faces[nFaces];
[...]
}
template FrameTransformMatrix {
<F6F23F41-7686-11cf-8F52-0040333594A3>
Matrix4x4 frameMatrix;
}
I.e. templates/structure declarations.
Also, in ball.x mesh is a part of hierarchy of Frames. In tiger.x it isn't, and is stored on top level of hierarchy.
It's been a while since I last used *.x file directly, but as far as I know, you'll need to include templates for all "non standard" templates into file. i.e. if file uses an object with template that wasn't registred using RegisterTemplates method of ID3DXFile or IDirectXFile, then the file won't load if template isn't written at the beginning of file. Try adding template definitions for every suspicious structure in ball.x , until you find the culprit . I'd start with "Header".
If the problem is because of hierarchy, you'll need to try another loading method.
using standard mesh viewers like the one which come with DirectX SDK.
AFAIK, mesh viewer comes with source code. Read the source and see how it works.
The mesh does not have any issue but the view. It was too zoomed in to display the image. I projected the image using the following matrix and was able to view the mesh properly.
//Set Projection
D3DXMATRIXA16 matProj(1.0,0.0,0.0,0.0,
0.0,1.0,0.0,0.0,
0.0,0.0,1.0,0.0,
0.0,0.0,0.0,150.0);