Join together menu with gameplay

Hello at all.

I'm triying to make the game go to the simulation by pressing 'g'.

I know the menu has so many options, but before I make them useful I want to try this. This is a basic game wich consists of a menu where you have the instructions and you can start or exit the program. If you select start you can select the car (only varies the color of the polygon), the place where you drive (still only changes the polygon color) and a pause menu (restart he car to the center of the screen, go to menu or exit the program).

I had been able to make the menu and the gameplay separately, but not both at the time.

Those things are not implementated yet, since I'm having trouble with the application. Whats the problem? I can't make compatible the car/quad which goes foward, reverse and turns with the menu. Also if any quad is under the declaration of the "menu" and "selection" in Drawscene, it will color the "menu" and "selection".

main
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#include <iostream>
#include <stdlib.h>
#include <glut.h>
#include "polygons.h"
#include "imageloader.h"
#include <iomanip>
#include <fstream>
#include <cmath>
#define RADIANS(a) (a * 3.14f / 180.0f)

using namespace std;

//DISTANCIES
//Between options: 0.3145
//between menus: 1.375

float selection = 0.0f;
float cameraheight = 0.0f;
float accept = 0.0f,
	xmove = 0.0f,
	ymove = 0.0f,
	xpos = 0.0f,
	ypos = 0.0f,
	_angle = 0.0f,
	esquerra = 0.0f;

GLuint _textureId;    

void Exit_Func(){
	if (selection == -0.629f){
		if(accept == 4.0f || 1.0f){
				exit(0);
		}
	}
}

void handleKeypress(unsigned char key, int x, int y) {
	switch (key) {
		case 'w':
			xpos += cos(RADIANS(_angle)) * 1.0f;
			ypos += sin(RADIANS(_angle)) * 1.0f;
			selection += 0.3145f;break;
		case 'a':
			ymove -= 1.375f; 
			accept += 1.0f;
			_angle += 20.0f;
			Exit_Func();		break;	
		case 's':
			xpos += cos(RADIANS(_angle)) * 1.0f;
			ypos += sin(RADIANS(_angle)) * 1.0f;
			selection -= 0.3145f;break;
		case 'd':
			ymove += 1.375f; 
			_angle -= 20.0f;
			accept -= 1.0f;			break;	
		
		case '1':
			cameraheight += 0.125f; break;
		case '2':
			cameraheight -= 0.125f; break;
		case 'g':
			esquerra += 10.0f; break;
			
		
	


	}
}

//Makes the image into a texture, and returns the id of the texture
GLuint loadTexture(Image* image) {
	GLuint textureId;
	glGenTextures(1, &textureId);
	glBindTexture(GL_TEXTURE_2D, textureId);
	glTexImage2D(GL_TEXTURE_2D,
				 0,
				 GL_RGB,
				 image->width, image->height,
				 0,
				 GL_RGB,
				 GL_UNSIGNED_BYTE,
				 image->pixels);
	return textureId;
}



//Initializes 3D rendering
void initRendering() {
	glEnable(GL_DEPTH_TEST); 
	glEnable(GL_COLOR_MATERIAL);
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glEnable(GL_NORMALIZE);
	glEnable(GL_COLOR_MATERIAL);

	Image* image = loadBMP("C:\\menu.bmp"); //EL MENU DEL PRINCIPI ES 1024X512 CUDIDAO EL NOU ES 2048PX
	_textureId = loadTexture(image);
	delete image;

	glClearColor(0.33f, 0.33f, 0.67f, 1.0f);
}

//Called when the window is resized
void handleResize(int w, int h) {
	glViewport(0, 0, w, h);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0, (double)w / (double)h, 0.00001, 200000.0);
}



