Z-Buffer fait des siennes

Résolu
bizzard4 Messages postés 155 Date d'inscription vendredi 12 décembre 2003 Statut Membre Dernière intervention 15 février 2009 - 19 mars 2007 à 18:42
bizzard4 Messages postés 155 Date d'inscription vendredi 12 décembre 2003 Statut Membre Dernière intervention 15 février 2009 - 19 mars 2007 à 22:22
J'ai un problème avec mon Z-Buffer. Il affiche très bien la partie droite et le dessous de mes cubes. Mais quand il est temps d'afficher le côté gauche de le dessus il met la face par dessus mais elle devrait être caché.

J'ai cherché des solutions mais je n'ai pas de piste sur la source du problème. D'après mois c'est mon Z-Buffer mais j'ai aussi de la misère à me faire une idée du sens de mes triangles. Doivent t'ils être dans le sens triginométrique par rapport au centre (0,0,0) au bien cela n'a pas d'importante ?

J'ai un screenshot du résultat

Merci à l'avance.

~~ Cordialement Francois Gingras

5 réponses

bizzard4 Messages postés 155 Date d'inscription vendredi 12 décembre 2003 Statut Membre Dernière intervention 15 février 2009
19 mars 2007 à 22:18
Bon !! J'ai trouvez la source de mon problème. C'est que je n'avais pas activez le :

    d3dpp.EnableAutoDepthStencil = true;
    d3dpp.AutoDepthStencilFormat = D3DFMT_D16;

Mais maintenant j'ai un nouveau bug

J'ai essayé sur plusieurs ordinateur pour savoir si c'est mon code ou ma carte 3D mais c'est mon code :

Screenshot:

Voila mes cubes sont maintenant complètement sacadé...

Si quelqu'un a une solution.

~~ Cordialement Francois Gingras
3
bizzard4 Messages postés 155 Date d'inscription vendredi 12 décembre 2003 Statut Membre Dernière intervention 15 février 2009
19 mars 2007 à 22:22
Bon je reposte pour une troisième fois !!! Désolé pour les postes sucétif.

J'ai trouvez mon erreur. J'explique :

Je ne "clearait" pas la buffer comme du monde. J'ai oublier de vider le zbuffer. Alors j'ai changé la ligne de mon clear
De : g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
À : g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);

Maintenant tout marche à merveille !

~~ Cordialement Francois Gingras
3
luhtor Messages postés 2023 Date d'inscription mardi 24 septembre 2002 Statut Membre Dernière intervention 28 juillet 2008 6
19 mars 2007 à 19:00
Si tu n'as pas activé de culling particulier, l'ordre des indices pour afficher un triangle n'a pas d'importance.

Pour ton pb, tu es sur d'avoir activer le zbuffer ?
0
spiky31 Messages postés 106 Date d'inscription mardi 11 novembre 2003 Statut Membre Dernière intervention 11 février 2008
19 mars 2007 à 19:24
Par defaut, les faces avant doivent etre dessinées dans le sens inverse des aiguilles d'une montre (mais tu peux le modifier avec glFrontFace).

Donc si tes triangles sont dessinées dans le bon ordre et que tu as activé le z-buffer (glEnable(GL_DEPTH_TEST)) il ne devrait pas y avoir de problemes.
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
bizzard4 Messages postés 155 Date d'inscription vendredi 12 décembre 2003 Statut Membre Dernière intervention 15 février 2009
19 mars 2007 à 22:08
spiky31 : C'est du DirectX mais cela revient au même.

Mon z-buffer et mon culling sont activés :
    g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
    g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, false);
    g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, true);

Et l'ordre de mes triangles est correctes car je les vois tous sans problème mais j'ai toujours le problème. C'est peux être mon VertexBuffer ? je vais vous montrez le code pour "seter" mes carrés.

