# VBForums CodeBank > CodeBank - Visual Basic 6 and earlier >  [VB6] Direct3D9.

## The trick

Hello everyone.
In the archive contains a type library "DirectX 9 for Visual Basic 6.0 type library by The trick" (dx9vb.tlb) contains a description of the following interfaces:
IDirect3D9;IDirect3DDevice9;IDirect3DSurface9;IDirect3DResource9;IDirect3DSwapChain9;IDirect3DTexture9;IDirect3DBaseTexture9;IDirect3DVolumeTexture9;IDirect3DVolume9;IDirect3DCubeTexture9;IDirect3DVertexBuffer9;IDirect3DIndexBuffer9;IDirect3DStateBlock9;IDirect3DVertexDeclaration9;IDirect3DVertexShader9;IDirect3DPixelShader9;IDirect3DQuery9.
Also in the library declared many types, constants and enumerations. The work of this library tested poorly, so something may not work. Also in the archive includes several modules written in VB6:
D3DX_COLOR.bas - for work with colors;D3DX_MATRICES.bas - for work with matrices;D3DX_QUATERNION.bas - for work with quaternions;D3DX_VECTOR2.bas, D3DX_VECTOR3.bas, D3DX_VECTOR4.bas - for work with vectors;D3DX_MISC.bas - other functions.
These modules include analogs of the respective functions D3DX. Also in the archive contains several test examples.





GitHub link

_08.24.2015. added drawing text example._

_09.17.2015. added 3D form example._

_02.27.2016. Fixed bug in D3DXMatrixTranspose function. Changed type of pointers to Any in methods IDirect3DDevice9::CreateVertexShader, IDirect3DDevice9::CreatePixelShader, IDirect3DDevice9::SetPixelShaderConstantB, IDirect3DDevice9::SetPixelShaderConstantI, IDirect3DDevice9::SetPixelShaderConstantF, IDirect3DDevice9::SetVertexShaderConstantB, IDirect3DDevice9::SetVertexShaderConstantI, IDirect3DDevice9::SetVertexShaderConstantF_

_05.06.2018. added simple scene example (camera, procedural generation, mouse picking, basic transformations); "laser lines" example, rendering in different thread example. Fixed bug in functions: D3DXMatrixTranspose, D3DXMatrixRotationQuaternion, D3DXVec2Length;
Changed function prototype for D3DXPlaneIntersectLine, error raising has been changed to return value;
Changed behavior of function D3DXQuaternionToAxisAngle, now it accepts non-normalized quaternions;_

----------


## georgekar

Have you something to draw text?
I would like to see any implementation..so maybe I put dx9 in M2000 Environment...some day...(Can we make controls with dx9??)

----------


## The trick

For drawing text you can use standard GDI functions. Usually uses special texture which contain a symbols. When you desire to draw some string you create a quads which represent each symbol with texture coordinates. Of course you can create this table dynamically using DrawText, GetTextExtentPoint32 etc. 
I add example work with text, download again it. In the example i use fixed simplest table using only digit and letter:

If you want create 3D-text look like this:

Then you should use GetGlyphOutline function in order to obtain a shape of each symbols and extrude mesh from it.

----------


## The trick



----------


## interactii

This is some really nice work. I think I will be using some of this! Thanks for the efforts!

----------


## mozaiktm

I have downloaded the file, but I can not find the file "clsTrickSubclass2.cls"
so, where can I find these files?

----------


## The trick

http://www.vbforums.com/showthread.p...ws-and-classes

----------


## mozaiktm

Thanks for your help.

----------


## Navion

Thanks for this very interesting post.

Now just quickly browsing through the bas modules, there is an error (typo most probably) in the module : D3DX_VECTOR2.bas

This function is not quite right :




```
Public Function D3DXVec2Length(pV As D3DVECTOR2) As Single
    
    D3DXVec2Length = Sqr(pV.X * pV.X + pV.Y + pV.Y)
    
End Function
```

----------


## The trick

> Thanks for this very interesting post.
> 
> Now just quickly browsing through the bas modules, there is an error (typo most probably) in the module : D3DX_VECTOR2.bas
> 
> This function is not quite right :
> 
> 
> 
> 
> ...


Thanks, i've fixed it.

----------


## The trick

New version 1.1.
Fixed bug in *D3DXMatrixTranspose* function. Changed type of pointers to *Any* in methods *IDirect3DDevice9::CreateVertexShader*, *IDirect3DDevice9::CreatePixelShader*, *IDirect3DDevice9::SetPixelShaderConstantB*, *IDirect3DDevice9::SetPixelShaderConstantI*, *IDirect3DDevice9::SetPixelShaderConstantF*, *IDirect3DDevice9::SetVertexShaderConstantB*, *IDirect3DDevice9::SetVertexShaderConstantI*, *IDirect3DDevice9::SetVertexShaderConstantF*

