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

OpenGL Discussion :

Problème d'appel des méthodes OpenGL


Sujet :

OpenGL

  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    465
    Détails du profil
    Informations personnelles :
    Localisation : France, Bas Rhin (Alsace)

    Informations forums :
    Inscription : Janvier 2007
    Messages : 465
    Points : 154
    Points
    154
    Par défaut Problème d'appel des méthodes OpenGL
    Salut tout le monde :
    En fait j'ai un probème (je crois de programmation).
    J'ai deux classes, une classe (appelée PolyLine)qui permet de dessiner une forme géométrique (triangle, rectangle, polygone...), et une autre classe (appelée Scene3D) qui contient la méthode main() ainsi que toutes les méthodes OpenGL (init, display)...
    Dans la méthode display() de la classe Scne3D, j'appelle la méthode dessinerForme() de la classe PolyLine.
    En déssinant un cube, j'obtient toutes les faces du cube l'une dèrrière l'autre avec un rendu un peu bizarre (j'obtiend pas un cube).
    Je sais pas d'où vient le problème sachant que j'ai bien vérifié les coordonnées des six faces du cube.

  2. #2
    Membre habitué Avatar de Harooold
    Homme Profil pro
    Ingénieur 3D temps réel
    Inscrit en
    Mars 2008
    Messages
    136
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Ingénieur 3D temps réel
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2008
    Messages : 136
    Points : 177
    Points
    177
    Par défaut
    Salut,

    Un peu de code ne ferait pas de mal, on ne peut pas trop deviner tes erreurs
    Reflechir peut s'averer utile, sisi.

  3. #3
    Membre habitué
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    465
    Détails du profil
    Informations personnelles :
    Localisation : France, Bas Rhin (Alsace)

    Informations forums :
    Inscription : Janvier 2007
    Messages : 465
    Points : 154
    Points
    154
    Par défaut
    Voilà la méthode qui permet de dessiner une formes géométrique
    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
     
    public void drawPolyLine(GL gl, String form,float ColorFirstCoord,float ColorSecondCoord,float ColorThirdCoord,Boolean IsTextured, String TextureURL, float TextureCoords[][], float x, float y, float z, double RotationAngle)
    {
     
    	//gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);       //Clear The Screen And The Depth Buffer
        //gl.glLoadIdentity();   	                                     //Reset The View
        gl.glRotatef((float) -RotationAngle,1,0,0);
        gl.glTranslatef(x,y,z-2);
     
        gl.glEnable(GL.GL_TEXTURE_2D);
        TextureLoader.Texture tex1 = null;
     
     
    	// 1) We test if there is no texture for the polyline
    	if (TextureURL == null)
     
        {
    	   // 1.1) We draw a Triangle
    	   if(form.toUpperCase().equals("TRIANGLE"))
    	   {
    		   // We begin drawing the Triangle
    		    gl.glBegin(GL.GL_TRIANGLES);
    			gl.glNormal3f(0,0,1.0f);
     
    			// if the ColorFirstCoord is not -100 (is not null), we define the color for the Triangle
    			if (ColorFirstCoord !=-100)
    			{	
    			  gl.glColor3f(ColorFirstCoord,ColorSecondCoord,ColorThirdCoord) ;
    			}
     
    	    for (int i=0;i< 3;i++)
    	    { 
    	    	gl.glVertex3f(getPoint(i,ThePolyLinePoints).getX(),getPoint(i,ThePolyLinePoints).getY(),getPoint(i,ThePolyLinePoints).getZ());	
    	    }
    	        gl.glEnd();
    	   }
     
    	   // 1.2) We draw a Quad
    	   if(form.toUpperCase().equals("QUADS"))
    	   {
     
    		gl.glBegin(GL.GL_QUADS);
    		gl.glNormal3f(0,0,1.0f);
     
    		// if the ColorFirstCoord is not -100 (is not null), we define the color for the quad
    		if (ColorFirstCoord !=-100)
    		{	
    		  gl.glColor3f(ColorFirstCoord,ColorSecondCoord,ColorThirdCoord) ;
    		}
     
    	    for (int i=0;i<4;i++)
    	    {   
    	    	gl.glVertex3f(getPoint(i,ThePolyLinePoints).getX(),getPoint(i,ThePolyLinePoints).getY(),getPoint(i,ThePolyLinePoints).getZ());
    	    }
    	    gl.glEnd();
    	    }
     
    	   // 1.3) We draw a Polygon
    	   if(form.toUpperCase() == "POLYGON")
    	   {
    		gl.glBegin(GL.GL_POLYGON);
    		gl.glBegin(GL.GL_TRIANGLES);
    	    for (int i=0;i< ThePolyLinePoints.size();i++)
    	    { 
    	    	gl.glVertex3f(getPoint(i,ThePolyLinePoints).getX(),getPoint(i,ThePolyLinePoints).getY(),getPoint(i,ThePolyLinePoints).getZ());	
    	    }
    	    gl.glEnd();
    	    }
        }
     
    	// 2) If the polygone have a texture 
    	else
    	{
    		try 
            {
    	      tex1 = TextureLoader.readTexture(TextureURL);
            } 
            catch(IOException e) 
            {
    	      System.err.println("Unable to load texture : "+ TextureURL);
            }
            if( tex1 != null )
    	     PolyLineTexture = tex1.toGL(gl,glu,false);
             else
    	     PolyLineTexture = -1;
     
     
            // 2.1) We draw a Triangle 
            if(form.toUpperCase().equals("TRIANGLE"))
     	   {
     		    gl.glBindTexture(GL.GL_TEXTURE_2D, PolyLineTexture);
            	gl.glBegin(GL.GL_TRIANGLES);
        		gl.glNormal3f(0,0,1.0f);
     
     
     	    for (int i=0;i< 3;i++)
     	    { 
     	    	gl.glTexCoord2d(TextureCoords[i][0],TextureCoords[i][1]);
     	    	gl.glVertex3f(getPoint(i,ThePolyLinePoints).getX(),getPoint(i,ThePolyLinePoints).getY(),getPoint(i,ThePolyLinePoints).getZ());	
     	    }
     	    gl.glEnd();
     	    }
     
         // 2.2) We draw a Quad
     	   if(form.toUpperCase().equals("QUADS"))
     	   {
     	    gl.glBindTexture(GL.GL_TEXTURE_2D, PolyLineTexture);
     		gl.glBegin(GL.GL_QUADS);
     		//gl.glNormal3f(0,0,1.0f);
     	    for (int i=0;i<4;i++)
     	    {   
     	    	gl.glTexCoord2d(TextureCoords[i][0],TextureCoords[i][1]);
     	    	gl.glVertex3f(getPoint(i,ThePolyLinePoints).getX(),getPoint(i,ThePolyLinePoints).getY(),getPoint(i,ThePolyLinePoints).getZ());
     	    }
     	    gl.glEnd();
     	    }
     	   // 2.3) We draw a Polygon
     	   if(form.toUpperCase() == "POLYGON")
     	   {
     		gl.glBindTexture(GL.GL_TEXTURE_2D, PolyLineTexture);
     		gl.glBegin(GL.GL_POLYGON);
     	    for (int i=0;i< ThePolyLinePoints.size();i++)
     	    { 
     	    	gl.glTexCoord2d(TextureCoords[i][0],TextureCoords[i][1]);
     	    	gl.glVertex3f(getPoint(i,ThePolyLinePoints).getX(),getPoint(i,ThePolyLinePoints).getY(),getPoint(i,ThePolyLinePoints).getZ());	
     	    }
     	    gl.glEnd();
     	    }
    	 }
     
     
    } // End drawPolyLine method
    et voilà comment j'appelle cette méthode dans la méthode display() de la classe contenant la méthode main():
    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
     
    PolyLine polygon1= new PolyLine();
    	Point p1=new Point(-0.5f, -0.5f, 0.5f);
    	Point p2=new Point(0.5f, -0.5f, 0.5f);
    	Point p3=new Point(0.5f, 0.5f, 0.5f);
    	Point p4=new Point(-0.5f, 0.5f, 0.5f);
    	polygon1.addPoint(p1);
    	polygon1.addPoint(p2);
    	polygon1.addPoint(p3);
    	polygon1.addPoint(p4);
    	float [][]TextureCoords = new float[4][2];
        TextureCoords[0][0]=0;
    	TextureCoords[0][1]=0;
    	TextureCoords[1][0]=1;
    	TextureCoords[1][1]=0;
    	TextureCoords[2][0]=1;
    	TextureCoords[2][1]=1;
    	TextureCoords[3][0]=0;
    	TextureCoords[3][1]=1;
     
    	polygon1.drawPolyLine(gl, "QUADS",-100,-100,-100,true,"Data/mur2.png",TextureCoords,x, y, z-2,angle);
     
    	// Back face
    	PolyLine polygon2= new PolyLine();
    	Point p5=new Point(-0.5f, -0.5f, -0.5f);
    	Point p6=new Point(0.5f, -0.5f, -0.5f);
    	Point p7=new Point(0.5f, 0.5f, -0.5f);
    	Point p8=new Point(-0.5f, 0.5f, -0.5f);
    	polygon2.addPoint(p5);
    	polygon2.addPoint(p6);
    	polygon2.addPoint(p7);
    	polygon2.addPoint(p8);
     
    	polygon2.drawPolyLine(gl, "QUADS",-100,-100,-100,true,"Data/mur2.png",TextureCoords,x, y, z-2,angle);
     
    	// Top face
    	PolyLine polygon3= new PolyLine();
     
    	polygon3.addPoint(p4);
    	polygon3.addPoint(p3);
    	polygon3.addPoint(p7);
    	polygon3.addPoint(p8);
     
    	polygon3.drawPolyLine(gl, "QUADS",-100,-100,-100,true,"Data/gazon.png",TextureCoords,x, y, z-2,angle);
     
    	float [][]TextureCoords2 = new float[3][2];
     
    	TextureCoords2[0][0]=0;
    	TextureCoords2[0][1]=0;
    	TextureCoords2[1][0]=1;
    	TextureCoords2[1][1]=0;
    	TextureCoords2[2][0]=0.5f;
    	TextureCoords2[2][1]=1;
     
    	PolyLine polygon4= new PolyLine();
    	Point p9=new Point(0, 1, 0.5f);
    	polygon4.addPoint(p4);
    	polygon4.addPoint(p3);
    	polygon4.addPoint(p9);
     
    	Point p10=new Point(-0.5f, 1, 0.5f);
    	Point p11=new Point(0.5f, 1, 0.5f);
    	//polygon4.addPoint(p4);
    	//polygon4.addPoint(p3);
    	//polygon4.addPoint(p11);
    	//polygon4.addPoint(p10);
     
    	polygon4.drawPolyLine(gl, "TRIANGLE",-100,-100,-100,true,"Data/mur2.png",TextureCoords2,x, y, z-2,angle);
     
    	drawFloor(gl,true);

  4. #4
    Membre habitué Avatar de Harooold
    Homme Profil pro
    Ingénieur 3D temps réel
    Inscrit en
    Mars 2008
    Messages
    136
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Ingénieur 3D temps réel
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2008
    Messages : 136
    Points : 177
    Points
    177
    Par défaut
    Ton code est dur à lire, c'est pas super organisé tout ça

    En le survolant, j'ai 2 questions :

    1) Si tu veux dessiner un cube, pourquoi n'as tu que 4 faces ?
    2) Si tu veux dessiner un cube, pourquoi as tu besoin de 11 points ?

    Juste avec p1 jusqu'a p8 tu peux dessiner les 6 faces de ton cube.
    Tes p9 p10 p11 me semblent vraiment louches :p
    Reflechir peut s'averer utile, sisi.

  5. #5
    Membre habitué
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    465
    Détails du profil
    Informations personnelles :
    Localisation : France, Bas Rhin (Alsace)

    Informations forums :
    Inscription : Janvier 2007
    Messages : 465
    Points : 154
    Points
    154
    Par défaut
    1) Si tu veux dessiner un cube, pourquoi n'as tu que 4 faces ?
    En fait c'est un essai de mes méthodes, donc j'ai déssiné une face d'avant, une face d'arrière, une face de droite et une face de dessus.
    2) Si tu veux dessiner un cube, pourquoi as tu besoin de 11 points ?
    T'as raison, j'ai besoin uniquement de 8 points, et les trois autres points sont pour faire quelques tests supplimentaires.

    Tu vois que mon code est un peu compliqué, j'ai organisé mon projet en certaines classes. Le plus important pour moi est que le dessin de mes formes soit paramétré et les coordonnées sont importées dynamiquement d'une Base de Données.Voilà.

  6. #6
    Membre habitué
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    465
    Détails du profil
    Informations personnelles :
    Localisation : France, Bas Rhin (Alsace)

    Informations forums :
    Inscription : Janvier 2007
    Messages : 465
    Points : 154
    Points
    154
    Par défaut
    J'ai trouvé l'erreur, j'ai oublié d'appeler la méthode glLoadIdentity() dans la méthode drawPolyLine().
    Merci Harooold

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. probléme dans l'appel des méthodes
    Par saraenim dans le forum Windows Forms
    Réponses: 5
    Dernier message: 07/04/2008, 09h20
  2. Problèmes d'appels de méthodes
    Par parano dans le forum C++
    Réponses: 7
    Dernier message: 07/03/2007, 12h08
  3. Héritage : problème d'appel de méthodes
    Par parano dans le forum C++
    Réponses: 15
    Dernier message: 02/03/2007, 14h42
  4. problème d'affichage des scènes OpenGL
    Par franc82 dans le forum OpenGL
    Réponses: 4
    Dernier message: 02/01/2007, 10h11
  5. Problème pour appeler une méthode d'une autre classe
    Par tse_tilky_moje_imja dans le forum Général Python
    Réponses: 7
    Dernier message: 03/03/2006, 13h33

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