// Here is the function that gets called each time the window needs to be redrawn.
// It is the "paint" method for our program, and is set up from the glutDisplayFunc in main
void render() {
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// New!
	glUseProgram(shaderProgramID);
	//theta = 0.01f;
	scaleAmount = sin(theta);

	// Fill the matrices with valid data
	makeScale(scaleMatrix, 1.0f, 1.0f, 1.0f);			// Fill the scaleMatrix variable
	makeRotateY(rotYMatrix, theta);						// Fill the rotYMatrix variable

	//makeTranslate(transMatrix, -0.25f, -0.25f, -0.25f);		// Fill the transMatrix to push the model back 1 "unit" into the scene
	 makeTranslate(V, 0.0f, 0.0f, -1.0f);			// Fill the (V)iew matrix to push the world up 1 unit
	
	// Multiply them together 
	//matrixMult4x4(M, transMatrix, rotYMatrix);	// Order is important!
	//matrixMult4x4(M, rotYMatrix, transMatrix);	// This is backwards, unless you want orbiting!

	matrixMult4x4(tempMatrix1, transMatrix, scaleMatrix);	// Scale, then rotate...
	matrixMult4x4(M, rotYMatrix, tempMatrix1);	// ... then multiply THAT by the translate
		
	// Important! Pass that data to the shader variables
	//glUniformMatrix4fv(modelMatrixID, 1, GL_TRUE, M);
	glUniformMatrix4fv(viewMatrixID, 1, GL_TRUE, V);
	glUniformMatrix4fv(perspectiveMatrixID, 1, GL_TRUE, P);
	glUniform3fv(emitterID, 1, emitter_pos);
	
	/* Render Particles. Enabling point re-sizing in vertex shader */
	glEnable (GL_PROGRAM_POINT_SIZE);
	glEnable (GL_BLEND);
	//glActiveTexture (GL_TEXTURE0);
	//glBindTexture (GL_TEXTURE_2D, tex);
	glUseProgram (shaderProgramID);
	current_seconds=Timer();
	/* update time in shaders */
	glUniform1f (timeID, (GLfloat)current_seconds);

	//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
#ifdef USING_INDEX_BUFFER
	glDrawElements (GL_TRIANGLES, NUM_INDICES, GL_UNSIGNED_INT, NULL);
#else
	//glDrawArrays(GL_TRIANGLES, 0, NUM_VERTICES);

	glBindVertexArray (vao);
	// draw points 0-3 from the currently bound VAO with current in-use shader
	glDrawArrays (GL_POINTS, 0, PARTICLE_COUNT);
	glDisable (GL_BLEND);
	glDisable (GL_PROGRAM_POINT_SIZE);
	l=clock();

#endif
	glutSwapBuffers();
	glutPostRedisplay();		// NEW! This calls "render" again, allowing for animation!
}
Beispiel #2
0
// Here is the function that gets called each time the window needs to be redrawn.
// It is the "paint" method for our program, and is set up from the glutDisplayFunc in main
void render() {
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glUseProgram(shaderProgramID);
	//theta = 0.01f;
	scaleAmount = 0.8f; //sin(theta);

	// Set the (M)odel matrix
	makeScale(scaleMatrix, scaleAmount, scaleAmount, scaleAmount);	// Fill the scaleMatrix variable
	makeRotateY(rotYMatrix,0.5);						// Fill the rotYMatrix variable
	makeRotateX(rotXMatrix,0.0);
	makeTranslate(transMatrix, 0.0f, 0.0f, -2.0f);	// Fill the transMatrix to push the model back 1 "unit" into the scene
	makeTranslate(transMatrix2, 0.0f, 0.0f, 0.0f);

	// Multiply them together 
	matrixMult4x4(tempMatrix1,rotYMatrix, scaleMatrix);	// Scale, then rotate...
	matrixMult4x4(tempMatrix2,rotXMatrix,tempMatrix1);
	matrixMult4x4(M, transMatrix, tempMatrix2);				// ... then multiply THAT by the translate
	
	// NEW!  Copy the rotations into the allRotsMatrix
	copyMatrix(rotYMatrix, allRotsMatrix);

	// Set the (V)iew matrix if you want to "move" around the scene
     makeTranslate(V, theta, gama, 0.0f);	
	
	// Important! Pass that data to the shader variables
	glUniformMatrix4fv(modelMatrixID, 1, GL_TRUE, M);
	glUniformMatrix4fv(viewMatrixID, 1, GL_TRUE, V);
	glUniformMatrix4fv(perspectiveMatrixID, 1, GL_TRUE, P);
	glUniformMatrix4fv(allRotsMatrixID, 1, GL_TRUE, allRotsMatrix);
	glUniform4fv(lightID, 1, light);
	
	//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
#ifdef USING_INDEX_BUFFER
	glDrawElements (GL_TRIANGLES, NUM_INDICES, GL_UNSIGNED_INT, NULL);
#else
	glDrawArrays(GL_TRIANGLES, 0, NUM_VERTICES);
#endif
	glutSwapBuffers();
	glutPostRedisplay();		// This calls "render" again, allowing for animation!
}
Beispiel #3
0
Matrix4 Matrix4::makeTranslate(Vector3 a)
{
    return makeTranslate(a[0], a[1], a[2]);
}