----------


## loquat

Hi Thread Starter
    I have found two open source as you do
http://roardx9.codeplex.com/
http://www.vbgood.com/thread-80529-1-1.html

----------


## DEXWERX

I definitely recommend against Roar - as it's adds a wrapper DLL, instead of calling the API directly.

----------


## The trick

I tried to do the independent source therefore the most part of this project is the standard modules with the sources of some *D3DX* functions. You don't need of an additional dependencies after compilation. I also didn't use any D3DX additional library.

----------


## DEXWERX

> I tried to do the independent source therefore the most part of this project is the standard modules with the sources of some *D3DX* functions. You don't need of an additional dependencies after compilation. I also didn't use any D3DX additional library.


The best approach  :Thumb:

----------


## The trick

> The best approach


Thanks. I think may be it is better to add the texture manipulation functions as well. There are the many issues with the simulation *D3DXCreateTextureFromFileInMemoryEx* function particularly with the filtration. I could simulate it with GDI+.

----------


## Ben321

Your typelib has no sound based interfaces. How do I use dx9 to output and input audio?

----------


## The trick

http://www.vbforums.com/showthread.p...B6-DirectSound
You can use either that or that classes as well.

----------


## Ben321

Or how about create a single complete typelib for DX9, that has sound and graphics related interfaces? It appears your typelib is really all about graphics (maybe that's all you care about, but it's not complete). A good typelib for DX9 would do for DX9 what the official MS DX8 and 7 typelibs did, and that is have interfaces for sound AND interfaces for graphics. I assume that DX9 does have sound-based interfaces.

----------


## The trick

> Or how about create a single complete typelib for DX9, that has sound and graphics related interfaces? It appears your typelib is really all about graphics (maybe that's all you care about, but it's not complete). A good typelib for DX9 would do for DX9 what the official MS DX8 and 7 typelibs did, and that is have interfaces for sound AND interfaces for graphics. I assume that DX9 does have sound-based interfaces.


The last of DirectSound is DirectSound8 shown there. DirectSound9 doesn't exist.

----------


## DEXWERX

> The last of DirectSound is DirectSound8 shown there. DirectSound9 doesn't exist.


