[ Príspevkov: 2 ] 
AutorSpráva
Offline

Užívateľ
Užívateľ
c++ directx DrawIndexedPrimitive

Registrovaný: 01.02.08
Prihlásený: 10.04.15
Príspevky: 31
Témy: 11 | 11
NapísalOffline : 11.07.2011 20:27 | c++ directx DrawIndexedPrimitive

Zdravim, prednedavnom som zacal robit pokusy s directx a teraz som narazil na jeden problem (tych problemov bolo viac ale vecsinu som vyriesil) mam nasledovne kody:
nacitanie:
Kód:
HeightMap::HeightMap(char *fname, IDirect3DDevice9* pd3dDevice)
{
    FILE *f=NULL;
    f=fopen(fname,"rb");
    if (!f)
    {
        x_width=0;
        z_height=0;
        map=NULL;
        return;
    }
    int a=0,b=0;
    fread(&x_width, sizeof(word),1, f);
    fread(&z_height, sizeof(word),1, f);
   
    map = new float*[x_width];
   for (int i = 0; i < x_width; ++i) map[i] = new float[z_height];
   
    for (int i=0; i<x_width; i++)
        for (int j=0; j<z_height; j++) map[i][j]=1;
   
   Vertices = new CUSTOMVERTEX[x_width*z_height];

   // Create the vertex buffer.
    if( FAILED( pd3dDevice->CreateVertexBuffer( x_width*z_height* sizeof( CUSTOMVERTEX ),
                                                  0, D3DFVF_CUSTOMVERTEX,
                                                  D3DPOOL_DEFAULT, &pVB, NULL ) ) )
    {
        return;
    }

   Indices = new UINT[(x_width-1)*(z_height-1)*6];
   if( FAILED( pd3dDevice->CreateIndexBuffer( (x_width-1)*(z_height-1)*6 *sizeof(UINT),
                                 D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_DEFAULT,
                                 &pIB, NULL ) ) )
   {
      return;
   }

   VOID *pVertices;
   if( FAILED( pVB->Lock( 0, 0, ( void** )&pVertices, 0 ) ) )
      return;
   
    do
    {
         fread(&map[a][b], sizeof(float),1, f);
       Vertices[a*x_width+b].x=a;
       Vertices[a*x_width+b].y=map[a][b];
       Vertices[a*x_width+b].z=b;
       Vertices[a*x_width+b].tu=a%2;
       Vertices[a*x_width+b].tv=b%2;
         a++;
         if (a==x_width) {b++;a=0;}
    }
    while(b<z_height);
   memcpy( pVertices, Vertices, sizeof(Vertices) );
   pVB->Unlock();

   VOID* pIndices;

   if( FAILED( pIB->Lock( 0, sizeof(Indices), (VOID**)&pIndices, 0) ) )
   {
      SAFE_RELEASE(pIB);
      return;
   }
   
   int k=0;
   for (int i=0; i<x_width-1; i++)
      for (int j=0; j<z_height-1; j++)
      {
         Indices[k]=i*x_width+j;
         k++;
         Indices[k]=(i+1)*x_width+j;
         k++;
         Indices[k]=i*x_width+j+1;
         k++;

         Indices[k]=(i+1)*x_width+j;
         k++;
         Indices[k]=(i+1)*x_width+j+1;
         k++;
         Indices[k]=i*x_width+j+1;
         k++;
      }

   memcpy( pIndices, Indices, sizeof(Indices) );
   pIB->Unlock();

    fclose(f);

   Texture=NULL;

   if( FAILED( D3DXCreateTextureFromFile( pd3dDevice, L"banana.bmp", &Texture ) ) )
    {
        // If texture is not in current folder, try parent folder
        if( FAILED( D3DXCreateTextureFromFile( pd3dDevice, L"..\\banana.bmp", &Texture ) ) )
        {
            MessageBox( NULL, L"Could not find banana.bmp", L"Textures.exe", MB_OK );
            return;
        }
    }
}


vykreslenie:
Kód:
                mProj = *g_Camera.GetProjMatrix();
      mView = *g_Camera.GetViewMatrix();

      // Get the projection & view matrix from the camera class
        D3DXMatrixTranslation(&mWorld,0,-6000,0);

        mWorldViewProjection = mWorld * mView * mProj;

        // Update the effect's variables.  Instead of using strings, it would
        // be more efficient to cache a handle to the parameter by calling
        // ID3DXEffect::GetParameterByName
      UINT iPass, cPasses;
      
        V( g_pEffect->SetMatrix( "g_mWorldViewProjection", &mWorldViewProjection ) );
        V( g_pEffect->SetMatrix( "g_mWorld", &mWorld ) );
        V( g_pEffect->SetFloat( "g_fTime", ( float )fTime ) );

        g_pEffect->SetTechnique( "RenderScene" );
      
      pd3dDevice->SetStreamSource( 0, mapa->pVB, 0, sizeof( CUSTOMVERTEX ) );
      pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
      pd3dDevice->SetIndices(mapa->pIB);
      
      V( g_pEffect->Begin( &cPasses, 0 ) );
      for( iPass = 0; iPass < cPasses; iPass++ )
      {
         V( g_pEffect->BeginPass( iPass ) );
         pd3dDevice->SetTexture( 0, mapa->Texture );
         pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, mapa->x_width*mapa->z_height, 0, (mapa->x_width-1)*(mapa->z_height-1));
         g_pEffect->EndPass();
      }
      g_pEffect->End();


