Problème Glut et Xcode

nedoura

Membre enregistré
23 Avril 2011
3
0
36
Tunisie
Bonjour à tous,

Je suis débutante en Open GL, c'est pour ça j'ai un grand problème avec le langage C et Glut, j'ai un code à executer avec Xcode qui prend une image en paramètres, lorsque je fais l'execution sous le terminal en tapant cette commande ./projetVisua ciel.bmp
(ciel.bmp: l'image que je passe en parametre) il m'affiche rien. je ne sais pas c'est quoi exactement le problème,
Voici mon code main.c





#include <unistd.h>
#include <stdio.h>
#include <math.h>
#include "bmp.h"

#include <GLUT/glut.h>
Image *image;

#define ESCAPE 27


void
Keyboard(unsigned char key, int x, int y)
{
switch(key){
case ESCAPE :
exit(0);
break;
default:
fprintf(stderr, "Unused key\n");
}
}


void
Mouse(int button, int state, int x, int y){

switch(button){
case GLUT_LEFT_BUTTON:
break;
case GLUT_MIDDLE_BUTTON:
break;
case GLUT_RIGHT_BUTTON:
break;
}
glutPostRedisplay();
}


int
Init(char *s){

image = (Image *) malloc(sizeof(Image));
if (image == NULL) {
fprintf(stderr, "Out of memory\n");
return(-1);
}
if(strstr(s,".bmp")!=NULL){
if (ImageLoad(s, image)==-1) return(-1);
}
else if(strstr(s,".sci")!=NULL){
if (ImageLoadSCI(s, image)==-1) return(-1);
}

glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glutReshapeWindow(image->sizeX, image->sizeY);

return (0);
}

void
Display(void){

GLint w, h;

glClear(GL_COLOR_BUFFER_BIT);

w = glutGet(GLUT_WINDOW_WIDTH);
h = glutGet(GLUT_WINDOW_HEIGHT);
glDrawPixels(image->sizeX, image->sizeY, GL_RGB, GL_UNSIGNED_BYTE,
image->data);

glFlush();
}

void Reshape(int w, int h){
glViewport(0, 0, (GLsizei)w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, (GLdouble) w, 0.0, (GLdouble)h);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void menuFunc(int item){
char s[256];
switch(item){
case 0:
printf("Taille de l image : %ld %ld\n", image->sizeX, image->sizeY);
break;
case 2:
printf("GRIS \n");
gris(image);
break;
case 7:
printf("Vert ajoute \n");
vert1(image);
break;
case 8:
printf("Vert par soustraction\n");
printf("Fonction a ecrire !\n");
vert2(image);
break;
case 3:
printf("Entrer le nom \n");
scanf("%s", &s[0]);
Init(s);
break;
case 4:
printf("Entrer le nom pour l'image dans cette taille\n");
scanf("%s", &s[0]);
if(strstr(s,".bmp")!=NULL)
ImageSave(s, image);
else if(strstr(s,".sci")!=NULL)
ImageSaveSCI(s, image);

break;
case 5:
free(image);
exit(0);
break;
case 6:
image=noir_blanc4(image);
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glutReshapeWindow(image->sizeX, image->sizeY);
break;
case 17:
printf("Entrer le nom pour l'image dans cette taille\n");
scanf("%s", &s[0]);
ImageSaveSCI(s, image);
break;
default:
break;
}
}

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

if (argc<2) {
fprintf(stderr, "Usage : palette nom_de_fichier\n");
exit(0);
}


glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowSize(640,480);
glutInitWindowPosition(0, 0);
glutCreateWindow("VPUP8");

Init(argv[1]);

glutCreateMenu(menuFunc);
glutAddMenuEntry("Informations", 0);
glutAddMenuEntry("Gris", 2);
glutAddMenuEntry("Ouvrir", 3);
glutAddMenuEntry("Sauver", 4);
glutAddMenuEntry("Noir et Blanc", 6);
glutAddMenuEntry("Vert 1", 7);
glutAddMenuEntry("Vert 2", 8);
glutAddMenuEntry("Quit", 5);
glutAttachMenu(GLUT_LEFT_BUTTON);

glutDisplayFunc(Display);
glutReshapeFunc(Reshape);
glutKeyboardFunc(Keyboard);

glutMouseFunc(Mouse);

glutMainLoop();

return 1;
}


J'espere que vous m'aidez, je vous remercie d'avance