DirectSound for DirectX9 uses all the same DirectSound8 Interface definitions, plus some bugfixes. (So yeah DirectSound9 doesn't exist)

----------


## baka

im trying to understand how this work and to be able to change my GDI code project to DirectX9 code using "similar" functions that do the same job.
but to do that, i need to know how this works. the samples have lots of 3D effects while what I need is to load images with alphasetting (png), render those images on a surface and thats it.
so my question is, what do i need to do to just:

- Load multiple PNG images (using array)
- Render any or all of the images on a form, where I can choose x,y,width,height.
- Cls the form (similar to FillRect+Brush) so that I can make a animation/loop
- Render a image mirrored (in GDI you can simply make source width/height negative)

----------


## The trick

baka, it's better to use Direct2D for 2d graphics. Of course you can use Direct3D for 2d graphics too.
For loading a PNG image you can use any code that gets pixels data. Then you should create a texture, lock it in the memory, copy the pixels data there and unlock texture (look the sources where i use textures).
For rendering on a form, you need to create a quad that represents the rendering surface. Then you need specify the texture coordinates to the quad's vertex (look text rendering source).
Cls - it just Clear method of IDirect3DDevice9 interface.
For mirroring you can use many ways, you can just change view matrix, or transform matrix.

----------


## The trick

*Update.*

The new examples:
Added simple scene example (camera, procedural generation, mouse picking, basic transformations);Added "laser lines" example;Added rendering in different thread example. 

Fixed bugs in the functions:
*D3DXMatrixTranspose*;*D3DXMatrixRotationQuaternion*;*D3DXVec2Length*.

Changes:
Changed function prototype for *D3DXPlaneIntersectLine*, error raising has been changed to return value;Changed behavior of function *D3DXQuaternionToAxisAngle*, now it accepts non-normalized quaternions;




Enjoy!

----------


## Elroy

@Trick:  The SimpleScene demo is *TOTALLY* cool.  I'll possibly plod along with DX8 for a bit, but you've made the jump to DX9 quite trivial.  I can't thank you enough for doing this.

All The Best Wishes To You,
Elroy

EDIT1:  Just for others, Trick has included all three of Rotate, Zoom, & Pan for the camera.  The Pan is on the middle-mouse button.  Because I've got my middle button programmed for something else, I made the following small change to his code in the SimpleScene demo (the frmMain).

In the picViewport_MouseMove event, I did the following...



```

	' from

ElseIf Button = vbMiddleButton Then

	' to

ElseIf Button = vbLeftButton + vbRightButton Then ' Holding both buttons down.

```

This allowed me to hold both left-and-right buttons down to get to the pan features.

Trick, again, this is *fabulous* stuff.

EDIT2:  Actually, after further reflection (and testing), I changed the entire event to the following:



```

Private Sub picViewport_MouseMove( _
            ByRef Button As Integer, _
            ByRef Shift As Integer, _
            ByRef X As Single, _
            ByRef Y As Single)
    Static fOx  As Single
    Static fOy  As Single

    Select Case meCurrentMode
    Case MM_CREATION

        ' // Creation stages
        Select Case tObjectCreation.eObject
        Case MM_CREATE_SPHERE
            CreatingSphere X, Y
        Case MM_CREATE_CONE
            CreatingCone X, Y
        Case MM_CREATE_BOX
            CreatingBox X, Y
        End Select

    Case Else

        ' // Camera movement
        If Button = vbLeftButton Then

            mcScene.Camera.RotateRel vec3(-(Y - fOy) / 100, -(X - fOx) / 100, 0)
            Render

        ElseIf Button = vbRightButton Then

            mcScene.Camera.Zoom -(fOy - Y) / 10
            Render

        ElseIf (Button = vbLeftButton + vbRightButton) Or Button = vbMiddleButton Then

            mcScene.Camera.Pan -(X - fOx) / 10, (Y - fOy) / 10
            Render

        End If

    End Select

    fOx = X: fOy = Y

End Sub


```

From Trick's original code, this swaps vbLeftButton and vbRightButton.  And it also "add" the (Button = vbLeftButton + vbRightButton) to the pan rather than just replacing vbMiddleButton.

This is the way Vicon Nexus works, which is somewhat an industry standard in displaying mocap data.


Best Regards,
Elroy

----------


## Elroy

Hi again, Trick.   :Smilie: 

Hey, I've got yet another request.  However, if you don't already have this, just forget it.  You've already done WAY too much for me, and I absolutely love your SimpleScene demo.  I've been working with it all day long.

Ok, here's the request.  Do you have a class that's similar to the older cd3dFrame.cls class?  In the SimpleScene demo, you give us that CScene.cls, and it does handle "children", but it's not really set up to be nested any further than that.  In my situation, I'll be cascading "objects" such that each object defines a *local*-coordinate-system for all its children.  That way, I can do rotations and translations relative to the parent (rather than the "scene") (like reverse kinematics).

Again, if you don't have it lying around, please, no worries.  I'll develop it on my own.


Also, just another FYI, I noticed that you've got three procedures that deal with Euler angles: 
modMain.MatrixToEulerD3DX_MATRICES.D3DXMatrixRotationYawPitchRollD3DX_QUATERNION.D3DXQuaternionRotationYawPitchRoll

As I'm sure you know, anytime you convert Euler angles to a quaternion (or a transformation matrix), you've got to deal with the X,Y,Z order (and pick one, or let the user specify the order).  I haven't studied your code well enough to know which order you picked, but I'll need to allow the user to specify which order they'd like.

Also, as I'm sure you know, when dealing with Euler angles, we must be careful or we might wind up in a gimbal lock situation.

I'll probably rewrite those procedures, allowing for the specification of a Euler order.  I'll post them when I get it done.

Again THANK YOU!

Take Care,
Elroy

----------


## The trick

Hi Elroy,
If you want transform an object relative a parent object you just need to combine the two transformation matrix (like i did pivot point, just think about it like parent object and you can make arbitrary number of the chains). Just multiply the transformation to the parent transformation matrix.





> Also, just another FYI, I noticed that you've got three procedures that deal with Euler angles:


They work like original DirectX functions.



> The order of transformations is roll first, then pitch, then yaw.

----------


## Elroy

Hi Trick,  :Smilie: 

Thanks for that.  Yeah, I'm slowly coming to grips with this stuff.  It's just a lot of new stuff to learn, not really having swam in the "deep end" of DX stuff before.  I'll get there though.  And yeah, I saw how you handled the pivot point.   :Smilie: 

I'm actually now working on another small problem.  I'd like to place a small "World" coordinate system "indicator" up in the top-left corner of my window.  I'll get it worked out, but I'll outline the problem to you anyway.  Let me start with a little video from some other software to illustrate what I'm talking about**:

Video Here

It's those three Red,Green,Blue lines (I'm creating three meshes for them).  In that software, it's in lower-left, but I like upper-left better as it's more out-of-the-way.  Basically, it doesn't scale or pan, but it does rotate.  The way I'm approaching the problem is to add functionality to the Camera Class.  I've already got a new procedure in it named ViewMatrixFixedDist(nDistance As Single) As D3DMATRIX.  Using that for my D3DTS_VIEW matrix of this little coordinate system indicator solves the no-scale problem.  If I grab the camera's target position, I can solve the no-pan problem.  However, I'm still working on moving it up to the corner.  All I know to do is to use the camera's rotation to un-rotate the line-meshes, translate to the corner, and then re-rotate the lines-meshes.  And the reason I can't just do it once, is because I want to be able to resize the screen (Viewport).  I've already got the resizing working nicely.

