Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1518 connectés 

  FORUM HardWare.fr
  Programmation
  C++

  probleme 3D opengl

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

probleme 3D opengl

n°2112695
encours
Posté le 22-11-2011 à 08:21:13  profilanswer
 

bonjour
je travaille avec opengl avec visual studion 2010
je travaille en 3D
j'ai crée un carré rouge sur la surface et je veux mettre sur ce carré un triangle jaune mais lorsque j'affiche le triangle ne se colore pas bien avec le jaune : je sais pas pourquoi  
voici le code  
est ce que vous avez une idée  
merci

Code :
  1. #include "stdafx.h"
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <time.h>
  5. #include <Windows.h>
  6. #include <GL/glut.h>
  7. /* l'heure systeme
  8. SYSTEMTIME Time;
  9.      
  10.     GetLocalTime(&Time);
  11.      
  12.     printf("Nous sommes le : %02d/%02d/%04d.\n",
  13.     Time.wDay, Time.wMonth, Time.wYear);
  14.  
  15.     printf("Et il est : %02dh %02dmn %02ds %03dms.\n",
  16.     Time.wHour, Time.wMinute, Time.wSecond, Time.wMilliseconds);
  17. */
  18. static void key(unsigned char k, int x, int y)
  19. {
  20.   switch (k) {
  21.   case 27:  //Echaper
  22.     exit(0);
  23.     break;
  24.   default:
  25.     return;
  26.   }
  27.   glutPostRedisplay();
  28. }
  29. void drawTriangle (GLfloat x1, GLfloat y1, GLfloat x2,
  30.     GLfloat y2, GLfloat x3, GLfloat y3, GLfloat z)
  31. {
  32.    glBegin (GL_TRIANGLES);
  33.    glVertex3f (x1, y1, z);
  34.    glVertex3f (x2, y2, z);
  35.    glVertex3f (x3, y3, z);
  36.    glEnd ();
  37. }
  38. void Dessiner()
  39. {
  40. glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  41.     glMatrixMode( GL_MODELVIEW );
  42.     glLoadIdentity( );
  43.     gluLookAt(5.5,6.5,3,0,0,0,0,0,1);
  44. glColor3ub(255,0,0);
  45. glBegin(GL_QUADS);
  46.  glVertex3d(6,-6,0);
  47.  glVertex3d(-6,-6,0);
  48.  glVertex3d(-6,6,0);
  49.  glVertex3d(6,6,0);
  50. glEnd();
  51. glColor3f(0,1,0);
  52. drawTriangle(1.6,1.6,7,1.6,1.6,7,0);
  53. glColor3f(0,1,0);
  54. drawTriangle(-1.6,1.6,-7,1.6,-1.6,7,0);
  55. // les axes
  56. glColor3ub(255,0,255);
  57. glBegin(GL_LINES);
  58.  glVertex3d(1,0,0);
  59.  glVertex3d(0,0,0);
  60. glEnd();
  61. //
  62. glColor3ub(0,255,0);
  63. glBegin(GL_LINES);
  64.  glVertex3d(0,1,0);
  65.  glVertex3d(0,0,0);
  66. glEnd();
  67. //
  68. glColor3ub(0,255,255);
  69. glBegin(GL_LINES);
  70.  glVertex3d(0,0,1);
  71.  glVertex3d(0,0,0);
  72. glEnd();
  73. glFlush();
  74. }
  75. int main(int argc, char** argv)
  76. {
  77. glutInit(&argc, argv);
  78. //glutInitDisplayMode(  GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH );
  79. glutInitWindowSize(800,500);
  80. glutInitWindowPosition(50,50);
  81. glutCreateWindow("fenetre OpenGl" );
  82. glMatrixMode( GL_PROJECTION );
  83.     glLoadIdentity();
  84.     gluPerspective(40,(double)640/480,1,100);
  85.     glEnable(GL_DEPTH_TEST);
  86. glutDisplayFunc(Dessiner);
  87. //Dessiner();
  88. glutKeyboardFunc(key);
  89. glutMainLoop();
  90. return 0;
  91. }

mood
Publicité
Posté le 22-11-2011 à 08:21:13  profilanswer
 

n°2112713
chewif
Posté le 22-11-2011 à 10:27:39  profilanswer
 

Sans avoir lu avec precision, je constate que tous tes dessins sont dans le plan Z=0.
 
Tu as glEnable(GL_DEPTH_TEST), ce qui fait que tous les fragments comparent a ce qui a deja dans le Z buffer avant de decider si ils vont dessiner. Du fait de problemes d imprecision numerique tu peux ramasser des artefacts. http://en.wikipedia.org/wiki/Z-fighting
 
- Essaye de desactiver GL_DEPTH_TEST..
- Essaye d'eviter de dessiner plusieurs fois au meme endroit en 3D.
 
Bon courage.

n°2112836
encours
Posté le 22-11-2011 à 20:46:46  profilanswer
 

Citation :

Essaye d'eviter de dessiner plusieurs fois au meme endroit en 3D.


j'ai differer le z des triangle par un 0.01 et le probleme est reglé
 
 
merci bien


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  C++

  probleme 3D opengl

 

Sujets relatifs
Gros problème en Visual Basic...Problème image d'un header qui se décale sous IE
VBAccess Problème requête paramétrée Formulaireproblème chemin sur un simplewiewer
probleme structureProblème avec firefox et IE
[OpenGL] Problème d'aliasing entre les trianglesproblème exercice tableau
Problème étrange d'inclusion de header 
Plus de sujets relatifs à : probleme 3D opengl


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR