Salut à tous,

Je me suis bien avancé dans mon programme mais j'arrive à un bug que je n'arrive pas à regler. J'y est travailler pendant toute la journée et j'ai rien trouver. Alors je me suis dit que je viendrais consulter les superbe membres du forum devellopez .

Alors le problème est que j'essaye de faire une detection de sélection avec la souris. Mais on dirait que c'est le if qui ne fonctionne pas, je trouve sa très étrange. Alors voila mon code :

Main.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
 
#include <GL/glut.h>
#include <iostream>
#include <stdlib.h>
#include "render.h"
 
RenderRR *g_Render = NULL;
 
const int LARGEUR_FENETRE = 800;
const int HAUTEUR_FENETRE = 600;
int g_mx=0, g_my=0;
int g_w, g_h;
 
#define BUFFERSIZE 1024
#define CARREROUGE 1
#define TRIANGLEBLEU 2
 
 
GLuint selectBuf[BUFFERSIZE];
GLint hits;
int cursorX, cursorY;
int renderScene;
 
//fonctions ci-dessous servent pour afficher le texte
void reshape(GLint w, GLint h) 
{
  g_w = w;
  g_h = h;
 
  glViewport(0, 0, g_w, g_h);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(65.0, (float)g_w / g_h, 1, 1000);
  glMatrixMode(GL_MODELVIEW);
}
 
void mousestate(int button, int state, int mousex, int mousey)
{
 
	if (button == GLUT_LEFT_BUTTON)
	{
		if (state == GLUT_DOWN)
		{
			cursorX = mousex;
			cursorY = mousey;
			void startPicking();
		}
	}
}
 
void startPicking(int cursorX, int cursorY)
{
GLint viewport[4];
	float ratio;
 
	glSelectBuffer(BUFFERSIZE,selectBuf);
 
	glGetIntegerv(GL_VIEWPORT,viewport);
 
	glRenderMode(GL_SELECT);
 
	glInitNames();
 
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
 
	gluPickMatrix(cursorX,viewport[3]-cursorY,5,5,viewport);
	ratio = (viewport[2]+0.0) / viewport[3];
	gluPerspective(45,ratio,0.1,1000);
	glMatrixMode(GL_MODELVIEW);
}
 
void processHits2 (GLint hits, GLuint buffer[], int sw)
{
	if(hits = 1)
	{
		renderScene=TRIANGLEBLEU;
	}
	else if(hits=2)
	{
		renderScene=CARREROUGE;
	}   
}
 
void stopPicking() {
 
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	glFlush();
	hits = glRenderMode(GL_RENDER);
	if (hits != 0){
		processHits2(hits,selectBuf,0);
	}
}
 
 
void mousemotion(int x, int y)
{
    g_mx = x;
    g_my = y;
    glutPostRedisplay();
}
 
//fonctions ci-dessous servent pour afficher le texte
void Graphique_SetOrthographicProjection() 
{
    //Sauvegarde de la matrice MODELVIEW
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
 
    // Passer dans le mode projection
    glMatrixMode(GL_PROJECTION);
    //Sauvegarde de la matrice PROJECTION    
    glPushMatrix();
    glLoadIdentity();
 
    // Mettre en place une perspective orthogonale
    gluOrtho2D(0,g_w, g_h, 0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}
 
void Graphique_ResetPerspectiveProjection() 
{
    glMatrixMode(GL_PROJECTION);
    //On remet la matrice de PROJECTION
    glPopMatrix();
 
    glMatrixMode(GL_MODELVIEW);
    //On remet la matrice de MODELVIEW 
    glPopMatrix();
}
 
void dessine_souris()
{
	Graphique_SetOrthographicProjection();
	glTranslatef(g_mx, g_my, 0.0f);
	g_Render->Cursor();
	Graphique_ResetPerspectiveProjection();
}
 
 
 
void display()
{
 
	// Enleve la couleur
    glClear(GL_COLOR_BUFFER_BIT);
    glLoadIdentity();
 
	Graphique_SetOrthographicProjection();
	g_Render->Menu(renderScene,LARGEUR_FENETRE,HAUTEUR_FENETRE);
	Graphique_ResetPerspectiveProjection();
 
	//Rendu de la souris
    dessine_souris();
 
	glutSwapBuffers();
 
}
 
int main(int argc, char **argv)
{
    glutInit(&argc,argv);
    glutInitWindowSize (LARGEUR_FENETRE,HAUTEUR_FENETRE);
    glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE);
    glutCreateWindow ("Jeux");
 
	glutSetCursor(GLUT_CURSOR_NONE);
    glutDisplayFunc(display);
	glutMouseFunc(mousestate);
    glutMotionFunc(mousemotion);
    glutPassiveMotionFunc(mousemotion);
    glutReshapeFunc(reshape);
 
    glutMainLoop();
 
	return(0);
}
Render.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
 
#include <gl/glut.h>
#include <gl/glu.h>
#include <math.h>
#include "Render.h"
 
#define CARRE 1
#define TRIANGLE 2
 
RenderRR::RenderRR()
{
}
 
RenderRR::~RenderRR()
{
}
 
void RenderRR::Cursor()
{
   // Couleur Verte
    glColor3f(0.0f, 0.5f, 0.0f);
 
    // Dessine les deux triangle formant la souris
    glBegin(GL_TRIANGLES);
        glVertex3d(0.0f, -0.0f, 0.0f);
        glVertex3d(0.0f, -8.0f, 0.0f);
        glVertex3d(-12.0f, -20.0f, 0.0f);
	glEnd();
 
	glBegin(GL_TRIANGLES);
        glVertex3d(8.0f, -8.0f, 0.0f);
        glVertex3d(0.0f, -8.0f, 0.0f);
        glVertex3d(-12.0f, -20.0f, 0.0f);
    glEnd();
 
}
 
void RenderRR::Menu(int render, int largeurf, int hauteurf)
{
 
	if(render = 0)
	{
	glPushName(CARRE);
	glTranslatef(largeurf/2-50, hauteurf/2-50, 0.0f);
 
	// Couleur Rouge
	glColor3f(1.0f, 0.0f, 0.0f);
	//Dessine un carré
 
	glBegin(GL_QUADS);
		glVertex3d(0.0f, 0.0f, 0.0f);
		glVertex3d(100.0f, 0.0f, 0.0f);
		glVertex3d(100.0f, 100.0f, 0.0f);
		glVertex3d(0.0f, 100.0f, 0.0f);
	glEnd();
	glPopName();
 
	}
	else if(render = 1)
	{
	glPushName(TRIANGLE);	
	glTranslatef(largeurf/2-50, hauteurf/2+50, 0.0f);
 
	// Couleur Bleu
	glColor3f(0.0f, 0.0f, 1.0f);
 
	// Dessine un triangle
 
	glBegin(GL_TRIANGLES);
		glVertex3d(0.0f, 0.0f, 0.0f);
		glVertex3d(100.0f, 0.0f, 0.0f);
		glVertex3d(50.0f, -100.0f, 0.0f);
	glEnd();
	glPopName();
 
	}
}

Alors si jamais quelqu'un trouve l'erreur ou la solution, je vais être extrêmement content. Merci.

Maxetime