Great contribution Sephnroth!
With that little help, I converted easily, and succesfully :
- d3d_line (it's faster!, try your BBC example below
)
- d3d_box
- d3d_boxAlpha
- d3d_line3D
Now, I still need help with:
- d3d_dot3D : it compiles, but I can see nothing when running.
- d3d_text3D : does not compile
- d3d_MakePyramid : does not compile
I think that we should try to convert them, at least dot3d and text3d, and post the whole thing into your "Text extension, Image extension, Primitives Extension" thread.
d3dfunc.cpp:
#include "DarkSDK.h"
#include "d3d9.h"
//for 2d functions
#define D3D_FVF_2D_VERTEX (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)
struct TransformedVertex // D3D_FVF_2D_VERTEX
{
float x, y, z, w; // Position of vertex in 3D space
DWORD color; // Color of vertex
};
//for 3d functions
#define D3DFVF_MY_VERTEX ( D3DFVF_XYZ | D3DFVF_DIFFUSE )
struct Vertex // D3DFVF_MY_VERTEX
{
float x, y, z; // Position of vertex in 3D space
DWORD color; // Color of vertex
};
//for MakePyramid
#define D3DFVF_DBPMESH (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1)
IDirect3DDevice9* g_pd3dDevice = NULL;
// ONLY NEEDED FOR ALPHA BOX
LPDIRECT3DVERTEXBUFFER9 g_pTriangleStrip_VB = NULL;
// ONLY NEEDED FOR TEXT3D
ID3DXMesh* g_pMesh3DText = NULL;
// ONLY NEEDED FOR 3D FUNCTIONS
D3DVIEWPORT9 g_pViewPort;
void InitD3DFunc() {
g_pd3dDevice = dbGetDirect3DDevice();
// Pre Create Vertex buffer for drawing an alpha enabled 2d box
// ONLY NEEDED FOR ALPHA BOX
g_pd3dDevice->CreateVertexBuffer( 4*sizeof(TransformedVertex), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFVF_XYZRHW | D3DFVF_DIFFUSE,
D3DPOOL_DEFAULT, &g_pTriangleStrip_VB,
NULL );
// Get default viewport (FULLSCREEN SIZE). This means you only need to call
// Set View command from DBP if you change the screen size
// FOR 3D FUNCTIONS
g_pd3dDevice->GetViewport( &g_pViewPort );
}
void d3d_dot (int x1,int y1, int r, int g, int b, int a) {
TransformedVertex *pVertices = NULL;
TransformedVertex g_lineList[] =
{
{-1.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_ARGB( 255, 255, 0, 255 ) }, // Line #1
};
g_lineList[0].x=(float)x1;
g_lineList[0].y=(float)y1;
g_lineList[0].z=1.0f;
g_lineList[0].color=D3DCOLOR_ARGB( a, r, g, b );
g_pd3dDevice->SetTexture(0,NULL);
g_pd3dDevice->SetTexture(1,NULL);
g_pd3dDevice->SetVertexShader(NULL);
g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
g_pd3dDevice->SetFVF( D3D_FVF_2D_VERTEX );
g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
g_pd3dDevice->DrawPrimitiveUP(D3DPT_POINTLIST,1,g_lineList,sizeof(TransformedVertex));
}
void d3d_line (int x1,int y1,int x2,int y2, int g_nRed, int g_nGreen, int g_nBlue, int g_nAlpha)
{
TransformedVertex *pVertices = NULL;
TransformedVertex g_lineList[] =
{
{-1.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_ARGB( 255, 255, 0, 255 ) }, // Line #1
{-1.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_ARGB( 255, 255, 0, 255 ) }, // Line #1
};
g_lineList[0].x=(float)x1;
g_lineList[0].y=(float)y1;
g_lineList[0].z=1.0f;
g_lineList[0].color=D3DCOLOR_ARGB( g_nAlpha, g_nRed, g_nGreen, g_nBlue );
g_lineList[1].x=(float)x2;
g_lineList[1].y=(float)y2;
g_lineList[1].z=1.0f;
g_lineList[1].color=D3DCOLOR_ARGB( g_nAlpha, g_nRed, g_nGreen, g_nBlue );
g_pd3dDevice->SetTexture(0,NULL);
g_pd3dDevice->SetTexture(1,NULL);
g_pd3dDevice->SetVertexShader(NULL);
g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
g_pd3dDevice->SetFVF( D3D_FVF_2D_VERTEX );
g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
g_pd3dDevice->DrawPrimitiveUP(D3DPT_LINELIST,1,g_lineList,sizeof(TransformedVertex));
}
void d3d_box ( int x1, int y1, int x2, int y2 , int g_nRed, int g_nGreen, int g_nBlue, int g_nAlpha)
{
D3DRECT pRect;
pRect.x1=x1;
pRect.y1=y1;
pRect.x2=x2;
pRect.y2=y2;
g_pd3dDevice->SetTexture(0,NULL);
g_pd3dDevice->SetTexture(1,NULL);
g_pd3dDevice->SetVertexShader(NULL);
g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
g_pd3dDevice->Clear(1,&pRect,D3DCLEAR_TARGET,D3DCOLOR_ARGB( g_nAlpha, g_nRed, g_nGreen, g_nBlue ),1.0f,0);
}
void d3d_boxAlpha ( int x1, int y1, int x2, int y2 , int g_nRed, int g_nGreen, int g_nBlue, int g_nAlpha)
{
TransformedVertex *pVertices = NULL;
TransformedVertex g_triangleStrip[] =
{
{-1.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_ARGB( 255, 255, 0, 255 ) }, // Line #1
{-1.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_ARGB( 255, 255, 0, 255 ) }, // Line #1
{-1.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_ARGB( 255, 255, 0, 255 ) }, // Line #1
{-1.0f, 0.0f, 0.0f, 1.0f, D3DCOLOR_ARGB( 255, 255, 0, 255 ) }, // Line #1
};
g_triangleStrip[0].x=(float)x1;
g_triangleStrip[0].y=(float)y1;
g_triangleStrip[0].z=1.0f;
g_triangleStrip[0].color=D3DCOLOR_ARGB( g_nAlpha, g_nRed, g_nGreen, g_nBlue );
g_triangleStrip[1].x=(float)x2;
g_triangleStrip[1].y=(float)y1;
g_triangleStrip[1].z=1.0f;
g_triangleStrip[1].color=D3DCOLOR_ARGB( g_nAlpha, g_nRed, g_nGreen, g_nBlue );
g_triangleStrip[2].x=(float)x1;
g_triangleStrip[2].y=(float)y2;
g_triangleStrip[2].z=1.0f;
g_triangleStrip[2].color=D3DCOLOR_ARGB( g_nAlpha, g_nRed, g_nGreen, g_nBlue );
g_triangleStrip[3].x=(float)x2;
g_triangleStrip[3].y=(float)y2;
g_triangleStrip[3].z=1.0f;
g_triangleStrip[3].color=D3DCOLOR_ARGB( g_nAlpha, g_nRed, g_nGreen, g_nBlue );
g_pd3dDevice->SetTexture(0,NULL);
g_pd3dDevice->SetTexture(1,NULL);
g_pd3dDevice->SetVertexShader(NULL);
g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_FALSE);
pVertices = NULL;
g_pTriangleStrip_VB->Lock( 0, sizeof(g_triangleStrip), (void**)&pVertices, D3DLOCK_DISCARD );
memcpy( pVertices, g_triangleStrip, sizeof(g_triangleStrip) );
g_pTriangleStrip_VB->Unlock();
g_pd3dDevice->SetStreamSource( 0, g_pTriangleStrip_VB, 0, sizeof(TransformedVertex) );
g_pd3dDevice->SetFVF( D3D_FVF_2D_VERTEX );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );
// g_pd3dDevice->Clear(1,&pRect,D3DCLEAR_TARGET,D3DCOLOR_ARGB( g_nAlpha, g_nRed, g_nGreen, g_nBlue ),1.0f,0);
}
/*
void d3d_text3D(int iID, int nFont, LPSTR pString, FLOAT nDepth, int nPrecision,int nAlign)
{
HRESULT hr;
hr=CreateD3DXTextMesh( g_pd3dDevice, nFont, &g_pMesh3DText, pString, nDepth ,nPrecision, nAlign);
if (hr==FALSE)
{
return;
}
MakeObjectFromDXMesh (iID,g_pMesh3DText);
}
//NEEDED FOR TEXT3D
HRESULT CreateD3DXTextMesh( IDirect3DDevice9* pd3dDevice, int nFont, LPD3DXMESH* ppMesh, TCHAR* pString, FLOAT nSize, int nPrecision, int nAlign)
{
HRESULT hr;
ID3DXMesh *pMeshNew = NULL;
HDC hdc = CreateCompatibleDC( NULL );
HFONT hFont;
HFONT hFontOld;
FLOAT fPrecision;
D3DXVECTOR3 minBounds,maxBounds,sum;
BYTE* pVertices=NULL;
DWORD nVertices;
DWORD nVertSize;
ID3DXMesh *pMesh=NULL;
switch (nPrecision)
{
case 0:
{
fPrecision=0.1f;
break;
}
case 1:
{
fPrecision=0.01f;
break;
}
case 2:
{
fPrecision=0.001f;
break;
}
}
hFont = CreateFont(g_nFontSize, 0, 0, 0, g_Bold ? FW_BOLD : FW_NORMAL, g_Italic ? TRUE : FALSE, FALSE, FALSE, DEFAULT_CHARSET,
OUT_TT_ONLY_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, aFont[nFont].sFont);
hFontOld = (HFONT)SelectObject(hdc, hFont);
hr = D3DXCreateText( pd3dDevice, hdc, pString,
fPrecision, nSize, &pMeshNew, NULL, NULL);
if (FAILED(hr))
return FALSE;
hr=pMeshNew->LockVertexBuffer(D3DUSAGE_DYNAMIC, (LPVOID*)&pVertices);
if (FAILED(hr))
return FALSE;
D3DXComputeBoundingBox((D3DXVECTOR3*)pVertices, pMeshNew->GetNumVertices(), D3DXGetFVFVertexSize(pMeshNew->GetFVF()), &minBounds, &maxBounds);
maxBounds.x=maxBounds.x*1;
maxBounds.y=maxBounds.y*1;
nVertices=pMeshNew->GetNumVertices();
nVertSize=D3DXGetFVFVertexSize(pMeshNew->GetFVF());
if ( nAlign<0 || nAlign>3)
nAlign=1;
switch (nAlign)
{
case 0:
{
for(DWORD i=0; i < nVertices; i++)
{
D3DXVECTOR3 p = *(D3DXVECTOR3*)(pVertices + i*nVertSize);
p.x=(p.x*1)-minBounds.x;
p.y=(p.y*1)-(maxBounds.y-minBounds.y)/2;
p.z=p.z+(maxBounds.z-minBounds.z)/2;
memcpy(pVertices + i*nVertSize,&p,sizeof(p));
}
break;
}
case 1:
{
for(DWORD i=0; i < nVertices; i++)
{
D3DXVECTOR3 p = *(D3DXVECTOR3*)(pVertices + i*nVertSize);
p.x=(p.x*1)-minBounds.x-(maxBounds.x-minBounds.x)/2;
p.y=(p.y*1)-(maxBounds.y-minBounds.y)/2;
p.z=p.z+(maxBounds.z-minBounds.z)/2;
memcpy(pVertices + i*nVertSize,&p,sizeof(p));
}
break;
}
case 2:
{
for(DWORD i=0; i < nVertices; i++)
{
D3DXVECTOR3 p = *(D3DXVECTOR3*)(pVertices + i*nVertSize);
p.x=(p.x*1)-maxBounds.x;
p.y=(p.y*1)-(maxBounds.y-minBounds.y)/2;
p.z=p.z+(maxBounds.z-minBounds.z)/2;
memcpy(pVertices + i*nVertSize,&p,sizeof(p));
}
break;
}
case 3:
{
for(DWORD i=0; i < nVertices; i++)
{
D3DXVECTOR3 p = *(D3DXVECTOR3*)(pVertices + i*nVertSize);
p.x=(p.x*1)-minBounds.x;
p.z=p.z+(maxBounds.z-minBounds.z)/2;
memcpy(pVertices + i*nVertSize,&p,sizeof(p));
}
break;
}
}
pMeshNew->UnlockVertexBuffer();
SelectObject(hdc, hFontOld);
DeleteObject( hFont );
DeleteDC( hdc );
hr=pMeshNew->CloneMeshFVF(D3DXMESH_MANAGED, //Options, see the SDK docs
D3DFVF_DBPMESH, //The FVF we want our new mesh to have
pd3dDevice,//Our D3D Device
&pMesh);
if( SUCCEEDED( hr ) )
{
*ppMesh = pMesh;
pMeshNew->Release();
}
return TRUE;
}
*/
//NEEDED FOR 3DTEXT & MAKEPIRAMID
/*
void MakeObjectFromDXMesh ( int iID,ID3DXMesh *ppMesh )
{
HRESULT hr;
int iFinalMeshCount = 1;
int iMesh = 0;
sObject* pObject = NULL;
sMesh* pMesh = NULL; // temporary mesh pointer
sFrame* pFrame = NULL; // temporary frame pointer
sMesh** ppMeshListFromObject = NULL; // mesh list array
DWORD dwIndexCount = 0; // index count
DWORD dwVertexCount = 0; // vertex count
BYTE* pVertices =NULL;
DWORD nVertSize;
LPDIRECT3DINDEXBUFFER9 pMeshIndexBuffer;
short *pIndices;
g_CreateNewObjectEx ( iID, "3DText", iFinalMeshCount );
pObject = g_GetObjectData ( iID );
if ( !pObject )
{
// error
}
// now get a pointer to the first mesh and first frame, finally
// create a temporary mesh list so we can access by array and not
// through the child structure, we can't use the object mesh list
// at this stage because it hasn't been created yet
pMesh = pObject->pFrame->pMesh;
pFrame = pObject->pFrame;
ppMeshListFromObject = new sMesh* [ iFinalMeshCount ];
if ( !ppMeshListFromObject )
{
// error
}
// store pointers to meshes in the mesh list
for ( iMesh = 0; iMesh < iFinalMeshCount; iMesh++ )
{
// store mesh pointer
ppMeshListFromObject [ iMesh ] = pMesh;
// move temporary pointers to child frames
if ( pFrame->pChild )
{
pFrame = pFrame->pChild;
pMesh = pFrame->pMesh;
}
}
// go through all meshes in list
for ( iMesh = 0; iMesh < iFinalMeshCount; iMesh++ )
{
// get index and vertex count of the block
dwIndexCount=ppMesh->GetNumFaces() * 3;
dwVertexCount = ppMesh->GetNumVertices();
// set up the new mesh
g_SetupMeshFVFData ( ppMeshListFromObject [ iMesh ], D3DFVF_DBPMESH, dwVertexCount, dwIndexCount );
sVertex* pVertex = ( sVertex* ) ppMeshListFromObject [ iMesh ]->pVertexData;
hr=ppMesh->LockVertexBuffer(D3DLOCK_READONLY, (LPVOID*)&pVertices);
nVertSize=D3DXGetFVFVertexSize(ppMesh->GetFVF());
//Get pointer to Index buffer and lock the index buffer in prder to access it
ppMesh->GetIndexBuffer(&pMeshIndexBuffer);
pMeshIndexBuffer->Lock(0, 3 * ppMesh->GetNumFaces() * sizeof(short), (void **)&pIndices, D3DLOCK_READONLY);
// copy vertices from block into our new mesh
for ( int iVertex = 0; iVertex < (int)dwVertexCount; iVertex++ )
{
sVertex p = *(sVertex*)(pVertices + iVertex*nVertSize);
pVertex [ iVertex ].x = p.x;
pVertex [ iVertex ].y = p.y;
pVertex [ iVertex ].z = p.z;
pVertex [ iVertex ].nx = p.nx;
pVertex [ iVertex ].ny = p.ny;
pVertex [ iVertex ].nz = p.nz;
pVertex [ iVertex ].tu = p.tu;
pVertex [ iVertex ].tv = p.tv;
}
ppMesh->UnlockVertexBuffer();
// copy indices from block into mesh
for ( int iIndex = 0; iIndex < (int)dwIndexCount; iIndex++ )
ppMeshListFromObject [ iMesh ]->pIndices [ iIndex ] = pIndices[iIndex];
pMeshIndexBuffer->Unlock();
// set up mesh properties, no lights as we use diffuse, triangle list for primitive type, store
// the vertex count and finally the primitive count
ppMeshListFromObject [ iMesh ]->bLight = true;
ppMeshListFromObject [ iMesh ]->iPrimitiveType = D3DPT_TRIANGLELIST;
ppMeshListFromObject [ iMesh ]->iDrawVertexCount = ppMeshListFromObject [ iMesh ]->dwVertexCount;
ppMeshListFromObject [ iMesh ]->iDrawPrimitives = ppMesh->GetNumFaces ( );
ppMeshListFromObject [ iMesh ]->iMeshType = 1;
// calculate the mesh bounds
g_CalculateMeshBounds ( ppMeshListFromObject [ iMesh ] );
}
// set the final properties of the object and apply a blank texture
g_SetNewObjectFinalProperties ( iID, 0.0f );
g_SetTexture ( iID, 0 );
// safely delete the temporary mesh list
SAFE_DELETE_ARRAY ( ppMeshListFromObject );
SAFE_RELEASE ( ppMesh );
}
*/
void d3d_line3D ( float x1, float y1, float z1, float x2, float y2, float z2, int nZenable, int g_nRed, int g_nGreen, int g_nBlue, int g_nAlpha)
{
Vertex *pVertices = NULL;
Vertex g_lineList[] =
{
{-1.0f, 0.0f, 0.0f, D3DCOLOR_ARGB( 255, 0, 0, 255 ) }, // Line #1
{-1.0f, 0.0f, 0.0f, D3DCOLOR_ARGB( 255, 0, 0, 255 ) }, // Line #1
};
g_lineList[0].x=x1;
g_lineList[0].y=y1;
g_lineList[0].z=z1;
g_lineList[0].color=D3DCOLOR_ARGB( g_nAlpha, g_nRed, g_nGreen, g_nBlue );
g_lineList[1].x=x2;
g_lineList[1].y=y2;
g_lineList[1].z=z2;
g_lineList[1].color=D3DCOLOR_ARGB( g_nAlpha, g_nRed, g_nGreen, g_nBlue );
//Translate the line into the current world space
D3DXMATRIX matWorld;
D3DXMatrixIdentity( &matWorld );
g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
g_pd3dDevice->SetTexture(0,NULL);
g_pd3dDevice->SetTexture(1,NULL);
g_pd3dDevice->SetVertexShader(NULL);
g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_ARGB( g_nAlpha, g_nRed, g_nGreen, g_nBlue ) );
g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, nZenable );
// g_pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, nZenable );
// g_pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS);
g_pd3dDevice->SetViewport( &g_pViewPort );
g_pd3dDevice->SetFVF( D3DFVF_MY_VERTEX );
g_pd3dDevice->DrawPrimitiveUP(D3DPT_LINELIST,1,g_lineList,sizeof(Vertex));
g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0 );
}
void d3d_dot3D ( float x1, float y1, float z1, int nZenable, int g_nRed, int g_nGreen, int g_nBlue, int g_nAlpha)
{
// LPDIRECT3DVERTEXBUFFER9 g_pLineList_VB = NULL;
Vertex *pVertices = NULL;
Vertex g_pointList[] =
{
{-1.0f, 0.0f, 0.0f, D3DCOLOR_ARGB( 255, 0, 0, 255 ) }, // Line #1
};
g_pointList[0].x=x1;
g_pointList[0].y=y1;
g_pointList[0].z=z1;
g_pointList[0].color=D3DCOLOR_ARGB( g_nAlpha, g_nRed, g_nGreen, g_nBlue );
D3DXMATRIX matWorld;
D3DXMatrixIdentity( &matWorld );
g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
g_pd3dDevice->SetTexture(0,NULL);
g_pd3dDevice->SetTexture(1,NULL);
g_pd3dDevice->SetVertexShader(NULL);
g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_ARGB( g_nAlpha, g_nRed, g_nGreen, g_nBlue ) );
g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, nZenable );
g_pd3dDevice->SetViewport( &g_pViewPort );
g_pd3dDevice->SetFVF( D3DFVF_MY_VERTEX );
g_pd3dDevice->DrawPrimitiveUP(D3DPT_POINTLIST,1,g_pointList,sizeof(Vertex));
g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0 );
}
/*
void d3d_MakePyramid( int iID, float x, float y, float z)
{
struct sVertex // D3DFVF_DBPMESH
{
float x, y, z;
float nx, ny, nz;
float tu, tv;
};
sVertex VertexList[] =
{
{ -0.5, -0.5, 0.5, 0.000000, 0.447214, 0.894427, 0.0, 1.0 },
{ 0.5, -0.5, 0.5, 0.000000, 0.447214, 0.894427, 1.0, 1.0 },
{ 0.0, 0.5, 0.0, 0.000000, 0.447214, 0.894427, 0.5, 0.0 },
{ 0.5, -0.5, 0.5, 0.894427, 0.447214, 0.000000, 0.0, 1.0 },
{ 0.5, -0.5,-0.5, 0.894427, 0.447214, 0.000000, 1.0, 1.0 },
{ 0.0, 0.5, 0.0, 0.894427, 0.447214, 0.000000, 0.5, 0.0 },
{ 0.5, -0.5,-0.5, 0.000000, 0.447214, -0.894427, 1.0, 1.0 },
{ -0.5, -0.5,-0.5, 0.000000, 0.447214, -0.894427, 0.0, 1.0 },
{ 0.0, 0.5, 0.0, 0.000000, 0.447214, -0.894427, 0.5, 0.0 },
{ -0.5, -0.5,-0.5, -0.894427, 0.447214, 0.000000, 1.0, 1.0 },
{ -0.5, -0.5, 0.5, -0.894427, 0.447214, 0.000000, 0.0, 1.0 },
{ 0.0, 0.5, 0.0, -0.894427, 0.447214, 0.000000, 0.5, 0.0 },
{ -0.5, -0.5, 0.5, 0.000000, -1.000000, 0.000000, 0.0, 1.0 },
{ -0.5, -0.5,-0.5, 0.000000, -1.000000, 0.000000, 0.0, 0.0 },
{ 0.5, -0.5, 0.5, 0.000000, -1.000000, 0.000000, 1.0, 1.0 },
{ -0.5, -0.5,-0.5, 0.000000, -1.000000, 0.000000, 0.0, 0.0 },
{ 0.5, -0.5,-0.5, 0.000000, -1.000000, 0.000000, 1.0, 0.0 },
{ 0.5, -0.5, 0.5, 0.000000, -1.000000, 0.000000, 1.0, 1.0 },
};
short IndexList[] =
{
{ 0 },
{ 1 },
{ 2 },
{ 3 },
{ 4 },
{ 5 },
{ 6 },
{ 7 },
{ 8 },
{ 9 },
{ 10 },
{ 11 },
{ 12 },
{ 13 },
{ 14 },
{ 15 },
{ 16 },
{ 17 },
};
sVertex *pVertices = NULL;
LPDIRECT3DVERTEXBUFFER9 pVertexList = NULL;
LPDIRECT3DINDEXBUFFER9 pIndexBuffer = NULL;
ID3DXMesh *pMeshNew = NULL;
DWORD nVertices;
DWORD nVertSize;
short *pIndices = NULL;
int i;
for ( i=0; i<18; i++)
{
VertexList[i].x=VertexList[i].x * x;
VertexList[i].y=VertexList[i].y * y;
VertexList[i].z=VertexList[i].z * z;
}
HRESULT res = D3DXCreateMeshFVF(6, 18, D3DXMESH_MANAGED , D3DFVF_DBPMESH, g_pd3dDevice, &pMeshNew);
nVertices=pMeshNew->GetNumVertices();
nVertSize=D3DXGetFVFVertexSize(pMeshNew->GetFVF());
res=pMeshNew->LockVertexBuffer(D3DUSAGE_DYNAMIC, (LPVOID*)&pVertices);
memcpy( pVertices, VertexList, sizeof(VertexList) );
pMeshNew->UnlockVertexBuffer();
res=pMeshNew->LockIndexBuffer(D3DUSAGE_DYNAMIC, (LPVOID*)&pIndices);
memcpy( pIndices, IndexList, sizeof(IndexList) );
pMeshNew->UnlockIndexBuffer();
MakeObjectFromDXMesh (iID,pMeshNew);
}
*/
d3dfunc.h:
void InitD3DFunc();
void d3d_dot(int x1,int y1, int r, int g, int b, int a);
void d3d_line (int x1,int y1,int x2,int y2, int g_nRed, int g_nGreen, int g_nBlue, int g_nAlpha);
void d3d_box ( int x1, int y1, int x2, int y2 , int g_nRed, int g_nGreen, int g_nBlue, int g_nAlpha);
void d3d_boxAlpha ( int x1, int y1, int x2, int y2 , int g_nRed, int g_nGreen, int g_nBlue, int g_nAlpha);
/*
void d3d_text3D (int iID, int nFont, LPSTR pString, FLOAT nDepth, int nPrecision,int nAlign);
HRESULT CreateD3DXTextMesh ( IDirect3DDevice9* pd3dDevice, int nFont, LPD3DXMESH* ppMesh, TCHAR* pString, FLOAT nSize, int nPrecision, int nAlign );
void MakeObjectFromDXMesh (int iID,ID3DXMesh* ppMesh);
*/
void d3d_line3D ( float x1, float y1, float z1, float x2, float y2, float z2, int nZenable, int g_nRed, int g_nGreen, int g_nBlue, int g_nAlpha);
void d3d_dot3D ( float x1, float y1, float z1, int nZenable, int g_nRed, int g_nGreen, int g_nBlue, int g_nAlpha);
//void d3d_MakePyramid ( int iID, float x, float y, float z);
simple usage example (your BBC program, delete the remarks to try each function):
#include "DarkSDK.h"
#include "d3dfunc.h"
void draw_line(int xp, int yp, int xq, int yq, int r, int g, int b);
int dRand(int low, int high);
void DarkSDK(void) {
dbSyncOn();
dbSyncRate(0);
dbSetDisplayMode(800, 600, 32);
InitD3DFunc();
int d, k, j1, j2, i;
d = 4;
j1 = 0;
int r, g, b;
while (LoopSDK()) {
if (dbEscapeKey())
return;
for (k = 500; k >= 380; k -= 40) {
while (j2 == j1) {
j2 = dRand(0,3);
}
j1 = j2;
r = dRand(0,255);
g = dRand(0,255);
b = dRand(0,255);
for (i=-k; i<=k; i=i+d) {
//line method1
//draw_line(k+400,i+300,-k+400,-i+300, r, g, b);
//draw_line(i+400,-k+300,-i+400,k+300, r, g, b);
//line method2, seems faster
d3d_line (k+400,i+300,-k+400,-i+300, r, g, b, 255);
d3d_line (i+400,-k+300,-i+400,k+300, r, g, b, 255);
//box test
//d3d_box (k+400,i+300,-k+400,-i+300, r, g, b, 255);
//d3d_box (i+400,-k+300,-i+400,k+300, r, g, b, 255);
//boxAlpha test
//d3d_boxAlpha (k+400,i+300,-k+400,-i+300, r, g, b, 255);
//d3d_boxAlpha (i+400,-k+300,-i+400,k+300, r, g, b, 255);
//line3D test
//d3d_line3D (k+400,i+300,100,-k+400,-i+300,100, 1, r, g, b, 255);
//d3d_line3D (i+400,-k+300,100,-i+400,k+300,100, 1, r, g, b, 255);
//dot3d_test
//d3d_dot3D ( k+400,i+300,100, 1, r, g, b, 255);
//d3d_dot3D ( i+400,-k+300,100, 1, r, g, b, 255);
//still no luck, I cannot see them
//d3d_dot3D ( 400,300,100, 1, 255, 255, 255, 255);
//d3d_dot3D ( 450,350,100, 1, 255, 255, 255, 255);
dbSync();
if (dbEscapeKey())
return;
}
}
dbSetCursor(0,0);
dbPrint(dbStr(dbScreenFPS()));
dbSync();
}
}
void draw_line(int xp, int yp, int xq, int yq, int r, int g, int b) {
int u=0;
int dx,dy,c,M,xinc=1,yinc=1;
int x=xp;
int y=yp;
dx=xq-xp;
dy=yq-yp;
if(dx<0) { xinc=-1; dx=-dx; }
if(dy<0) { yinc=-1; dy=-dy; }
if(dy<dx) {
c=2*dx; M=2*dy;
while(x!=xq) {
d3d_dot(x, y, r, g, b, 255);
x+=xinc; u+=M;
if(u>dx) { y+=yinc; u-=c; }
}
} else {
c=2*dy; M=2*dx;
while(y!=yq) {
d3d_dot(x, y, r, g, b, 255);
y+=yinc; u+=M;
if(u>dy) { x+=xinc; u-=c; }
}
}
d3d_dot(xq, yq, r, g, b, 255);
}
int dRand(int low, int high) {
int r = low+rand()%(high-low+1);
return r;
}
Tell me what you think. Thanks for your help!