Afficher un point en opengl

Résolu
dmk04 Messages postés 206 Date d'inscription samedi 29 octobre 2005 Statut Membre Dernière intervention 7 mars 2012 - 19 mai 2006 à 11:25
dmk04 Messages postés 206 Date d'inscription samedi 29 octobre 2005 Statut Membre Dernière intervention 7 mars 2012 - 19 mai 2006 à 19:09
Bonjour,

je commence l'opengl et je n'arrive pas à afficher un point.
J'ulise le code suivant :

#include <stdio.h>
#include <GL\glut.h>

void renderScene(void) {
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}

void afficherPoint(float x, float y)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0f,0.0f,0.0f);

glBegin(GL_POINTS);
glVertex2f(x,y);
glEnd();

glFlush();
}

void main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(500,500);
glutCreateWindow("Afficher un point");
glClearColor(1,1,1,1);
glutDisplayFunc(renderScene);
afficherPoint(0,0);
glutMainLoop();
}

Si je demande à afficher mon point depuis renderScene ça marche mais pas depuis afficherPoint.

Merci pour votre aide

A+

7 réponses

Alcantornet Messages postés 89 Date d'inscription mardi 8 février 2005 Statut Membre Dernière intervention 14 novembre 2007
19 mai 2006 à 17:03
Tu peux utiliser les lists d'affichage, exemple (Testé sous dev-cpp):

#include <stdio.h>
#include <GL\glut.h>

int idList;

void renderScene(void) {
  glClear(GL_COLOR_BUFFER_BIT);
  glColor3f(0.0f,0.0f,0.0f);
  glCallList(idList); // Affiche toute la liste
  glFlush();
}

void addPoint(float x, float y){
    glBegin(GL_POINTS);
      glVertex2f(x,y);
    glEnd();
}

void main(int argc, char **argv) {
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA);
  glutInitWindowPosition(100,100);
  glutInitWindowSize(500,500);
  glutCreateWindow("Afficher un point");
  glClearColor(1,1,1,1);
 
  idList = glGenLists(1);
  glNewList(idList,GL_COMPILE); // Commence une liste de dessin
 
  addPoint(0, 0);
  addPoint(.2, .2);
  addPoint(-.2, .2);
  addPoint(.2, -.2);
  addPoint(-.2,-.2);
 
  glEndList(); // Une fois tous les points ajouté,
               // on termine la liste
 
  glutDisplayFunc(renderScene);
  glutMainLoop();
}
3
luhtor Messages postés 2023 Date d'inscription mardi 24 septembre 2002 Statut Membre Dernière intervention 28 juillet 2008 6
19 mai 2006 à 11:32
Bas c'est normal, dans ta fonction renderscene tu dis de rien n'afficher. Revois le fonctionnement de glut.

Mets ta fonction afficherPoint(0,0); dans renderscene.
0
dmk04 Messages postés 206 Date d'inscription samedi 29 octobre 2005 Statut Membre Dernière intervention 7 mars 2012
19 mai 2006 à 11:38
Mon soucis en fait, c'est que renderScene ne prend  pas de paramètres, et on ne peut pas passer une fonction avec paramètres à la fonction glutDisplayFunc.
Merci
A+
0
luhtor Messages postés 2023 Date d'inscription mardi 24 septembre 2002 Statut Membre Dernière intervention 28 juillet 2008 6
19 mai 2006 à 12:25
Mais tu vois un pb la ou il y en a pas:

Pour afficher un truc avec opengl, faut lui demander a chaque frame !
c'est pas un fonctionnement style paint ou style librairie basique.


void renderScene(void) {

glClear(GL_COLOR_BUFFER_BIT);


afficherPoint(0,0);


glFlush();

}


void afficherPoint(float x, float y)

{

glBegin(GL_POINTS);

glVertex2f(x,y);

glEnd();

}


void main(int argc, char **argv) {

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA);

glutInitWindowPosition(100,100);

glutInitWindowSize(500,500);

glutCreateWindow("Afficher un point");

glClearColor(1,1,1,1);

glutDisplayFunc(renderScene);

glutMainLoop();

}
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
dmk04 Messages postés 206 Date d'inscription samedi 29 octobre 2005 Statut Membre Dernière intervention 7 mars 2012
19 mai 2006 à 13:44
Moi je voudrais pouvoir ajouter des points en appelant une fonction, dans ce cas les coordonnées sont fixées.
glutDisplayFunc n'est apparament pas la fonction appropriée. Connaitrais-tu une fonction qui correspondrait mieux à ce que je recherche ?
Merci,
A+
0
dmk04 Messages postés 206 Date d'inscription samedi 29 octobre 2005 Statut Membre Dernière intervention 7 mars 2012
19 mai 2006 à 13:52
Mal exprimé, je reprends ma première phrase :


Moi je voudrais pouvoir ajouter des points en appelant une fonction, et avec glutDisplayFunc les coordonnées sont fixées. On ne peut pas rajouter des points au fur et à mesure ?

Merci
A+
0
dmk04 Messages postés 206 Date d'inscription samedi 29 octobre 2005 Statut Membre Dernière intervention 7 mars 2012
19 mai 2006 à 19:09
Ok, merci ;)

A+
0
Rejoignez-nous