Also, when dealing only with rotations, I'm more used to thinking in terms of quaternions, rather than transformation matrices.  Therefore, I put together this little function:



```

Public Sub D3DXVec3ByQuatMultiply(pOut As D3DVECTOR, _
                                  pV As D3DVECTOR, _
                                  pQ As D3DQUATERNION)
    pOut.X = (1! - (pQ.Y * pQ.Y * 2! + pQ.Z * pQ.Z * 2!)) * pV.X + (pQ.X * pQ.Y * 2! - pQ.w * pQ.Z * 2!) * pV.Y + (pQ.X * pQ.Z * 2! + pQ.w * pQ.Y * 2!) * pV.Z
    pOut.Y = (pQ.X * pQ.Y * 2! + pQ.w * pQ.Z * 2!) * pV.X + (1! - (pQ.X * pQ.X * 2! + pQ.Z * pQ.Z * 2!)) * pV.Y + (pQ.Y * pQ.Z * 2! - pQ.w * pQ.X * 2!) * pV.Z
    pOut.Z = (pQ.X * pQ.Z * 2! - pQ.w * pQ.Y * 2!) * pV.X + (pQ.Y * pQ.Z * 2! + pQ.w * pQ.X * 2!) * pV.Y + (1! - (pQ.X * pQ.X * 2! + pQ.Y * pQ.Y * 2!)) * pV.Z
End Sub

```

I put it in your D3DX_VECTOR3 module.

Also, I prefer to write these things as functions, so here's my version of it:  :Smilie: 



```

Public Function DxVectorByQuatMultiply(uV As D3DVECTOR, uQ As D3DQUATERNION) As D3DVECTOR
    'DxVectorByQuatMultiply.X = (1! - (uQ.Y * uQ.Y * 2! + uQ.Z * uQ.Z * 2!)) * uV.X +       (uQ.X * uQ.Y * 2! - uQ.s * uQ.Z * 2!)  * uV.Y +       (uQ.X * uQ.Z * 2! + uQ.s * uQ.Y * 2!)  * uV.Z
    'DxVectorByQuatMultiply.Y =       (uQ.X * uQ.Y * 2! + uQ.s * uQ.Z * 2!)  * uV.X + (1! - (uQ.X * uQ.X * 2! + uQ.Z * uQ.Z * 2!)) * uV.Y +       (uQ.Y * uQ.Z * 2! - uQ.s * uQ.X * 2!)  * uV.Z
    'DxVectorByQuatMultiply.Z =       (uQ.X * uQ.Z * 2! - uQ.s * uQ.Y * 2!)  * uV.X +       (uQ.Y * uQ.Z * 2! + uQ.s * uQ.X * 2!)  * uV.Y + (1! - (uQ.X * uQ.X * 2! + uQ.Y * uQ.Y * 2!)) * uV.Z
    '
    DxVectorByQuatMultiply.X = (1! - (uQ.Y * uQ.Y * 2! + uQ.Z * uQ.Z * 2!)) * uV.X + (uQ.X * uQ.Y * 2! - uQ.w * uQ.Z * 2!) * uV.Y + (uQ.X * uQ.Z * 2! + uQ.w * uQ.Y * 2!) * uV.Z
    DxVectorByQuatMultiply.Y = (uQ.X * uQ.Y * 2! + uQ.w * uQ.Z * 2!) * uV.X + (1! - (uQ.X * uQ.X * 2! + uQ.Z * uQ.Z * 2!)) * uV.Y + (uQ.Y * uQ.Z * 2! - uQ.w * uQ.X * 2!) * uV.Z
    DxVectorByQuatMultiply.Z = (uQ.X * uQ.Z * 2! - uQ.w * uQ.Y * 2!) * uV.X + (uQ.Y * uQ.Z * 2! + uQ.w * uQ.X * 2!) * uV.Y + (1! - (uQ.X * uQ.X * 2! + uQ.Y * uQ.Y * 2!)) * uV.Z
End Function

```