//Draws the 3D scene
void drawScene() {
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	//set cam pos
	glTranslatef(0.0f, -1.0625f - esquerra, -1.75f + cameraheight);
	
	
	////////////////gameplay////////////////////////
		glPushMatrix(); //Save the transformations performed thus far	
		glTranslatef(0.0f, 10.0f, 0.0f);///circuit/////
		glPushMatrix();
		glDisable( GL_BLEND );
		glDisable(GL_TEXTURE_2D);
		glBegin(GL_QUADS);
		 //Red Ferrari
		glVertex3f(-2000.0f, 2000.0f, 0.0f); //Meters (4,5m long per 2,25m wide)
		glVertex3f(2000.0f, 2000.0f, 0.0f);
		glVertex3f(2000.0f, -2000.0f, 0.0f);
		glVertex3f(-2000.0f, -2000.0f, 0.0f);	
		glEnd();
		glPopMatrix();

		///cotxe////
		glTranslatef(-esquerra + xpos, ypos, 0.0f);

		glRotatef(_angle, 0.0f, 0.0f, 1.0f);
		glDisable( GL_BLEND );
		glDisable(GL_TEXTURE_2D);
		glBegin(GL_QUADS);
		 //Red Ferrari
		glVertex3f(-2.25f, 1.0f, 0.01f); //Meters (4,5m long per 2,25m wide)
		glVertex3f(2.25f, 1.0f, 0.01f);
		glVertex3f(2.25f, -1.0f, 0.01f);
		glVertex3f(-2.25f, -1.0f, 0.01f);	
		glEnd();
		glPopMatrix(); //Undo the move of the car

	//MENU
	glDepthMask(false);
	glDisable( GL_BLEND );
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, _textureId);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	
	glPushMatrix();
	glTranslatef( 0.0f , - 0.375f - ymove , 0.0f);
	Menu();
	glPopMatrix();

	//SELECTION
	glDepthMask(true);
	glEnable( GL_BLEND );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
	glPushMatrix();
	glTranslatef( 0.0f , selection , 0.0f);
	Selection();
	glPopMatrix();

	////////////////gameplay////////////////////////
		glPushMatrix(); //Save the transformations performed thus far	
		glTranslatef(0.0f, 10.0f, 0.0f);///circuit/////
		glPushMatrix();
		glBegin(GL_QUADS);
		 //Red Ferrari
		glVertex3f(-2000.0f, 2000.0f, 0.0f); //Meters (4,5m long per 2,25m wide)
		glVertex3f(2000.0f, 2000.0f, 0.0f);
		glVertex3f(2000.0f, -2000.0f, 0.0f);
		glVertex3f(-2000.0f, -2000.0f, 0.0f);	
		glEnd();
		glPopMatrix();

		///cotxe////
		glTranslatef(-esquerra + xpos, ypos, 0.0f);

		glRotatef(_angle, 0.0f, 0.0f, 1.0f);		
		glBegin(GL_QUADS);
		 //Red Ferrari
		glVertex3f(-2.25f, 1.0f, 0.01f); //Meters (4,5m long per 2,25m wide)
		glVertex3f(2.25f, 1.0f, 0.01f);
		glVertex3f(2.25f, -1.0f, 0.01f);
		glVertex3f(-2.25f, -1.0f, 0.01f);	
		glEnd();
		glPopMatrix(); //Undo the move of the car

		glutSwapBuffers();
	
}

void update(int value) {
	glutPostRedisplay();
	glutTimerFunc(25, update, 0);

	/*if (selection < -0.629f - accept * (1.375f)){		
			selection = 0 - accept * (1.375f);
		}
*/
	
	if (selection < -0.64f){
		selection = 0.0f;
	}

	if (selection > 0.0f){
		selection = -0.64f;
	}

	if (ymove < 3.3 * -1.375f){
		ymove = 3* -1.375f;
	}
	
	if (ymove > 1.375f){
		ymove = 1.375f;
	}

	
	


}
	

	




int main(int argc, char** argv) {
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
	glutInitWindowSize(480, 320);
	
	glutCreateWindow("Treball de Recerca - Marc Colomé 2013");
	initRendering();
	
	glutDisplayFunc(drawScene);
	glutKeyboardFunc(handleKeypress);
	glutReshapeFunc(handleResize);	
	glutTimerFunc(25, update, 0);
	
	glutMainLoop();
	return 0;
}



Topic archived. No new replies allowed.