summaryrefslogtreecommitdiff
path: root/2005
diff options
context:
space:
mode:
authorgaillaro2005-04-05 18:38:17 +0000
committergaillaro2005-04-05 18:38:17 +0000
commit79229eabb3cfedde010d4819a69f6890a234a2e1 (patch)
tree1b43d2f30dab3feedcde72287ebb8042b36aaee8 /2005
parent877c222c6403097ee7ea204e6b20cca5be000dfe (diff)
ajout d'un fichier d'interface
Diffstat (limited to '2005')
-rw-r--r--2005/i/robert/src/ovision/ui/liveView.cc174
1 files changed, 174 insertions, 0 deletions
diff --git a/2005/i/robert/src/ovision/ui/liveView.cc b/2005/i/robert/src/ovision/ui/liveView.cc
new file mode 100644
index 0000000..f80dc7b
--- /dev/null
+++ b/2005/i/robert/src/ovision/ui/liveView.cc
@@ -0,0 +1,174 @@
+#include <GL/glut.h> // Header File For The GLUT Library
+#include <GL/gl.h> // Header File For The OpenGL32 Library
+#include <GL/glu.h> // Header File For The GLu32 Library
+#include <iostream>
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <signal.h>
+
+#include "adjust.hh"
+#include "live.hh"
+
+using namespace std;
+
+#define IMG_WIDTH 360
+#define IMG_HEIGHT 296
+#define WIDTH 718
+#define HEIGHT 592
+int window;
+Live *live;
+int width=538; int height=395;
+static const unsigned nbImg = 4;
+
+/// Chargement d'une texture a partir de donnees RGB
+unsigned int
+loadImage(int width, int height, unsigned char *data, unsigned int lastTex)
+{
+ GLuint tex;
+ if (glIsTexture(lastTex)) glDeleteTextures(1, &lastTex);
+ // Mode de chargement des donnees
+ glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
+ // Creer une id pour stocker l'image
+ glGenTextures(1, &tex);
+ glBindTexture(GL_TEXTURE_2D, tex);
+ // Stocke l'image
+ //glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
+ gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE, data);
+ // Config des parametres
+ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
+ // Retourne l'id de l'image
+ return tex;
+}
+
+/// Initialisation des fonctions OpenGL
+void
+initGL(int width, int height)
+{
+ // Initialisation du mode d'affichage
+ glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+ // Mode de chargement des donnees
+ glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
+ glShadeModel(GL_FLAT);
+ glEnable(GL_TEXTURE_2D);
+ // Remise a zero de la matrice de projection
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ // Plan de projection en 2D
+ glOrtho(0.0, WIDTH, 0.0, HEIGHT, -1.0, 1.0);
+ glMatrixMode(GL_MODELVIEW);
+}
+
+
+
+/// Redimenssionement d'une fenetre
+void
+reSizeGLScene(int w, int h)
+{
+ // Evite div par 0
+ if (height==0) h=1;
+ height = h;
+ width = w;
+ // Initialise le point de vue
+ glViewport(0, 0, w, h);
+ glMatrixMode(GL_PROJECTION);
+ // Remise a zero et mode 2D
+ glLoadIdentity();
+ glOrtho(0.0, WIDTH, 0.0, HEIGHT, -1.0, 1.0);
+ glMatrixMode(GL_MODELVIEW);
+}
+
+
+/// Affiche une image
+/// @param texId numero de la texture a afficher
+void
+drawImage(GLuint texId)
+{
+ int wMin, wMax;
+ int hMin, hMax;
+ // Selection de l'image
+ glBindTexture(GL_TEXTURE_2D, live->tex[texId]);
+ // Calcul des coordonnees de l'image
+ wMin = BORDER+(texId%3)*(352+BORDER);
+ wMax = 352+BORDER+(texId%3)*(352+BORDER);
+ hMin = HEIGHT-288-BORDER-(int)(texId/3)*(288+BORDER);
+ hMax = HEIGHT-BORDER-(int)(texId/3)*(288+BORDER);
+ // Dessine un carre contenant l'image
+ glBegin(GL_QUADS);
+ glNormal3f( 0.0f, 0.0f, 1.0f);
+ glColor3f(1.0f,1.0f,1.0f);
+ glTexCoord2f(0.0f, 0.0f); glVertex3f(wMax, hMax, -1.0f);
+ glTexCoord2f(1.0f, 0.0f); glVertex3f(wMin, hMax, -1.0f);
+ glTexCoord2f(1.0f, 1.0f); glVertex3f(wMin, hMin, -1.0f);
+ glTexCoord2f(0.0f, 1.0f); glVertex3f(wMax, hMin, -1.0f);
+ glEnd();
+}
+
+
+/// Dessine les images a l'ecran
+void
+drawGLScene()
+{
+ // Efface le buffer
+ glClear(GL_COLOR_BUFFER_BIT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ // Affiche toutes les images
+ for (unsigned i=0; i<nbImg; i++)
+ drawImage(i);
+ glFlush();
+ // Affiche le buffer suivant
+ glutSwapBuffers();
+}
+
+
+/// Interruptions du clavier
+void
+keyPressed(unsigned char key, int x, int y)
+{
+ // Touche Echap
+ if (key == 27)
+ {
+ glutDestroyWindow(window);
+ exit (0);
+ }
+ if (key == ' ')
+ {
+ live->updateImg ("shots/quille1.rgb");
+ drawGLScene ();
+ }
+ if (key == 'r')
+ live->reloadConfig ("rc/vision.conf");
+}
+
+/// Gestion souris
+void
+mouseFunc(int button, int state, int x, int y)
+{
+}
+
+/// Fonction principale
+int
+main(int argc, char **argv)
+{
+ // Initialisation de l'OpenGL
+ glutInit(&argc, argv);
+ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
+ glutInitWindowSize(width, height);
+ glutInitWindowPosition(0, 0);
+ window = glutCreateWindow("liveCam - APBteam");
+ glutDisplayFunc(&drawGLScene);
+ glutReshapeFunc(&reSizeGLScene);
+ glutKeyboardFunc(&keyPressed);
+ glutMouseFunc(&mouseFunc);
+ initGL(WIDTH, HEIGHT);
+
+ live = new Live (nbImg);
+ live->init ("shots/test.rgb");
+
+ // Boucle principale
+ glutMainLoop();
+
+ return 1;
+}