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

  FORUM HardWare.fr
  Programmation
  C++

  GLFW écran noir (si multi thread)

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

GLFW écran noir (si multi thread)

n°2294171
ptitchep
Posté le 31-12-2016 à 13:07:49  profilanswer
 

Bonjour,
 
J'ai un bout de code qui utilise GLFW et glew pour afficher de la 3D dans une
fenêtre. Honnêtement j'ai un peu copié/collé l'init pour pouvoir me concentrer
sur la partie opengl.
 
Mon code fonctionne très bien sur 2 machines différentes mais pas sur une
troisième. J'ai une distribution Archlinux à jour sur les 3 machines (donc
normalement tout pareil). La seule différence est que la 3ème possède une carte
graphique nvidia alors que les autres utilisent un chipset intégré intel.
 
Voici l'init:

Code :
  1. Afficheur::Afficheur(unsigned p_largeur,
  2.                      unsigned p_hauteur,
  3.                      const Carte& p_carte) throw(AFFICHEUR_ERREUR):
  4.     m_xcamera(p_carte.largeur() / 2),
  5.     m_ycamera(p_carte.hauteur() / 2),
  6.     m_zcamera(p_carte.largeur()),
  7.     m_xvisee(p_carte.largeur() / 2),
  8.     m_yvisee(p_carte.hauteur() / 2),
  9.     m_zvisee(0)
  10. {
  11.     if (!glfwInit())
  12.     {
  13.         std::cerr<<"Impossible de démarrer GLFW"<<std::endl;
  14.         throw AFFICHEUR_ERREUR_GLFW_INIT;
  15.     }
  16.     glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
  17.     glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
  18.     glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
  19.     glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  20.     glfwWindowHint(GLFW_SAMPLES, 8);
  21.     m_fenetre = glfwCreateWindow(p_largeur, p_hauteur, "Terrain", NULL, NULL);
  22.     if (!m_fenetre)
  23.     {
  24.         std::cerr<<"Impossible de créer la fenêtre"<<std::endl;
  25.         glfwTerminate();
  26.         throw AFFICHEUR_ERREUR_FENETRE_INIT;
  27.     }
  28.     glfwMakeContextCurrent(m_fenetre);
  29.     glewExperimental = GL_TRUE;
  30.     glewInit();
  31.     const GLubyte* renderer = glGetString(GL_RENDERER); // get renderer string
  32.     const GLubyte* version = glGetString(GL_VERSION); // version as a string
  33.     std::cout<<"Renderer: "<<renderer<<std::endl;
  34.     std::cout<<"OpenGL version supported "<<version<<std::endl;
  35.     glEnable(GL_DEPTH_TEST); // enable depth-testing
  36.     glDepthFunc(GL_LESS); // depth-testing interprets a smaller value as "closer"
  37.     m_afficheurCarte = new AfficheurCarte(p_carte);
  38.     m_stop = false;
  39.     m_thread = std::thread(&Afficheur::affichage, this, p_largeur, p_hauteur);


 
Et le thread d'affichage:

Code :
  1. void Afficheur::affichage(float p_largeur,
  2.                           float p_hauteur)
  3. {
  4.     glfwMakeContextCurrent(m_fenetre);
  5.     glm::mat4 projection = glm::perspective(100.0f, p_largeur / p_hauteur, 0.1f, 2000.0f);
  6.     glm::mat4 view;
  7.     // Model matrix : an identity matrix (model will be at the origin)
  8.     glm::mat4 model      = glm::mat4(1.0f);
  9.     // Our ModelViewProjection : multiplication of our 3 matrices
  10.     glm::mat4 MVP = projection * view * model;
  11.     glm::vec3 lightPos = glm::vec3(m_xcamera,m_ycamera,300);
  12.     while(!m_stop)
  13.     {
  14.         view = glm::lookAt(glm::vec3(m_xcamera, m_ycamera, m_zcamera),
  15.                            glm::vec3(m_xvisee, m_yvisee, m_zvisee),
  16.                            glm::vec3(0,-1,0));
  17.         MVP = projection * view * model;
  18.         titre();
  19.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  20.         m_afficheurCarte->affichage(MVP, model, view, lightPos);
  21.         glfwPollEvents();
  22.         glfwSwapBuffers(m_fenetre);
  23.     }
  24. }


 
Tout fonctionne bien sur les 2 premières machines mais sur la 3ème j'ai un
simple écran noir. À noter que la fonction titre() fonctionne tout de même (elle
affiche les fps dans la barre de titre).
 
Si je remplace:

Code :
  1. m_thread = std::thread(&Afficheur::affichage, this, p_largeur, p_hauteur);


Par:

Code :
  1. affichage(p_largeur, p_hauteur);


L'affichage fonctionne. Sauf que bien sûr je n'ai plus la main...
 
J'en déduis donc qu'il y a un problème avec le multithreading mais pourquoi sur
une seule machine? Et comment résoudre ça?
 
Merci.


---------------
deluser --remove-home ptitchep
mood
Publicité
Posté le 31-12-2016 à 13:07:49  profilanswer
 

n°2294175
xilebo
noone
Posté le 31-12-2016 à 19:05:17  profilanswer
 

c'est xorg derrière ? Il gère très mal le multithreading. Il me semble également qu'opengl est pas trop prévu pour faire du multithreading ( notamment le contexte opengl partagé entre thread ).

n°2294206
ptitchep
Posté le 02-01-2017 à 08:21:40  profilanswer
 

Oui en effet c'est du xorg.
Bon je vais initialiser tout ça autrement pour que tout soit dans le thread d'affichage.
 
Merci.


---------------
deluser --remove-home ptitchep

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

  GLFW écran noir (si multi thread)

 

Sujets relatifs
[C#] Capture d'écran en jeuThread et tkinter
Matlab : Comment afficher du texte (consigne) à l'écranChanger le fond d'écran à intervalle régulier
Requête SQL avec liaison multi-tables[projetCommun]c# multi bdd, datascience
script steam big picture + écran secondaireprogramme un écran à led
Convertir un fichier Swf en fichier pour "écran de veille sous WindowsConvertir un fichier Swf en fichier pour "écran de veille sous Windows
Plus de sujets relatifs à : GLFW écran noir (si multi thread)


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