Esempio n. 1
0
		void run() {
			glUseProgram(normalShaderProgram);

			Vertex centre = {0,0,0};

			SphereShaded sphere = SphereShaded(1, centre, 10, 10, 0);

			mat4 Projection = perspective(45.0f, 1.0f, 0.1f, 100.0f);
			mat4 View = lookAt(vec3(0,2,1), vec3(0,0,0), vec3(0,1,0));
			View = scale(View, vec3(0.7f));
			mat4 Model = mat4(1.0f);
			mat4 MVP;
			GLuint MatrixID = glGetUniformLocation(normalShaderProgram, "MVP");

			vec4 LightV = vec4(0.8f, 0.8f, 0.8f, 1.f);
			GLuint LightVID = glGetUniformLocation(normalShaderProgram, "LightV");
			glUniform4fv(LightVID, 1, &LightV[0]);
				
			vec4 LightC = vec4(0.7f, 0.7f, 0.7f, 1.f);
			GLuint LightCID = glGetUniformLocation(normalShaderProgram, "LightC");
			glUniform4fv(LightCID, 1, &LightC[0]);
				
			vec4 Material = vec4(1.f, 0.f, 0.f, 1.f);
			GLuint MaterialID = glGetUniformLocation(normalShaderProgram, "Material");
			glUniform4fv(MaterialID, 1, &Material[0]);

			//Running stuff
			running = GL_TRUE;
			double old_time = 0, current_time = 0;
			ostringstream title;
			float rotation = 0.f;
			while(running) { 
				current_time = glfwGetTime();
				rotation = (float)((current_time - old_time) * speed);
				if (rotation >= 360.f) {
					rotation = 0.f;
				}
				old_time = current_time;

				View = rotate(View, rotation, vec3(1, 1, 1));
				MVP = Projection * View * Model;
				glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);
		
				glClearColor(0,0,0,0);
				glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
				sphere.render();
				glFlush();
				glfwSwapBuffers();	
				if (!glfwGetWindowParam(GLFW_OPENED)) {
					running = GL_FALSE;
				}
			}
		}
Esempio n. 2
0
int main(void){
	int running = GL_TRUE;
	char currentKey = 'A';
	SphereRotate sphereA;
	coneRotate coneB;
	SphereNormals normalsC;
	Paths pathsE;
	SphereShaded shadedD;
	//initialise GLFW

	if(!glfwInit()) {
		exit(EXIT_FAILURE);
	}

	//open window

	if(!glfwOpenWindow(600, 600, 0, 0, 0, 0, 0, 0, GLFW_WINDOW)){
		glfwTerminate();
		exit(EXIT_FAILURE);
	}

	glewInit();
	
	if(!(sphereA.init() && coneB.init() && normalsC.init() && pathsE.init() && shadedD.init()))
		exit(EXIT_FAILURE);

	while( running ) {
		//render here
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glClearColor(0, 0, 0, 1);

		if(currentKey == 'A'){
			sphereA.render();
		} else if(currentKey =='B'){
			coneB.render();
		} else if(currentKey == 'C'){
			normalsC.render();
		} else if(currentKey == 'D'){
			shadedD.render();
		} else if(currentKey == 'E'){
			pathsE.render();
		}
		//check("draw");
		glfwSwapBuffers();
		//check("swap buffers");
		//check esc key

		running= !(glfwGetKey(GLFW_KEY_ESC) || glfwGetKey('Q')) && glfwGetWindowParam(GLFW_OPENED);
		
		if(glfwGetKey('A'))
			currentKey = 'A';
		else if(glfwGetKey('B'))
			currentKey='B';
		else if(glfwGetKey('C'))
			currentKey='C';
		else if(glfwGetKey('D'))
			currentKey='D';
		else if(glfwGetKey('E'))
			currentKey = 'E';
		glFlush();
				
	}

	//end app

	glfwTerminate();

	exit(EXIT_SUCCESS);

}