int k = 0;
    for (int j = 0; j < 10; j++)
    {
        for (int i = 0; i < 10; i++)
        {
            // Fond :: Rouge
            g_Vertices[(j*360)+(i*36)+0].position = D3DXVECTOR3(-5.0f + (11.0f * (float)i), -5.0f - (11.0f * (float)j), 0.0f);
            g_Vertices[(j*360)+(i*36)+0].tu = 0.0f;
            g_Vertices[(j*360)+(i*36)+0].tv = 1.0f;
            g_Vertices[(j*360)+(i*36)+1].position = D3DXVECTOR3(5.0f + (11.0f * (float)i), -5.0f - (11.0f * (float)j), 0.0f);
            g_Vertices[(j*360)+(i*36)+1].tu = 1.0f;
            g_Vertices[(j*360)+(i*36)+1].tv = 1.0f;
            g_Vertices[(j*360)+(i*36)+2].position = D3DXVECTOR3(-5.0f + (11.0f * (float)i), 5.0f - (11.0f * (float)j), 0.0f);
            g_Vertices[(j*360)+(i*36)+2].tu = 0.0f;
            g_Vertices[(j*360)+(i*36)+2].tv = 0.0f;

            g_Vertices[(j*360)+(i*36)+3].position = D3DXVECTOR3(5.0f + (11.0f * (float)i), -5.0f - (11.0f * (float)j), 0.0f);
            g_Vertices[(j*360)+(i*36)+3].tu = 1.0f;
            g_Vertices[(j*360)+(i*36)+3].tv = 1.0f;
            g_Vertices[(j*360)+(i*36)+4].position = D3DXVECTOR3(5.0f + (11.0f * (float)i), 5.0f - (11.0f * (float)j), 0.0f);
            g_Vertices[(j*360)+(i*36)+4].tu = 1.0f;
            g_Vertices[(j*360)+(i*36)+4].tv = 0.0f;
            g_Vertices[(j*360)+(i*36)+5].position = D3DXVECTOR3(-5.0f + (11.0f * (float)i), 5.0f - (11.0f * (float)j), 0.0f);
            g_Vertices[(j*360)+(i*36)+5].tu = 0.0f;
            g_Vertices[(j*360)+(i*36)+5].tv = 0.0f;

            // Top :: Vert
            g_Vertices[(j*360)+(i*36)+6].position = D3DXVECTOR3(-5.0f + (11.0f * (float)i), -5.0f - (11.0f * (float)j), -10.0f);
            g_Vertices[(j*360)+(i*36)+6].tu = 0.0f;
            g_Vertices[(j*360)+(i*36)+6].tv = 1.0f;
            g_Vertices[(j*360)+(i*36)+7].position = D3DXVECTOR3(-5.0f + (11.0f * (float)i), 5.0f - (11.0f * (float)j), -10.0f);
            g_Vertices[(j*360)+(i*36)+7].tu = 0.0f;
            g_Vertices[(j*360)+(i*36)+7].tv = 0.0f;
            g_Vertices[(j*360)+(i*36)+8].position = D3DXVECTOR3(5.0f + (11.0f * (float)i), -5.0f - (11.0f * (float)j), -10.0f);
            g_Vertices[(j*360)+(i*36)+8].tu = 1.0f;
            g_Vertices[(j*360)+(i*36)+8].tv = 1.0f;

            g_Vertices[(j*360)+(i*36)+9].position = D3DXVECTOR3(5.0f + (11.0f * (float)i), -5.0f - (11.0f * (float)j), -10.0f);
            g_Vertices[(j*360)+(i*36)+9].tu = 1.0f;
            g_Vertices[(j*360)+(i*36)+9].tv = 1.0f;
            g_Vertices[(j*360)+(i*36)+10].position = D3DXVECTOR3(-5.0f + (11.0f * (float)i), 5.0f - (11.0f * (float)j), -10.0f);
            g_Vertices[(j*360)+(i*36)+10].tu = 0.0f;
            g_Vertices[(j*360)+(i*36)+10].tv = 0.0f;
            g_Vertices[(j*360)+(i*36)+11].position = D3DXVECTOR3(5.0f + (11.0f * (float)i), 5.0f - (11.0f * (float)j), -10.0f);
            g_Vertices[(j*360)+(i*36)+11].tu = 1.0f;
            g_Vertices[(j*360)+(i*36)+11].tv = 0.0f;

            // Face Devant :: Bleu
            g_Vertices[(j*360)+(i*36)+12].position = D3DXVECTOR3(-5.0f + (11.0f * (float)i), -5.0f - (11.0f * (float)j), 0.0f);
            g_Vertices[(j*360)+(i*36)+12].tu = 0.0f;
            g_Vertices[(j*360)+(i*36)+12].tv = 1.0f;
            g_Vertices[(j*360)+(i*36)+13].position = D3DXVECTOR3(-5.0f + (11.0f * (float)i), -5.0f - (11.0f * (float)j), -10.0f);
            g_Vertices[(j*360)+(i*36)+13].tu = 0.0f;
            g_Vertices[(j*360)+(i*36)+13].tv = 0.0f;
            g_Vertices[(j*360)+(i*36)+14].position = D3DXVECTOR3(5.0f + (11.0f * (float)i), -5.0f - (11.0f * (float)j), 0.0f);
            g_Vertices[(j*360)+(i*36)+14].tu = 1.0f;
            g_Vertices[(j*360)+(i*36)+14].tv = 1.0f;

            g_Vertices[(j*360)+(i*36)+15].position = D3DXVECTOR3(5.0f + (11.0f * (float)i), -5.0f - (11.0f * (float)j), 0.0f);
            g_Vertices[(j*360)+(i*36)+15].tu = 1.0f;
            g_Vertices[(j*360)+(i*36)+15].tv = 1.0f;
            g_Vertices[(j*360)+(i*36)+16].position = D3DXVECTOR3(-5.0f + (11.0f * (float)i), -5.0f - (11.0f * (float)j), -10.0f);
            g_Vertices[(j*360)+(i*36)+16].tu = 0.0f;
            g_Vertices[(j*360)+(i*36)+16].tv = 0.0f;
            g_Vertices[(j*360)+(i*36)+17].position = D3DXVECTOR3(5.0f + (11.0f * (float)i), -5.0f - (11.0f * (float)j), -10.0f);
            g_Vertices[(j*360)+(i*36)+17].tu = 1.0f;
            g_Vertices[(j*360)+(i*36)+17].tv = 0.0f;

            // Face derrìère :: Rose
            // PROBLEME LA FACE PASSE PAR DESSUS LES AUTRES
            g_Vertices[(j*360)+(i*36)+18].position = D3DXVECTOR3(-5.0f + (11.0f * (float)i), 5.0f - (11.0f * (float)j), 0.0f);
            g_Vertices[(j*360)+(i*36)+18].tu = 0.0f;
            g_Vertices[(j*360)+(i*36)+18].tv = 1.0f;
            g_Vertices[(j*360)+(i*36)+19].position = D3DXVECTOR3(5.0f + (11.0f * (float)i), 5.0f - (11.0f * (float)j), 0.0f);
            g_Vertices[(j*360)+(i*36)+19].tu = 1.0f;
            g_Vertices[(j*360)+(i*36)+19].tv = 1.0f;
            g_Vertices[(j*360)+(i*36)+20].position = D3DXVECTOR3(-5.0f + (11.0f * (float)i), 5.0f - (11.0f * (float)j), -10.0f);
            g_Vertices[(j*360)+(i*36)+20].tu = 0.0f;
            g_Vertices[(j*360)+(i*36)+20].tv = 0.0f;

            g_Vertices[(j*360)+(i*36)+21].position = D3DXVECTOR3(5.0f + (11.0f * (float)i), 5.0f - (11.0f * (float)j), 0.0f);
            g_Vertices[(j*360)+(i*36)+21].tu = 1.0f;
            g_Vertices[(j*360)+(i*36)+21].tv = 1.0f;
            g_Vertices[(j*360)+(i*36)+22].position = D3DXVECTOR3(5.0f + (11.0f * (float)i), 5.0f - (11.0f * (float)j), -10.0f);
            g_Vertices[(j*360)+(i*36)+22].tu = 1.0f;
            g_Vertices[(j*360)+(i*36)+22].tv = 0.0f;
            g_Vertices[(j*360)+(i*36)+23].position = D3DXVECTOR3(-5.0f + (11.0f * (float)i), 5.0f - (11.0f * (float)j), -10.0f);
            g_Vertices[(j*360)+(i*36)+23].tu = 0.0f;
            g_Vertices[(j*360)+(i*36)+23].tv = 0.0f;

            // Face Gauche :: Cyan
            // PROBLEME LA FACE PASSE PAR DESSUS LES AUTRES
            g_Vertices[(j*360)+(i*36)+24].position = D3DXVECTOR3(-5.0f + (11.0f * (float)i), 5.0f - (11.0f * (float)j), 0.0f);
            g_Vertices[(j*360)+(i*36)+24].tu = 0.0f;
            g_Vertices[(j*360)+(i*36)+24].tv = 1.0f;
            g_Vertices[(j*360)+(i*36)+25].position = D3DXVECTOR3(-5.0f + (11.0f * (float)i), 5.0f - (11.0f * (float)j), -10.0f);
            g_Vertices[(j*360)+(i*36)+25].tu = 0.0f;
            g_Vertices[(j*360)+(i*36)+25].tv = 0.0f;
            g_Vertices[(j*360)+(i*36)+26].position = D3DXVECTOR3(-5.0f + (11.0f * (float)i), -5.0f - (11.0f * (float)j), 0.0f);
            g_Vertices[(j*360)+(i*36)+26].tu = 1.0f;
            g_Vertices[(j*360)+(i*36)+26].tv = 1.0f;

            g_Vertices[(j*360)+(i*36)+27].position = D3DXVECTOR3(-5.0f + (11.0f * (float)i), -5.0f - (11.0f * (float)j), 0.0f);
            g_Vertices[(j*360)+(i*36)+27].tu = 1.0f;
            g_Vertices[(j*360)+(i*36)+27].tv = 1.0f;
            g_Vertices[(j*360)+(i*36)+28].position = D3DXVECTOR3(-5.0f + (11.0f * (float)i), 5.0f - (11.0f * (float)j), -10.0f);
            g_Vertices[(j*360)+(i*36)+28].tu = 0.0f;
            g_Vertices[(j*360)+(i*36)+28].tv = 0.0f;
            g_Vertices[(j*360)+(i*36)+29].position = D3DXVECTOR3(-5.0f + (11.0f * (float)i), -5.0f - (11.0f * (float)j), -10.0f);
            g_Vertices[(j*360)+(i*36)+29].tu = 1.0f;
            g_Vertices[(j*360)+(i*36)+29].tv = 0.0f;

            // Face Droite :: Jaune
            g_Vertices[(j*360)+(i*36)+30].position = D3DXVECTOR3(5.0f + (11.0f * (float)i), 5.0f - (11.0f * (float)j), -10.0f);
            g_Vertices[(j*360)+(i*36)+30].tu = 1.0f;
            g_Vertices[(j*360)+(i*36)+30].tv = 0.0f;
            g_Vertices[(j*360)+(i*36)+31].position = D3DXVECTOR3(5.0f + (11.0f * (float)i), -5.0f - (11.0f * (float)j), 0.0f);
            g_Vertices[(j*360)+(i*36)+31].tu = 0.0f;
            g_Vertices[(j*360)+(i*36)+31].tv = 1.0f;
            g_Vertices[(j*360)+(i*36)+32].position = D3DXVECTOR3(5.0f + (11.0f * (float)i), -5.0f - (11.0f * (float)j), -10.0f);
            g_Vertices[(j*360)+(i*36)+32].tu = 1.0f;
            g_Vertices[(j*360)+(i*36)+32].tv = 1.0f;

            g_Vertices[(j*360)+(i*36)+33].position = D3DXVECTOR3(5.0f + (11.0f * (float)i), -5.0f - (11.0f * (float)j), 0.0f);
            g_Vertices[(j*360)+(i*36)+33].tu = 0.0f;
            g_Vertices[(j*360)+(i*36)+33].tv = 1.0f;
            g_Vertices[(j*360)+(i*36)+34].position = D3DXVECTOR3(5.0f + (11.0f * (float)i), 5.0f - (11.0f * (float)j), -10.0f);
            g_Vertices[(j*360)+(i*36)+34].tu = 1.0f;
            g_Vertices[(j*360)+(i*36)+34].tv = 0.0f;
            g_Vertices[(j*360)+(i*36)+35].position = D3DXVECTOR3(5.0f + (11.0f * (float)i), 5.0f - (11.0f * (float)j), 0.0f);
            g_Vertices[(j*360)+(i*36)+35].tu = 0.0f;
            g_Vertices[(j*360)+(i*36)+35].tv = 0.0f;
        }
    }

    // Setup des couleurs
        // met tout en blacn
    for (k = 0; k < 3600; k++)
    {
        g_Vertices[k].color = D3DCOLOR_XRGB(255, 255, 255);
    }
        // sauf la première case du haut :: Vert
    for (k = 0; k < 36; k++)
    {
        g_Vertices[k].color = D3DCOLOR_XRGB(0, 255, 0);
    }
        // et la dernière
    for (k = 3564; k < 3600; k++)
    {
        g_Vertices[k].color = D3DCOLOR_XRGB(255, 0, 0);
    }

Si quelqu'un a une solution ou une idée pour réglé je suis preneur !

~~ Cordialement Francois Gingras
0
Rejoignez-nous