Beispiel #1
0
// Loader for inline data to Model (almost same as LoadModelPlus)
Model* LoadDataToModel(
			GLfloat *vertices,
			GLfloat *normals,
			GLfloat *texCoords,
			GLfloat *colors,
			GLuint *indices,
			int numVert,
			int numInd)
{
	Model* m = (Model*)malloc(sizeof(Model));
	memset(m, 0, sizeof(Model));
	
	m->vertexArray = vertices;
	m->texCoordArray = texCoords;
	m->normalArray = normals;
	m->indexArray = indices;
	m->numVertices = numVert;
	m->numIndices = numInd;
	
	glGenVertexArrays(1, &m->vao);
	glGenBuffers(1, &m->vb);
	glGenBuffers(1, &m->ib);
	glGenBuffers(1, &m->nb);
	if (m->texCoordArray != NULL)
		glGenBuffers(1, &m->tb);

	ReloadModelData(m);
	
	return m;
}
void calculateNextPos2(vector<glm::vec3> &particle, FBOstruct *fboPos, FBOstruct *fboOldPos, FBOstruct *fboVel, FBOstruct *fboOldVel, Model* squareModel, GLuint velocityEulerShader, GLuint pass, GLuint PositionEulerShader)
{	
	ReloadModelData(squareModel);
	
	//update old velosity
	glUseProgram(pass);
	useFBO(fboOldVel, fboVel, 0L);
	glClearColor(0.0, 0.0, 0.0, 0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	DrawModel(squareModel, pass, "in_Position", NULL, "in_TexCoord");

	//old position is updated to current position
	glUseProgram(pass);
	useFBO(fboOldPos, fboPos, 0L);
	glClearColor(0.0, 0.0, 0.0, 0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	DrawModel(squareModel, pass, "in_Position", NULL, "in_TexCoord");

	//update velosity
	glUseProgram(velocityEulerShader);
	use2FBO(fboVel, fboOldVel, fboOldPos, velocityEulerShader);
	glClearColor(0.0, 0.0, 0.0, 0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	
	DrawModel(squareModel, velocityEulerShader, "in_Position", NULL, "in_TexCoord");
		
	//current position is updated to new position, need currnt position therfor updated old position first
	glUseProgram(PositionEulerShader);
	use2FBO(fboPos, fboVel, fboOldPos, PositionEulerShader);
	glClearColor(0.0, 0.0, 0.0, 0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	DrawModel(squareModel, PositionEulerShader, "in_Position", NULL, "in_TexCoord");

	// position vector is updated
	const size_t SIZE = nrOfParticlesVertically*nrOfParticlesHorizontally * 4;
	float particlePixels[SIZE];
	glReadPixels(0, 0, nrOfParticlesVertically*nrOfParticlesHorizontally, 1, GL_RGBA, GL_FLOAT, particlePixels);
	for (int i = 0, j = 0; i < particle.size(); i++, j += 4)
	{
		//cout << "Position vector: " << particlePixels[j] << " " << particlePixels[j + 1] << " " << particlePixels[j + 2] << endl;
		particle.at(i).x = particlePixels[j];
		particle.at(i).y = particlePixels[j + 1];
		particle.at(i).z = particlePixels[j + 2];
	};
}
Beispiel #3
0
Model* LoadModelPlus(const char* name/*,
			GLuint program,
			char* vertexVariableName,
			char* normalVariableName,
			char* texCoordVariableName*/)
{
	Model *m;
	
	m = LoadModel(name);
	
	glGenVertexArrays(1, &m->vao);
	glGenBuffers(1, &m->vb);
	glGenBuffers(1, &m->ib);
	glGenBuffers(1, &m->nb);
	if (m->texCoordArray != NULL)
		glGenBuffers(1, &m->tb);
		
	ReloadModelData(m);
	
	return m;
}