All The Best,
Elroy

----------


## Elroy

WOW, this stuff gets complicated.  I managed to get my three little Red,Green,Blue sticks translated up into the top-left corner.  However, the camera is now looking "over" at them.  I need them rendered as if the camera that "sees the sticks" is normal (orthogonal) to the screen (possibly a second camera, but that sounds like over-kill).  I'll get it sorted.  I'm just publicly moaning at the complexity of this stuff.  And I need to get my head around the secrets embedded in the D3DTS_VIEW, D3DTS_PROJECTION, and D3DTS_WORLD settings.

Ahhh, I figured it out.  It finally dawned on me that this was like a post-render translation.  Therefore, I translated the D3DTS_PROJECTION matrix, and voila, I got what I wanted.  :Thumb:   Of course, I put it back before rendering everything else.

----------


## The trick

You can just change Viewport to the needed area and cancel moving in View matrix:
.m41 = 0
.m42 = 0
.m43 = 1

----------


## Leadron

Dear friends,
I'm writing a 3D program in VB6 with DirectX9 based on The trick's samples.
But at certain zooms and perspectives, the mesh that I made looks broken (intermittent) also look jagged at collision of 2 planes



I need help, what causes this to happen and how to deal with it?

thank you

----------


## The trick

It's called z-fighting issue. You can for example move the near plane away from camera to avoid that.

----------


## Leadron

Thanks The trick.. it solved by adjust the z near and z far :
D3DXMatrixPerspectiveFovLH tMtx, PI / 4, tRC.Right / tRC.Bottom, 50, 100000
This is because the size of my mesh object is very large

----------


## Leadron

Hello everyone, especially The trick, I found a new problem, when I use :

m_Direct3DDevice8.SetRenderState D3DRS_SRCBLEND, D3DBLEND_SRCALPHA
m_Direct3DDevice8.SetRenderState D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA
m_Direct3DDevice8.SetRenderState D3DRS_ALPHABLENDENABLE, True

DirectX doesn't drawn the alpha correctly.

I really need help, what is the solution to this problem?
All suggestions are highly appreciated.

I attach the picture :



Thanks.

----------


## The trick

The problem look like you forget to disable writing to Z-buffer when you draw the transparent polygons.
You can enable the Z-buffer and draw all the non-transparent polygons then disable writing and draw all the transparent polygons (sorted from far to near ones)

----------


## Leadron

Hi @The trick.. thanks for the reply
Disable the D3DRS_ZENABLE is resolves the alpha problem, but it will cause a new problem,
where the object that should look in front, it will be blocked with the other behind objects (in several perspectives)
Microsoft says that we should render it from front to back,
But it's almost impossible to re-create buffers every time I have to render, those trees are stored in a large enough vertexbuffer with the indices, say.. 300k-500k faces or more, and the position of each tree added randomly

If I am wrong in interpreting the 'right way' to process the data buffer, please correct me and please teach me the how it should be.

Thanks

----------


## xman2000

> It's called z-fighting issue. You can for example move the near plane away from camera to avoid that.


Hi @the Trick, i am begginer, you know or can make a GraphicsLibary  Pure VB6 open-source like Aforge?
the base of library with cornersDetectors, EdgeDEtectors, Thereshould, some scientifc algorithms, and next, add more features?
the algorithms of geometry in VB6 is more easy found in web, but the base of library not.
cheers!

----------


## Elroy

> Hi @the Trick, i am begginer, you know or can make a GraphicsLibary  Pure VB6 open-source like Aforge?
> the base of library with cornersDetectors, EdgeDEtectors, Thereshould, some scientifc algorithms, and next, add more features?
> the algorithms of geometry in VB6 is more easy found in web, but the base of library not.
> cheers!


This is basically a duplicate of this post.  

Xman, I don't understand why you feel the need to hijack other off-topic threads.  I think you'd have a much better response if you just started your own thread with an outline of your question over in the normal VB6 Q&A section.

----------


## xman2000

Hi, TheTrick

is awesome this 3D9 libary, you like make this entire in VB6 ? why?

----------


## The trick

> is awesome this 3D9 libary, you like make this entire in VB6 ? why?


Hi, xman2000:



> I tried to do the independent source therefore the most part of this project is the standard modules with the sources of some D3DX functions. You don't need of an additional dependencies after compilation. I also didn't use any D3DX additional library.

----------


## Elroy

> Hi, TheTrick
> 
> is awesome this 3D9 libary, you like make this entire in VB6 ? why?


Hi xman2000,

