IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

DirectX Discussion :

impossible d'afficher quoi que ce soit


Sujet :

DirectX

  1. #1
    Acropole
    Invité(e)
    Par défaut impossible d'afficher quoi que ce soit
    Bonjour,

    Je commence avec directx et j'essaye juste d'affiche un mesh exporté depuis 3ds max. Mais rien a faire, l'écran reste noir.

    Je pense que le problème vient des vertex et index buffer vu qu'avant de m'en servir ça marchait.

    EDIT : j'ai fixé quelques bugs, mais ça n'affiche toujours rien.
    Voici le nouveau code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    #include "stdafx.h"
     
    #include "D3D9Device.h"
     
    // TEMP
    #include "EntityPlugin_Mesh.h"
     
    EntityPluginMesh * plugMesh;
     
    void D3D9Device::Initialize(HWND hWnd)
    {
        m_D3D = Direct3DCreate9(D3D_SDK_VERSION);    // create the Direct3D interface
     
        D3DPRESENT_PARAMETERS d3dpp;    // create a struct to hold various device information
     
        ZeroMemory(&d3dpp, sizeof(d3dpp));    // clear out the struct for use
        d3dpp.Windowed = TRUE;    // program fullscreen, not windowed
        d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    // discard old frames
        d3dpp.hDeviceWindow = hWnd;    // set the window to be used by Direct3D
        d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;    // set the back buffer format to 32-bit
        d3dpp.BackBufferWidth = SCREENWIDTH;    // set the width of the buffer
        d3dpp.BackBufferHeight = SCREENHEIGHT;    // set the height of the buffer
        d3dpp.EnableAutoDepthStencil = TRUE;
        d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
     
        // create a device class using this information and information from the d3dpp stuct
        m_D3D->CreateDevice(D3DADAPTER_DEFAULT,
                          D3DDEVTYPE_HAL,
                          hWnd,
                          D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                          &d3dpp,
                          &m_Device);
     
        m_Device->SetRenderState(D3DRS_LIGHTING, TRUE);
        m_Device->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(50, 50, 50));
        m_Device->SetRenderState(D3DRS_ZENABLE, TRUE);    // turn on the z-buffer
        m_Device->SetRenderState(D3DRS_NORMALIZENORMALS, TRUE);
     
        InitLight();
    }
     
    // this is the function that sets up the lights and materials
    void D3D9Device::InitLight(void)
    {
        D3DLIGHT9 light;    // create the light struct
     
        ZeroMemory(&light, sizeof(light));    // clear out the light struct for use
        light.Type = D3DLIGHT_POINT;    // make the light type 'directional light'
        light.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);    // set the light's color
    //    light.Direction = D3DXVECTOR3(-1.0f, -0.3f, -1.0f);
     
        m_Device->SetLight(0, &light);    // send the light struct properties to light #0
        m_Device->LightEnable(0, TRUE);    // turn on light #0
     
        InitMaterial();
    }
     
    void D3D9Device::InitMaterial(void)
    {
        D3DMATERIAL9 material;    // create the material struct
        ZeroMemory(&material, sizeof(D3DMATERIAL9));    // clear out the struct for use
        material.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);    // set diffuse color to white
        material.Ambient = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);    // set ambient color to white
     
        m_Device->SetMaterial(&material);    // set the globably-used material to &material    
    }
     
    // Preparation de la scene avant le rendu. Collecte les infos nécessaires au rendu
    void D3D9Device::PrepareScene(void)
    {
        static bool done = false;
     
        if(!done){
            // TEMP
            plugMesh = new EntityPluginMesh();
            string s( "aegil.amf");
            plugMesh->LoadFromFile( &s );
     
     
            // create the vertices using the CUSTOMVERTEX struct
            int vCount = plugMesh->GetVecteurs().size();
            CUSTOMVERTEX * vertices = new CUSTOMVERTEX[ vCount ];
            for( int i = 0; i < vCount; i++ )
            {
                vertices[i].X = plugMesh->GetVecteurs()[i].x;
                vertices[i].Y = plugMesh->GetVecteurs()[i].y;
                vertices[i].Z = plugMesh->GetVecteurs()[i].z;
                vertices[i].Z = 1.0;
                //vertices[i].COLOR = D3DCOLOR_COLORVALUE( 1.0, 1.0, 1.0, 1.0 );
                vertices[i].NORMAL.x = plugMesh->GetNormales()[i].x;
                vertices[i].NORMAL.y = plugMesh->GetNormales()[i].y;
                vertices[i].NORMAL.z = plugMesh->GetNormales()[i].z;
            }
     
            // create a vertex buffer interface called m_VertexBuffer
            if( FAILED( m_Device->CreateVertexBuffer( vCount * sizeof(CUSTOMVERTEX),
                                       0,
                                       CUSTOMFVF,
                                       D3DPOOL_MANAGED,
                                       &m_VertexBuffer,
                                       NULL) ) ){
                return;
            }
     
            void* pVoid;    // a void pointer
     
            // lock m_VertexBuffer and load the vertices into it
            m_VertexBuffer->Lock(0, 0, &pVoid, 0);
            memcpy(pVoid, vertices, sizeof(vertices));
            m_VertexBuffer->Unlock();
     
            // create the indices using an int array
            int fCount = plugMesh->GetFaces().size();
            int * indices = new int[ fCount * 3 ];
            int k = 0;
            for(int i = 0; i < fCount; i++){
                for(int j = 0; j < 3; j++){
                    indices[ k ] = plugMesh->GetFaces()[i][j];
                    k++;
                }
            }
     
            // create an index buffer interface called m_IndexBuffer
            m_Device->CreateIndexBuffer( 3 * fCount * sizeof( short ),
                                      0,
                                      D3DFMT_INDEX16,
                                      D3DPOOL_MANAGED,
                                      &m_IndexBuffer,
                                      NULL);
     
            // lock m_IndexBuffer and load the indices into it
            void * pIndices;
            m_IndexBuffer->Lock(0, 0, &pIndices, 0);
            memcpy(pIndices, indices, 3 * fCount * sizeof( short ));
            m_IndexBuffer->Unlock();
        }
     
     
        done = true;
    }
     
    // this is the function used to render a single frame
    void D3D9Device::Render(void)
    {
        static float camDist = 20.0f;
        camDist += 20.0f * Input::gInput->GetKey(VK_F3);
        camDist -= 20.0f * Input::gInput->GetKey(VK_F4);
     
        // clear the window to a deep blue
        m_Device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
        m_Device->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
        m_Device->BeginScene();    // begins the 3D scene
     
             // select which vertex format we are using
     
            // VIEW
            D3DXMATRIX matView;    // the view transform matrix
     
            D3DXMatrixLookAtLH(&matView,
                               &D3DXVECTOR3 (0.0f, 5.0f, camDist),    // the camera position
                               &D3DXVECTOR3 (0.0f, 0.0f, 0.0f),    // the look-at position
                               &D3DXVECTOR3 (0.0f, 1.0f, 0.0f));    // the up direction
            m_Device->SetTransform(D3DTS_VIEW, &matView);    // set the view transform to matView
     
            // PROJECTION
            D3DXMATRIX matProjection;     // the projection transform matrix
     
            D3DXMatrixPerspectiveFovLH(&matProjection,
                                       D3DXToRadian(45),    // the horizontal field of view
                                       (FLOAT)SCREENWIDTH / (FLOAT)SCREENHEIGHT, // aspect ratio
                                       1.0f,    // the near view-plane
                                       100.0f);    // the far view-plane
     
            m_Device->SetTransform(D3DTS_PROJECTION, &matProjection);    // set the projection
     
     
            // set the world transform
            static float index = 0.0f;
            float rot = 0.0;
            rot += Input::gInput->GetKey(VK_F1);
            rot -= Input::gInput->GetKey(VK_F2);
            index+=0.03f * rot ; // an ever-increasing float value
            D3DXMATRIX matRotateY;    // a matrix to store the rotation for each triangle
            D3DXMatrixRotationY(&matRotateY, index);    // the rotation matrix
            m_Device->SetTransform(D3DTS_WORLD, &(matRotateY));    // set the world transform
            // SET UP THE PIPELINE
     
            // select the vertex and index buffers to use
            m_Device->SetStreamSource(0, m_VertexBuffer, 0, sizeof(CUSTOMVERTEX));
            m_Device->SetFVF(CUSTOMFVF);
            m_Device->SetIndices(m_IndexBuffer);
            int vCount = plugMesh->GetVecteurs().size();
            int fCount = plugMesh->GetFaces().size();
            //m_Device->DrawPrimitive( D3DPT_TRIANGLELIST, 0, fCount);
            m_Device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,vCount,0,fCount);
     
        m_Device->EndScene();    // ends the 3D scene
        m_Device->Present(NULL, NULL, NULL, NULL);    // displays the created frame
    }
     
    // this is the function that cleans up Direct3D and COM
    void D3D9Device::CleanUp(void)
    {
        m_VertexBuffer->Release();
        m_IndexBuffer->Release();
        m_Device->Release();    // close and release the 3D device
        m_D3D->Release();    // close and release Direct3D
    }
     
    D3D9Device::D3D9Device(HWND hWnd)
    {
        m_VertexBuffer = NULL;
        m_IndexBuffer = NULL;
        Initialize(hWnd);
    }
     
    D3D9Device::~D3D9Device(void)
    {
        CleanUp();
    }
    Dernière modification par Acropole ; 02/01/2010 à 11h42.

  2. #2
    Membre actif Avatar de ShadowTzu
    Homme Profil pro
    Développeur de jeux vidéo
    Inscrit en
    Juin 2005
    Messages
    243
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Haute Saône (Franche Comté)

    Informations professionnelles :
    Activité : Développeur de jeux vidéo

    Informations forums :
    Inscription : Juin 2005
    Messages : 243
    Points : 296
    Points
    296
    Par défaut
    Bonjour,

    J'ai survoler tes extraits de code, et quelque truc manque où sont étrange. De plus un petit conseil, n'utilise pas la lumière tant que ce n'est pas rendu correctement, difficile de voir ce qui va pas avec un clear noir, et une lumière mal défini, donc noir.
    donc:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    m_Device->SetRenderState(D3DRS_LIGHTING, FALSE);
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    light.Type = D3DLIGHT_POINT; 
    [...]
    je suppose que c'est en cherchant ce qui va pas qui tu as changé ça, mais à l'origine c'était une lumière directionnel. Pour une ponctuel tu as d'autre info à fournir, mais bon plus tard, et il me semble qu'il manque un update:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    device.Lights(0).Update() '(ou Commit suivant ta version de directx)
    dans ta fonction PrepareScene il y a une double ligne:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    vertices[i].Z = plugMesh->GetVecteurs()[i].z;
    vertices[i].Z = 1.0;
    dans la création de ton indexbuffer il semblerait que ton tableau d'indices soit un "Int" et que l'indexbuffer est créé avec un "Short"

    pour ton clear tu devrais pouvoir rassembler ces 2 lignes ensemble:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    m_Device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
    m_Device->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
    en:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    m_Device->Clear(0, NULL, D3DCLEAR_TARGET OR D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255, 0, 255), 1.0f, 0); // j'ai m'y du rose
    sinon attention à l'échelle, généralement quand j'exporte mes models pour les utiliser, ils sont ENORME, donc au cas ou met ton far plane très loin ou même vers l'infini (-1.0f):

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    D3DXMatrixPerspectiveFovLH(&matProjection, D3DXToRadian(45),(FLOAT)SCREENWIDTH / (FLOAT)SCREENHEIGHT, 1.0f, 10000.0f);
    Bon courage.

  3. #3
    Acropole
    Invité(e)
    Par défaut
    Merci pour tes conseils mais y'a rien a faire, ça n'affiche rien.

  4. #4
    Expert confirmé

    Profil pro
    Inscrit en
    Février 2006
    Messages
    2 395
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2006
    Messages : 2 395
    Points : 5 009
    Points
    5 009
    Par défaut
    tu as testé les valeurs de retour pour toutes les fonctions, des fois que ...

  5. #5
    Expert éminent sénior
    Avatar de Mat.M
    Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2006
    Messages
    8 392
    Détails du profil
    Informations personnelles :
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Novembre 2006
    Messages : 8 392
    Points : 20 494
    Points
    20 494
    Par défaut
    Citation Envoyé par Acropole Voir le message
    Bonjour,

    Je commence avec directx et j'essaye juste d'affiche un mesh exporté depuis 3ds max. Mais rien a faire, l'écran reste noir.
    As-tu pensé à faire une chose toute bête : utiliser un D3DXMesh ?
    Si tu charges un objet 3d avec D3DXLoadMeshFromX et que tu l'affiches c'est que le fichier est mal converti au format X alors
    Regarder dans le SDK de Direct X le tuto /samples/tutorial05/meshes qui affiche un tigre ( Direct X 9)

  6. #6
    Membre régulier
    Profil pro
    Étudiant
    Inscrit en
    Octobre 2007
    Messages
    77
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2007
    Messages : 77
    Points : 73
    Points
    73
    Par défaut
    T'es en train de créer le context de dirct3d avant de créer ta fenêtre !
    créé d'abord la fenêtre puis passe le hWnd à Direct3D.
    Note:
    T'es sûr que ce même code marchait avant ??

  7. #7
    Acropole
    Invité(e)
    Par défaut
    Je comprend pas ce que tu dis. Hwnd est passé en paramètre, elle est crée avant.
    Oui ce code marchait, mais j'utilisai pas les buffers.

Discussions similaires

  1. impossible de faire quoi que se soit sur windows 8
    Par jebbayou dans le forum Windows 8
    Réponses: 3
    Dernier message: 18/05/2013, 15h05
  2. Réponses: 0
    Dernier message: 28/12/2012, 08h27
  3. Windows HS et impossible de faire quoi que ce soit
    Par ipodtueur dans le forum Windows 7
    Réponses: 19
    Dernier message: 17/12/2010, 12h26
  4. Réponses: 0
    Dernier message: 17/02/2008, 22h22
  5. PC reboot en boucle avant d'afficher quoi que ce soit
    Par bruman dans le forum Composants
    Réponses: 7
    Dernier message: 04/01/2008, 01h42

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo