Well, check my algorithm for writing vertex and index data and they work as they should.
This is my current code:
bool CreateNewObject ( int iID, LPSTR pName, int iFrame );
sObject* dbGetObject ( int iID );
bool SetupMeshFVFData ( sMesh* pMesh, DWORD dwFVF, DWORD dwVertexCount, DWORD dwIndexCount );
bool SetupStandardVertex ( DWORD dwFVF, BYTE* pVertex, int iOffset, float x, float y, float z, float nx, float ny, float nz, DWORD dwDiffuseColour, float tu, float tv );
bool SetNewObjectFinalProperties ( int iID, float fRadius );
void SetTexture ( int iID, int iImage );
void n0_CreateNewObject( int obj, int noVer, int noInd, n0_simpleVertex verList[] , int indList[] )
{
CreateNewObject( obj , "" , 1 );
sObject* pObject = dbGetObject( obj );
sMesh* pMesh = pObject->pFrame->pMesh;
SetupMeshFVFData( pMesh , D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1, noVer , noInd);
for(int x=0; x < noVer + 1; x++)
{// Index
SetupStandardVertex ( pMesh->dwFVF , pMesh->pVertexData , x , verList[x].x , verList[x].y , verList[x].z , 0.0f , 0.0f , -1.0f , 0 , 0.0f , 0.0f );
}
// Skriver index-data
for(int x=0; x < noInd + 1; x++)
{
pMesh->pIndices[x] = indList[x];
}
pMesh->iPrimitiveType = D3DPT_TRIANGLELIST;
pMesh->iDrawVertexCount = noVer;
// pMesh->dwIndexCount = noInd;
pMesh->iDrawPrimitives = 1; // 24; //pMesh->dwIndexCount / 3;
SetNewObjectFinalProperties( obj , 0.0f );
SetTexture( obj , 0 );
}
/* Prototyper for DirectX Hooking */
IDirect3D9* dbGetDirect3D ( void );
IDirect3DDevice9* dbGetDirect3DDevice( void );
void DarkGDK ( void )
{
/*
n0_simpleVertex vArray[4];
int iArray[6];
vArray[1].x = 0; vArray[0].y = 0; vArray[0].z = 0;
vArray[2].x = 50; vArray[1].y = 50; vArray[1].z = 0;
vArray[3].x = 50; vArray[2].y = 0; vArray[2].z = 0;
vArray[4].x = 0; vArray[3].y = 50; vArray[3].z = 0;
iArray[1] = 1;
iArray[2] = 2;
iArray[3] = 4;
iArray[4] = 2;
iArray[5] = 3;
iArray[6] = 1;
n0_CreateNewObject( 1, 4, 6, vArray , iArray );
dbSetObjectCull( 1 , 0 );
*/
/*
FUNKER IKKE
Ser ut til at det er en feil i index-data algo'en.
*/
const int kol = 4;
const int rad = 3;
int square = 128;
const int vArraySize = (kol + 1) * (rad + 1);
const int iArraySize = kol * rad * 6;
n0_simpleVertex vertexArray[vArraySize];
int indexArray[iArraySize];
// Loop for å fylle inn vertex-arrayen
int teller = 0;
for(int d = 0; d < kol + 1; ++d)
{
for(int a = 0; a < rad + 1; ++a)
{
// Fylle inn vertex-array
vertexArray[teller].x = d * square;
vertexArray[teller].y = 0;
vertexArray[teller].z = a * square;
++teller;
}
}
// Loop for å fylle inn index-arrayen
teller = 0;
for(int j = 0; j < kol; ++j)
{
for(int r = 0; r < rad; ++r)
{
// Fylle inn index-array
indexArray[teller] = 1 + r + j * 4;
++teller;
indexArray[teller] = 5 + r + j * 4;
++teller;
indexArray[teller] = 4 + r + j * 4;
++teller;
indexArray[teller] = 1 + r + j * 4;
++teller;
indexArray[teller] = r + (j + 1) * 4;
++teller;
indexArray[teller] = r + j * 4;
++teller;
}
}
for(teller = 0; teller < iArraySize; ++teller)
{
dbPrint(dbStr(indexArray[teller]));
}
dbWaitKey();
n0_CreateNewObject( 1, vArraySize, iArraySize, vertexArray , indexArray );
dbSetObjectCull( 1 , 0 );
IDirect3D9* test = dbGetDirect3D();
IDirect3DDevice9* devtest = dbGetDirect3DDevice();
while ( LoopGDK ( ) )
{
dbPointCamera( dbObjectPositionX( 1 ) , dbObjectPositionY( 1 ) , dbObjectPositionZ( 1 ) );
if(dbUpKey()){dbMoveCamera(0.5f);}
if(dbDownKey()){dbMoveCamera(-.5f);}
dbSync ( );
}
return;
}
But it wouldn't render anything else then me debug output >.<
EDIT:
Now the code have started to return an error about mem_alloc
#include "DarkGDK.h"
#include "windows.h"
#include "globstruct.h"
/* Header fil med alle n0Life strukturene */
#include "n0types.h"
/* Prototyper for å lage egene vertices */
bool CreateNewObject ( int iID, LPSTR pName, int iFrame );
sObject* dbGetObject ( int iID );
bool SetupMeshFVFData ( sMesh* pMesh, DWORD dwFVF, DWORD dwVertexCount, DWORD dwIndexCount );
bool SetupStandardVertex ( DWORD dwFVF, BYTE* pVertex, int iOffset, float x, float y, float z, float nx, float ny, float nz, DWORD dwDiffuseColour, float tu, float tv );
bool SetNewObjectFinalProperties ( int iID, float fRadius );
void SetTexture ( int iID, int iImage );
/*
n0_CreateNewObject
int obj - Objekt nummer
int noVer - Antall vertices
int noInd - Antall indekser
n0_simpleVertex verList[] - Array med alle vertex data
int indList[] - Array med alle index data
*/
/*
void n0_CreateNewObject( int obj, int noVer, int noInd, n0_simpleVertex verList[] , int indList[] )
{
CreateNewObject( obj , "" , 1 );
sObject* pObject = dbGetObject( obj );
sMesh* pMesh = pObject->pFrame->pMesh;
SetupMeshFVFData( pMesh , D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1, noVer , noInd);
for(int x=0; x < noVer + 1; x++)
{// Index
SetupStandardVertex ( pMesh->dwFVF , pMesh->pVertexData , x , verList[x].x , verList[x].y , verList[x].z , 0.0f , 0.0f , -1.0f , 0 , 0.0f , 0.0f );
}
// Skriver index-data
for(int x=0; x < noInd + 1; x++)
{
pMesh->pIndices[x] = indList[x];
}
pMesh->iPrimitiveType = D3DPT_TRIANGLELIST;
pMesh->iDrawVertexCount = noVer;
// pMesh->dwIndexCount = noInd;
pMesh->iDrawPrimitives = 1; // 24; //pMesh->dwIndexCount / 3;
SetNewObjectFinalProperties( obj , 0.0f );
SetTexture( obj , 0 );
}*/
void n0_CreateNewObject( int obj, int noVer, int noInd, n0_simpleVertex verList[] , int indList[] )
{
CreateNewObject( obj , "" , 1 );
sObject* pObject = dbGetObject( obj );
sMesh* pMesh = pObject->pFrame->pMesh;
SetupMeshFVFData( pMesh , D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1, noVer , noInd);
for(int x=0; x < noVer + 1; x++)
{// Index
SetupStandardVertex ( pMesh->dwFVF , pMesh->pVertexData , x , verList[x].x , verList[x].y , verList[x].z , 0.0f , 0.0f , -1.0f , 0 , 0.0f , 0.0f );
}
// Skriver index-data
for(int x=0; x < noInd + 1; x++)
{
pMesh->pIndices[x] = indList[x];
}
pMesh->iPrimitiveType = D3DPT_TRIANGLELIST;
pMesh->iDrawVertexCount = noVer;
// pMesh->dwIndexCount = noInd;
pMesh->iDrawPrimitives = 1; // 24; //pMesh->dwIndexCount / 3;
SetNewObjectFinalProperties( obj , 0.0f );
SetTexture( obj , 0 );
}
/* Prototyper for DirectX Hooking */
IDirect3D9* dbGetDirect3D ( void );
IDirect3DDevice9* dbGetDirect3DDevice( void );
void DarkGDK ( void )
{
//dbSyncOn ( );
// dbSyncRate ( 60 );
//dbSetDisplayMode(1248,1024,32)
HWND window = GetActiveWindow();
/* Meny - Not working , need to add items I think and fix the DirectX */
HMENU menu = CreateMenu();
SetMenu(window,menu);
/* Test button
Fungerer, men vises ikke pga DirectX overskrider den
HWND button = CreateWindow(
"BUTTON",
"Class Options",
WS_VISIBLE | WS_CHILD,
5,
60,
105,
20,
window,
NULL, //(HMENU)IDB_CLASS_OPTIONS,
NULL, //(HINSTANCE)GetWindowLong(insert, GWL_HINSTANCE),
NULL);
*/
/* Lager bakken
Lager bakken, med "welded-vertices" for å øke hastigheten i realtime editing
Tester med å lage en 3 x 4 rutenett
*/
n0_simpleVertex vArray[4];
int iArray[6];
vArray[1].x = 0; vArray[0].y = 0; vArray[0].z = 0;
vArray[2].x = 50; vArray[1].y = 50; vArray[1].z = 0;
vArray[3].x = 50; vArray[2].y = 0; vArray[2].z = 0;
vArray[4].x = 0; vArray[3].y = 50; vArray[3].z = 0;
iArray[1] = 1;
iArray[2] = 2;
iArray[3] = 4;
iArray[4] = 2;
iArray[5] = 3;
iArray[6] = 1;
n0_CreateNewObject( 1, 4, 6, vArray , iArray );
dbSetObjectCull( 1 , 0 );
/*
FUNKER IKKE
Ser ut til at det er en feil i index-data algo'en.
*//*
const int kol = 4;
const int rad = 3;
int square = 128;
dbPrint(dbStr(kol));
dbWaitKey();
const int vArraySize = (kol + 1) * (rad + 1);
const int iArraySize = kol * rad * 6;
n0_simpleVertex vertexArray[vArraySize];
int indexArray[iArraySize];
// Loop for å fylle inn vertex-arrayen
int teller = 0;
for(int d = 0; d < kol + 1; ++d)
{
for(int a = 0; a < rad + 1; ++a)
{
// Fylle inn vertex-array
vertexArray[teller].x = d * square;
vertexArray[teller].y = 0;
vertexArray[teller].z = a * square;
++teller;
}
}
// Loop for å fylle inn index-arrayen
teller = 0;
for(int j = 0; j < kol; ++j)
{
for(int r = 0; r < rad; ++r)
{
// Fylle inn index-array
indexArray[teller] = 1 + r + j * 4;
++teller;
indexArray[teller] = 5 + r + j * 4;
++teller;
indexArray[teller] = 4 + r + j * 4;
++teller;
indexArray[teller] = 1 + r + j * 4;
++teller;
indexArray[teller] = r + (j + 1) * 4;
++teller;
indexArray[teller] = r + j * 4;
++teller;
}
}
for(teller = 0; teller < iArraySize; ++teller)
{
dbPrint(dbStr(indexArray[teller]));
}
dbWaitKey();
n0_CreateNewObject( 1, vArraySize, iArraySize, vertexArray , indexArray );
dbSetObjectCull( 1 , 0 );
*/
IDirect3D9* test = dbGetDirect3D();
IDirect3DDevice9* devtest = dbGetDirect3DDevice();
while ( LoopGDK ( ) )
{
dbPointCamera( dbObjectPositionX( 1 ) , dbObjectPositionY( 1 ) , dbObjectPositionZ( 1 ) );
if(dbUpKey()){dbMoveCamera(0.5f);}
if(dbDownKey()){dbMoveCamera(-.5f);}
dbSync ( );
}
return;
}
Can anyone help me out please? (I think im driving IanM nuts)