I've got no idea what motivates The Trick, as I've got little idea what motivates myself.  However, I'm sure glad that The Trick was willing to share this work.  I've used it in several of my own VB6 projects.  Here's a C3D mocap reader I've posted on the CodeBank that uses it.  I've also used it in several other contexts.

Take Care,
Elroy

----------


## xman2000

> Hi xman2000,
> 
> I've got no idea what motivates The Trick, as I've got little idea what motivates myself.  However, I'm sure glad that The Trick was willing to share this work.  I've used it in several of my own VB6 projects.  Here's a C3D mocap reader I've posted on the CodeBank that uses it.  I've also used it in several other contexts.
> 
> Take Care,
> Elroy


Hi Elroy,
this 3D9 libray is a greate work, greate project, and not problem if closed source-code, only i need some time use pure vb6 and i like to find in the web a pure vb6 library like this 3D9. 

My intention not is find the library only by algorithms but to pradronize the code, and se Library is big i use like external compiled file, but if the codes i need is small i use only few codes of library to my project, or rebuild the library into small libraries but with same pradronized code, to avoid bugs, to make more easy understand.

only is a question to know the plans of the autor and possible difficulties to implement this idea.


cheers.

----------


## Elroy

> this 3D9 libray is a greate work, greate project, and not problem if closed source-code, only i need some time use pure vb6 and i like to find in the web a pure vb6 library like this 3D9.


Hi Xman,

Everything about The Trick's work is open-source.  I'm not sure what you mean by closed-source?!  

He provided many linear algebra procedures (in VB6 open-source source-code).  But the main thing he provides is the DX9VB.tlb TypeLib, which allows VB6 to interface with the DirectX3D library built into Windows.  And this DX9VB.tlb is easily open-source as well.  Here, I've attached the IDL file for your perusal (see attached ZIP).

Now, you say "pure VB6".  This is about as pure VB6 as it gets.  Do you want to do all the DirectX3D graphics functions in VB6 code?  If so, that's sort of insane because the DirectX technology interfaces directly with the GPU (graphics processing unit) of your hardware to do its work.  Sure, you could write your own procedures with the graphics statements of a PictureBox (or a Form), but they'd be _MUCH_ slower than anything using DirectX.  Without DirectX (or some other similar technology, such as the stuff that uses OpenGL), you're not interfacing directly with the GPU.  That's the whole reason for DirectX.