pouzivam MS VC++ 2010, Microsoft DirectX SDK (June 2010).
problem je ten ze DrawIndexedPrimitive nevykresli nic, mam kameru ovladam sipkami a klavesami W S. Skusal som ju najst :rolleyes: ale nepodarilo sa.
vykreslenie bez indexov funguje:
Kód:
        D3DXMatrixTranslation(&mWorld,5,-4,5);
      
        mWorldViewProjection = mWorld * mView * mProj;

      V( g_pEffect->SetMatrix( "g_mWorldViewProjection", &mWorldViewProjection ) );
        V( g_pEffect->SetMatrix( "g_mWorld", &mWorld ) );
        V( g_pEffect->SetFloat( "g_fTime", ( float )fTime ) );
        g_pEffect->SetTechnique( "RenderScene" );

      pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof( CUSTOMVERTEX ) );
      pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );

      V( g_pEffect->Begin( &cPasses, 0 ) );
      for( iPass = 0; iPass < cPasses; iPass++ )
      {
         V( g_pEffect->BeginPass( iPass ) );
         pd3dDevice->SetTexture( 0, g_pTexture );
         pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 1 );
         g_pEffect->EndPass();
      }
        g_pEffect->End();


Jedna sa o tom ze som naprogramoval hru s grafikou v Opengl, teraz by som to rad prepisal do Directx.


Offline

Užívateľ
Užívateľ
c++ directx DrawIndexedPrimitive

Registrovaný: 08.03.09
Prihlásený: 17.01.25
Príspevky: 1116
Témy: 88 | 88
Bydlisko: 00100100
NapísalOffline : 11.07.2011 21:57 | c++ directx DrawIndexedPrimitive

ak sa ti nikto neozve, tak skus napisat na nejake oficialne forum kde sa zaoberaju konkretne DirectX ;)


_________________
Programming is The Best
Hackers Are Not Crackers!!! Hackers build things, crackers break them!
;-)
 [ Príspevkov: 2 ] 


c++ directx DrawIndexedPrimitive



Podobné témy

 Témy  Odpovede  Zobrazenia  Posledný príspevok 
V tomto fóre nie sú ďalšie neprečítané témy.

Mám sa učiť C ++/objective C/ C#?

v Backend

5

849

08.07.2014 20:40

XOLOO

V tomto fóre nie sú ďalšie neprečítané témy.

DirectX

v Ostatné programy

10

1233

01.01.2007 22:23

shaggy

V tomto fóre nie sú ďalšie neprečítané témy.

DirectX

v Grafické programy

3

662

17.02.2010 16:17

prandof

V tomto fóre nie sú ďalšie neprečítané témy.

DirectX

v Ovládače

0

603

03.02.2012 21:40

logaro

V tomto fóre nie sú ďalšie neprečítané témy.

DirectX

v Ovládače

17

1002

25.01.2015 12:50

Johnsik

V tomto fóre nie sú ďalšie neprečítané témy.

Directx

v Ostatné programy

1

607

28.01.2021 17:07

shiro

V tomto fóre nie sú ďalšie neprečítané témy.

DirectX

v Hry a herné konzoly

8

1235

19.01.2008 18:52

tomas4458

V tomto fóre nie sú ďalšie neprečítané témy.

directX

v nVidia grafické karty

18

1477

25.07.2007 0:45

miskoTT

V tomto fóre nie sú ďalšie neprečítané témy.

DirectX

[ Choď na stránku:Choď na stránku: 1, 2 ]

v Ostatné grafické karty

32

1749

03.08.2012 15:18

TOMQ

V tomto fóre nie sú ďalšie neprečítané témy.

directx

v Ovládače

9

1337

13.11.2008 20:45

shiro

V tomto fóre nie sú ďalšie neprečítané témy.

directX

v Windows

2

679

23.03.2010 20:00

p4tooo

V tomto fóre nie sú ďalšie neprečítané témy.

DirectX

v Ovládače

4

810

01.02.2012 11:14

tairikuokami

V tomto fóre nie sú ďalšie neprečítané témy.

DirectX problem

v Windows

0

586

08.10.2006 12:10

Meldo

V tomto fóre nie sú ďalšie neprečítané témy.

DirectX 10

[ Choď na stránku:Choď na stránku: 1, 2 ]

v AMD grafické karty

37

2180

06.12.2008 14:28

djfreeman

V tomto fóre nie sú ďalšie neprečítané témy.

Directx 12

v AMD grafické karty

3

564

07.06.2015 19:56

kllr007

V tomto fóre nie sú ďalšie neprečítané témy.

directX 10

[ Choď na stránku:Choď na stránku: 1, 2 ]

v nVidia grafické karty

36

1903

11.06.2007 14:53

eXistenZ



© 2005 - 2026 PCforum, edited by JanoF