Problème avec les polygones

nisaloncaje Messages postés 154 Date d'inscription samedi 7 janvier 2006 Statut Membre Dernière intervention 28 septembre 2008 - 24 juin 2006 à 21:17
nisaloncaje Messages postés 154 Date d'inscription samedi 7 janvier 2006 Statut Membre Dernière intervention 28 septembre 2008 - 28 janv. 2007 à 18:31
Bonjour, j'ai le code source suivant :

#include <GL/glut.h>
#include <stdlib.h>


double a=0,inca=0.1;


/* Prototype des fonctions */
void affichage();
void clavier(unsigned char touche,int x,int y);
void reshape(int x,int y);
void idle();


int main(int argc,char **argv)
{
  /* initialisation de glut et creation
     de la fenetre */
  glutInit(&argc,argv);
  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
  glutInitWindowPosition(200,200);
  glutInitWindowSize(500,500);
  glutCreateWindow("Numéro 1");


  /* Initialisation d'OpenGL */
  glClearColor(0.0,0.0,0.0,0.0);
 
  glShadeModel(GL_FLAT);


  /* enregistrement des fonctions de rappel */
  glutDisplayFunc(affichage);
  glutKeyboardFunc(clavier);
  glutReshapeFunc(reshape);
  glutIdleFunc(idle);


  /* Entree dans la boucle principale glut */
  glutMainLoop();
  return 0;
}


void affichage()
{


  glClear(GL_COLOR_BUFFER_BIT);
 
  glLoadIdentity();
  glTranslatef(0.0,-0.5,0.0);
  glRotatef(10.0,1.0,0.0,0.0);
  glRotatef(a,0.0,1.0,0.0);


  glBegin(GL_POLYGON);
  glColor3f(0.0,1.0,1.0);
  glVertex3f( 0.0, 0.0, 0.0);
  glVertex3f( 0.1, 0.0, 0.0);
  glVertex3f( 0.1, 0.8, 0.0);
  glVertex3f( 0.0, 0.8, 0.0);
  glVertex3f(-0.2, 0.7, 0.0);
  glVertex3f(-0.2, 0.6, 0.0);
  glVertex3f( 0.0, 0.7, 0.0);
  glVertex3f( 0.0, 0.0, 0.0);
  glEnd();
 
  glFlush();
  glutSwapBuffers();
}


void clavier(unsigned char touche,int x,int y)
{
  switch (touche)
    {
    case 'q' :
    exit(0);
    break;
     
    case 'a':
    glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
    break;
   
    case 'z':
    glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
    break;  
   
    }
}


void reshape(int x,int y)
{
  if (x<y)
    glViewport(0,(y-x)/2,x,x);
  else
    glViewport((x-y)/2,0,y,y);
}


void idle()
{
  a+=inca;
  if (a>360)
    a-=360;


  glutPostRedisplay();
}

Cependant, comme vous pouvez le voir si vous le compiler, quand on est en mode fil de fer, on obtient le chiffre 1 alors que quand on est en mode remplissage, on obtient une autre chose "bizarre"
 Comment faire pour obtenir en mode remplissage un 1 correctement rempli ?

Merci d'avance

NC

2 réponses

cs_tibur Messages postés 101 Date d'inscription samedi 9 février 2002 Statut Membre Dernière intervention 5 mai 2009
28 janv. 2007 à 18:05
glBegin(GL_POLYGON) est fait pour dessiner un polygone convexe. Or ton 1 n'est pas convexe. Si je me souviens bien, un polygone convexe est un polygone tel que si tu prends 2 points a,b du polygone, le segment AB ne sort pas du polygone.
La solution consiste à decouper ton 1 en triangles.
A+
0
nisaloncaje Messages postés 154 Date d'inscription samedi 7 janvier 2006 Statut Membre Dernière intervention 28 septembre 2008
28 janv. 2007 à 18:31
salut !!!

Merci, mais cela fait presque un an que j'avais posté ce message :)
0
Rejoignez-nous