Bonjour,

Je suis débutant en OpenGL et je code en C#. J'essais de faire un jeu de pichenotte en 3D.

Je me suis fait une librairie basé sur l'exemple de la lesson 31 de Nehe. Elle sert à charger un objet MilkShape.

http://nehe.gamedev.net/data/lessons....asp?lesson=31

Lorsque je dessine mon objet MilkShape, j'ai une dégradation des performances. J'ai vérifier le temps que prend l'objet à se dessiner, parfois 0 ou 15 à 16 ms. Je trouve que c'est énorme pour un objet qui comprend 216 triangle, à moins que ca soit normal mais je ne crois pas.

J'ai effectuer quelque test et j'ai remarquer que lorsque j'enlevais l'appel à glNormal, je tombais à 0 ms plus souvent que 15 à 16 ms.

Avec 1 objet j'obtient 62 à 66 fps mais lorsque j'ai 5 objets j'obtient 12 à 21 fps. Je suis désespéré, je cherche depuis 2 semaine à trouver le moyen de rendre le tout fluide parce qu'il va devoir y avoir 30 objets.

voici le code pour afficher l'objet
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
 
public override void Draw()
{
            GL.glPushMatrix();
            GL.glTranslatef(posX, posY, posZ);
            GL.glRotatef(xRot, 1.0f, 0.0f, 0.0f);
            GL.glRotatef(yRot, 0.0f, 1.0f, 0.0f);
            GL.glRotatef(zRot, 0.0f, 0.0f, 1.0f);
            GL.glScaled(sX, sY, sZ);
 
            MS3DTriangle pTri;
            int index;
            int triangleIndex;
            for (int i = 0; i < obj.Mesh.Length; i++)
            {
                GL.glBegin(GL.GL_TRIANGLES);
                {
                    for (int j = 0; j < obj.Mesh[i].nbTriangles; j++)
                    {
                        pTri = obj.Triangles[obj.Mesh[i].indicesTriangle[j]];
 
                        for (int k = 0; k < 3; k++)
                        {
                            GL.glNormal3fv(pTri.normals[k]);
                            GL.glVertex3fv(obj.Vertex[pTri.indices[k]].location);
                        }
                    }
                }
                GL.glEnd();
            }
 
            GL.glPopMatrix();
        }
}
MS3DTriangle
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
 
namespace Model
{
    public struct MS3DTriangle
    {
        public float[][] normals;
        public float[] s;
        public float[] t;
        public int[] indices;
 
        public MS3DTriangle(float[][] n, float[] s, float[] t,int[] ind)
        {
            normals = n;
 
            this.s = s;
            this.t = t;
            indices = ind;
        }
    }
}
obj.Mesh : Représente l'objet qui est charger en mémoire.

Code de la méthode Paint
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
 
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
 
GL.glMatrixMode(GL.GL_MODELVIEW);
GL.glLoadIdentity();
 
GLU.gluLookAt(XCam, 80, 80, 0, 0, 0, 0, 1, 0);
GL.glRotatef(YCam, 0.0f, 1.0f, 0.0f);
GL.glRotatef(ZCam, 0.0f, 0.0f, 1.0f);
 
GL.glColor3f(0.7f, 0.0f, 0.0f);
pichenotteRouge.Rotate(xRot, yRot, 0.0f);
pichenotteRouge.Scale(2.0, 2.0, 2.0);
pichenotteRouge.Draw();
 
GL.glFlush();
WGL.wglSwapBuffers(m_uint_DC);
Je crois que c'est le principal. Pour le chargement du model c'est pareil comme dans le tutorial de Nehe sauf que c'est en C#.

Pour le moment je tient seulement compte d'un objet sans matériel.

J'utilise le double buffer également
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
 
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, false);
this.SetStyle(ControlStyles.UserPaint, true);
et j'utilise le clavier pour déplacer la caméra
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
 
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
     if (e.KeyCode == Keys.Home)
           YCam += 1.0f;
 
     if (e.KeyCode == Keys.End)
           YCam -= 1.0f;
 
     if (e.KeyCode == Keys.Delete)
           XCam -= 1.0f;
 
     if (e.KeyCode == Keys.PageDown)
           XCam += 1.0f;
 
     if (e.KeyCode == Keys.Add)
           ZCam -= 1.0f;
 
     if (e.KeyCode == Keys.Subtract)
           ZCam += 1.0f;
 
     this.Invalidate();
}
Voyez-vous quelque chose qui n'est pas correcte?

DestinyWar