Now, if you want the TypeLib out of the picture (and there's really no reason for that), you could drop back to DirectX8, which is directly COM compatible.  Also DirectX8 uses StdCall, which allows for API declarations directly in the VB6 source code, and no need for a TypeLib.  But again, what's wrong with a TypeLib?

The DirectX9 just comes with all recent versions of Windows, which is very convenient.  However, to use DirectX8, you'll have to find a copy of the dx8vb.dll, and distribute it with your application.

Good Luck,
Elroy

----------


## xman2000

Hi, Elroy,

yes, i like  "Do you want to do all the DirectX3D graphics functions in VB6 code? If so, that's sort of insane"

not problem if is more slow, only if works very well.

"Now, if you want the TypeLib out of the picture"  
i not understand "out of the picture" but i like the TypeLib in pure vb6 inside the project like a module .bas, or class or .frm but i need not use files.

in some times i use external files, .dll, .ocx, but other times i like use only vb6 code and others with apis.

i understand you speak this Libarry is to DirectX interaction, i I had imagined that something like this already existed, and that this library was a little (little and simple) substitute for Directx and people can add more features.

"you're not interfacing directly with the GPU"
yes, we can make a 3D Library replacement of Directx more simple with not GPU and other version of the 3D library with GPU.

 What would we need to do to create a GPU version?
there would be a need to create compatibility for the drivers of each VGA GPU device of each company?
eu can stop this subject not to flood this thread.

not problem if is more slow, only if works very well and not uses external files or external ressources, the most compatible and universal is better for some uses.

like this idea: have a 3D libray in pure VB6 i can put all code inside the vb project an re-use all functions and rebuild the big library into small libraries to especific purposes and can padronize the codes i use in image processing, and can add more features, more algorithms like scientific and image vision, medical, etc.

edit:it is not always necessary that the performance be very fast as for games at 60fps, it can be slow if it is only to visualize an object or a scenario observing the details, but perhaps to edit objects and see the changes in a reasonable speed a non- GPU library I do not know if it will.


edit2: but if we can but use the GPU but with everything written in VB6 with total replacement of Directx or OpenGL would be very good, even if it is a little slower than them.

This 3D9 library by TheTrick is greate and is specific to DirectX, greate! 
I was not sure if it was this or a replacement. Now i know.

----------


## Barrin

How about this? im using this source code but I cant load pictures from memory. Thanks.

----------


## The trick

> How about this? im using this source code but I cant load pictures from memory. Thanks.


Hello.
What's the problem exactly? Please show your attempts and i'll try to help you.

----------


## Barrin

Hi The trick! Thanks for replying.

Im trying to load a PNG file in memory directly into DX9, I used the D3Dx.CreateTextureFromFileInMemoryEx but I cannot find it in your typelib. Thanks.

----------


## The trick

> Hi The trick! Thanks for replying.
> 
> Im trying to load a PNG file in memory directly into DX9, I used the D3Dx.CreateTextureFromFileInMemoryEx but I cannot find it in your typelib. Thanks.


There is no this function in the type library. You could load a picture using GDI+ and using the bits of the picture to initialize texture IDirect3DTexture9.LockRect (see the prjCubeDemo).

----------


## leonbadman

Hi all, 

I need your help  :Smilie: 

My  problem: two textures; one for background (image from hd), the other one with a lot of text (with vertex), black background, and text color random.

I need to make transparent only the black background, not alpha the text (must be completly opaque)

This is my code:

    ' // Apply texture Background
    d3dev.SetTexture 0, texture
    d3dev.DrawPrimitive D3DPT_TRIANGLELIST, 0, 2

      ' // Remove texture
    d3dev.SetTexture 0, Nothing
    d3dev.SetTexture 0, textureText

        d3dev.SetRenderState D3DRS_ALPHABLENDENABLE, 1
        d3dev.SetRenderState D3DRS_SRCBLEND, D3DBLEND_SRCCOLOR
        d3dev.SetRenderState D3DRS_DESTBLEND, D3DBLEND_DESTCOLOR
        d3dev.SetRenderState D3DRS_BLENDOP, D3DBLENDOP_ADD
    d3dev.SetRenderState D3DRS_BLENDOP, D3DBLENDOP_ADD


    ' // Draw background
    d3dev.DrawPrimitive D3DPT_TRIANGLELIST, 6, 2 
    d3dev.SetTexture 0, Nothing
    d3dev.EndScene

    d3dev.Present ByVal 0, ByVal 0, 0, ByVal 0


Thanx in advance.

Ciao.
L.

----------


## leonbadman

Hi all, 

I need your help  :Smilie: 

My  problem: two textures; one for background (image from hd), the other one with a lot of text (with vertex), black background, and text color random.

I need to make transparent only the black background, not alpha the text (must be completly opaque)

This is my code:

    ' // Apply texture Background
    d3dev.SetTexture 0, texture
    d3dev.DrawPrimitive D3DPT_TRIANGLELIST, 0, 2

      ' // Remove texture
    d3dev.SetTexture 0, Nothing
    d3dev.SetTexture 0, textureText

        d3dev.SetRenderState D3DRS_ALPHABLENDENABLE, 1
        d3dev.SetRenderState D3DRS_SRCBLEND, D3DBLEND_SRCCOLOR
        d3dev.SetRenderState D3DRS_DESTBLEND, D3DBLEND_DESTCOLOR
        d3dev.SetRenderState D3DRS_BLENDOP, D3DBLENDOP_ADD
    d3dev.SetRenderState D3DRS_BLENDOP, D3DBLENDOP_ADD


    ' // Draw background
    d3dev.DrawPrimitive D3DPT_TRIANGLELIST, 6, 2 
    d3dev.SetTexture 0, Nothing
    d3dev.EndScene

    d3dev.Present ByVal 0, ByVal 0, 0, ByVal 0


Thanx in advance.

Ciao.
L.

----------


## The trick

Use additive blending (see Fire example demo).

----------


## leonbadman

> Use additive blending (see Fire example demo).


Hi Trick, first of all thank you (sorry for delay).

I saw the fire example, but maybe isn't what i'm looking for. My problem is that the second texture (the one with the text only) must be opaque (with black background completly transparent):

- texture 0: a random image from file
- texture 1: opaque text (background is black)

Is possibile? 

PS: As you can see, I'm not an expert of DirectX  :Big Grin: 

Thank you again.

Ciao.
L.

----------


## The trick

Hi leonbadman, just think about it as about the additional blending like in the fire demo. When you have a pixel with the zero color then during blending it won't affect to the result color because ANYCOLOR + BLACK (0) = ANYCOLOR. Opposite, when you have white color (1) it will replace the result color to white (ANYCOLOR + 1 > 1).

----------


## reexre

hello this seems to me the best starting point to create a 3d graphic engine for "games".
What I noticed in the examples is that necessary code in my opinion is a little too low level.
I'd like to have higher-level classes / functions such as in TrueVision3D.
Do you think it would be a good idea to build these higher level classes? (in a sense simplified and more intuitive to use)
anyone interested?
These classes could be for example:
 SCENE CAMERA MATERIAL OBJECT MESH TEXTURE LIGHT GROUND SKY HELPER-Math such as VECTOR MATRIX QUATERNION TEXT, "SPRITES", 2D shapes,  .... MORE

What do you think? Is it an absurd idea?
What difficulties would be encountered?
What would be the pros and cons?

----------


## Elroy

Hi Reexre,

In the project on which I'm currently working, I've got clsDxScene, clsDxMesh, & clsDxCamera.  I haven't messed with texturing, and I typically just deal with lighting and ground in the clsDxScene class.  I also haven't done anything with the 2D stuff ... well, it's been a while, and it was back when I was still using DX8.

I'm not sure I'd know the difference between Mesh and Object, nor the difference between Texture and Material.

Also, The Trick's work was/is always my starting place with DX9, but I've reworked all his math procedures into functions.  They're just more intuitive to me that way, so I'm not starting from exactly the same place as everyone else.

But, I certainly think it's a good idea, possibly a VB6 DLL with its own set of classes and calls.

Take Care,
Elroy

----------


## reexre

> In the project on which I'm currently working, I've got clsDxScene, clsDxMesh, & clsDxCamera.  I haven't messed with texturing, and I typically just deal with lighting and ground in the clsDxScene class.  I also haven't done anything with the 2D stuff ... well, it's been a while, and it was back when I was still using DX8.


Wow very interesting! Do you plan on sharing this code at some point?




> I'm not sure I'd know the difference between Mesh and Object, nor the difference between Texture and Material.


About Object I think I was wrong... Yes it should be the same.
About Textutre and Material I would differentiate them like this:
Material is what concerns color and the relationship with light such as reflection etc.
Texture is a kind of image applied to a surface.
but, yes in fact they can also be considered as a single aspect. (of a surface / mesh)




> Also, The Trick's work was/is always my starting place with DX9, but I've reworked all his math procedures into functions.  They're just more intuitive to me that way, so I'm not starting from exactly the same place as everyone else.


Agree and understand




> But, I certainly think it's a good idea, possibly a VB6 DLL with its own set of classes and calls.


Yes, I too had thought of a DLL.

Well, then if you want to share the code it would be fantastic, and maybe somehow me and others could contribute to it.

EDIT:
Here's what I thought about OBJECT.
By OBJECT I meant a hierarchical set of meshes. (Parent / child)
Which could have characteristics related to the other such as pivot point and rotation.

----------


## Elroy

> Here's what I thought about OBJECT.
> By OBJECT I meant a hierarchical set of meshes. (Parent / child)
> Which could have characteristics related to the other such as pivot point and rotation.


Yeah, after I posted, I had a similar though.  An "Object" might be a way to group individual mesh pieces.  And then, they could possibly be moved and rotated as a unit.

And yeah, I see the distinction between Texture and Material.

I'm still deciding about when/whether I'm going to share the code to this latest project.  However, here is another project that has pretty much all of the same features.

----------


## reexre

> ..... However, here is another project that has pretty much all of the same features.


Wow huge work!
So I begin creating the engine using it.
I opened a new thread about this

----------


## The trick

*UPDATE:*

Added d3dxvb.tlb library;Added CornerPin demo;Added Raymarching demo.

----------


## baka

I tried CornerPin.
if I start the project in IDE, I see the picture, but when I click on any of the "dots" the picture disappears.
when I compile it and run the EXE, it works.

Im now in windows 10. maybe thats the reason?

----------


## The trick

> I tried CornerPin.
> if I start the project in IDE, I see the picture, but when I click on any of the "dots" the picture disappears.
> when I compile it and run the EXE, it works.
> 
> Im now in windows 10. maybe thats the reason?


Are the points changed when you move the mouse over them (they should appear filled)?

----------


## baka

yeah, the points works, I can move them around. but the picture itself is not shown at all.
only at start I see picture, once I start moving the dots, the picture disappears and never returns.
but, if I compile and run .exe it works.

----------


## gaouser

@the trick can you add a import .obj or .x demo

----------


## gaouser

hi the trick can you add a example fot loading,resizing,moving,rotating .x or .obj in dx9vb

----------


## gaouser

how to load obj with it

----------


## The trick

> how to load obj with it


You need to parse your file to a set of vertices. Create a vertex buffer and put them into it. Optionally create an index buffer and use it to refer to vertex buffer.

----------

