Exemplo n.º 1
0
void MainWindow::sendDataToHardware()
{
	Neumont::ShapeData cubeData = Neumont::ShapeGenerator::makeCube();
	Neumont::ShapeData torusData = Neumont::ShapeGenerator::makeTorus(12);
	Neumont::ShapeData planeData = Neumont::ShapeGenerator::makePlane(3);

	glGenBuffers(1, &theBufferID);
	glBufferData(GL_ARRAY_BUFFER, 
		cubeData.vertexBufferSize() + cubeData.indexBufferSize() +
		torusData.vertexBufferSize() + torusData.indexBufferSize() +
		planeData.vertexBufferSize() + planeData.indexBufferSize(), 0, GL_FALSE);
	
	GLintptr currentOffset = 0;
	glBufferSubData(GL_ARRAY_BUFFER, currentOffset, cubeData.vertexBufferSize(), cubeData.verts);
	currentOffset += cubeData.vertexBufferSize();
	glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, currentOffset, cubeData.indexBufferSize(), cubeData.verts);
	currentOffset += cubeData.indexBufferSize();
	glBufferSubData(GL_ARRAY_BUFFER, currentOffset, torusData.vertexBufferSize(), torusData.verts);
	currentOffset += torusData.vertexBufferSize();
	glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, currentOffset, torusData.indexBufferSize(), torusData.verts);
	currentOffset += torusData.indexBufferSize();
	glBufferSubData(GL_ARRAY_BUFFER, currentOffset, planeData.vertexBufferSize(), planeData.verts);
	currentOffset += planeData.vertexBufferSize();
	glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, currentOffset, planeData.indexBufferSize(), planeData.verts);
	currentOffset += planeData.indexBufferSize();

	cubeNumIndices = cubeData.numIndices;
	torusNumIndices = torusData.numIndices;
	planeNumIndices = planeData.numIndices;

	glBindAttribLocation(programID, cubeVertexArrayIndex, &cubeVertexArrayIndex);
	glEnableVertexAttribArray(0);
	glEnableVertexAttribArray(1);
}
Exemplo n.º 2
0
void DebugShapes::AddFBX(const glm::mat4& position, const bool& ignoreDepth, const bool& useBlend)
{
	std::ifstream in("c:\\lulu.bin", std::ios::in | std::ios::binary);
	in.seekg(0, std::ios::end);
	const unsigned int BUFFER_SIZE = in.tellg(); 
	char* buf = new char[BUFFER_SIZE];
	in.seekg(0, std::ios::beg);
	in.read(buf, BUFFER_SIZE);
	in.close();

	uint NUM_SHAPE =  *reinterpret_cast<unsigned int*>(buf);

	Neumont::ShapeData* shapeDatas = reinterpret_cast<Neumont::ShapeData*>(buf + sizeof(unsigned int));	
	
	for(unsigned int i = 0; i < NUM_SHAPE; i++)
	{
		Neumont::ShapeData& d = shapeDatas[i];
		d.verts = reinterpret_cast<Neumont::Vertex*>( buf + (unsigned int)(d.verts));
		d.indices = reinterpret_cast<ushort*>( buf + (unsigned int)(d.indices));

		Neumont::ShapeData fbxObject = shapeDatas[i];
		unsigned int fbxObjectGeometryIndex = renderer->AddGeometry(fbxObject.verts,fbxObject.vertexBufferSize(),
		fbxObject.indices,fbxObject.numIndices, GL_TRIANGLES);	

		Renderer::Renderable* renderableToTrack = renderer->AddRenderable(fbxObjectGeometryIndex, position * glm::translate(glm::vec3(0.0f,1.0f*(i),0.0f)),shaderProgramID,ignoreDepth, useBlend);
		Object = renderableToTrack;
	}		
	
	delete[] buf;
}
Exemplo n.º 3
0
void DebugShapes::initialize()
{
	Neumont::ShapeData cube = Neumont::ShapeGenerator::makeCube();		
	Neumont::ShapeData arrow = Neumont::ShapeGenerator::makeArrow();	
	Neumont::ShapeData plane = Neumont::ShapeGenerator::makePlane(15,15);
	Neumont::ShapeData sphere = Neumont::ShapeGenerator::makeSphere(20);
	Neumont::ShapeData teapot = Neumont::ShapeGenerator::makeTeapot(15, glm::mat4());

	Neumont::ShapeData* table;
	unsigned int numberShapes;
	Neumont::FbxLoader::loadFbxFile("table.fbx", table, numberShapes);

	cubeGeometryIndex = renderer->AddGeometry(cube.verts,cube.vertexBufferSize(),
		cube.indices,cube.numIndices,GL_TRIANGLES);	

	arrowGeometryIndex = renderer->AddGeometry(arrow.verts, arrow.vertexBufferSize(),
		arrow.indices, arrow.numIndices, GL_TRIANGLES);

	planeGeometryIndex = renderer->AddGeometry(plane.verts, plane.vertexBufferSize(),
		plane.indices, plane.numIndices, GL_TRIANGLES);

	sphereGeometryIndex = renderer->AddGeometry(sphere.verts, sphere.vertexBufferSize(),
		sphere.indices, sphere.numIndices, GL_TRIANGLES);

	teapotGeometryIndex = renderer->AddGeometry(teapot.verts, teapot.vertexBufferSize(),
		teapot.indices, teapot.numIndices, GL_TRIANGLES);

	for(unsigned int i = 0; i < numberShapes; i++)
	{
		tableGeometryIndex = renderer->AddGeometry(table[i].verts, table[i].vertexBufferSize(),
			table[i].indices, table[i].numIndices, GL_TRIANGLES);
	}
		
	shaderProgramID = renderer->AddShader("VertexShader.hlsl","FragmentShader.hlsl");
	NormalShaderProgramID = renderer->AddShader("NormalVertexShader.hlsl","NormalFragmentShader.hlsl");
	ReflectionProgramID = renderer->AddShader("VertexShader.hlsl","ReflectionFragmentShader.hlsl");
	VertexDisplacementShaderProgramID = renderer->AddShader("VertexDisplacementShader.hlsl","FragmentShader.hlsl");
	
	cube.cleanUp();
	arrow.cleanUp();
	plane.cleanUp();
	sphere.cleanUp();
	teapot.cleanUp();
}
Exemplo n.º 4
0
void MyGLWidget::fillBuffer()
{

// arrow
	Neumont::ShapeData data = Neumont::ShapeGenerator::makeArrow();
	arrow_numIndices = data.numIndices;
	arrow_shapeData = data;

	glGenBuffers(1, &arrow_vertexBufferID);
	glGenBuffers(1, &arrow_indexBufferID);

	glBindBuffer(GL_ARRAY_BUFFER, arrow_vertexBufferID);
	glBufferData(GL_ARRAY_BUFFER, data.vertexBufferSize(), data.verts, GL_STATIC_DRAW);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, arrow_indexBufferID);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, data.indexBufferSize(), data.indices, GL_STATIC_DRAW);

	data.cleanUp();

// torus
	data = Neumont::ShapeGenerator::makeTorus(50);
	torus_numIndices = data.numIndices;
	torus_shapeData = data;

	glGenBuffers(1, &torus_vertexBufferID);
	glGenBuffers(1, &torus_indexBufferID);

	glBindBuffer(GL_ARRAY_BUFFER, torus_vertexBufferID);
	glBufferData(GL_ARRAY_BUFFER, data.vertexBufferSize(), data.verts, GL_STATIC_DRAW);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, torus_indexBufferID);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, data.indexBufferSize(), data.indices, GL_STATIC_DRAW);

	data.cleanUp();

// Tell GL how to read the bits (3 for the position, 4 for the color)
	glEnableVertexAttribArray(0);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, Neumont::Vertex::STRIDE, 0);

	glEnableVertexAttribArray(1);
	glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, Neumont::Vertex::STRIDE, BUFFER_OFFSET(Neumont::Vertex::COLOR_OFFSET));
}
Exemplo n.º 5
0
void MyGLWindow::sendDataToHardware()
{

	Neumont::ShapeData cube= Neumont::ShapeGenerator::makeCube();
	Neumont::ShapeData Torus= Neumont::ShapeGenerator::makeTorus(120);
	Neumont::ShapeData Sphere= Neumont::ShapeGenerator::makeSphere(10);
	Neumont::ShapeData Arrow= Neumont::ShapeGenerator::makeArrow();
	Neumont::ShapeData plane= Neumont::ShapeGenerator::makePlane(2);
	Neumont::ShapeData TangCube = makeCube();


	
	shaders[1]=shapes.createShaderInfo("../shaders/lightVertShader.glsl","../shaders/lightFragShader.glsl");
	shaders[2]=shapes.createShaderInfo("../shaders/LightingVertexShaderCode.glsl", "../shaders/LightingFragmentShaderCode.glsl");
	shaders[3]=shapes.createShaderInfo("../shaders/LightedBinaryVertexShaderCode.glsl", "../shaders/LightedBinaryFragmentShaderCode.glsl");
	shaders[4]=shapes.createShaderInfo("../shaders/lightedVertShader2 (2).glsl", "../shaders/lightedFragShader2 (3).glsl");
	shaders[5]=shapes.createShaderInfo("../shaders/NormalVertexShaderCode.glsl", "../shaders/NormalFragmentShaderCode.glsl");
	shaders[6]=shapes.createShaderInfo("../shaders/LightingVertexShaderCode2.glsl", "../shaders/LightingFragmentShaderCode2.glsl");
	shaders[7]=shapes.createShaderInfo("../shaders/TanVert.glsl", "../shaders/TanFrag.glsl");


	
	textures[0]=shapes.addTexture("umbreon.png");
	textures[1]=shapes.addTexture("patter2.png");
	textures[2]=shapes.addTexture("pikachu.png");
	textures[3]=shapes.addTexture("Shapes.png");


	
	geometries[0]=shapes.addGeometry(cube.verts,cube.vertexBufferSize(),cube.indices,cube.numIndices,GL_TRIANGLES);
	shapes.addShaderStreamedParameter(geometries[0],0,Renderer::PT_VEC3,0,12*sizeof(float));
	shapes.addShaderStreamedParameter(geometries[0],1,Renderer::PT_VEC4,geometries[0]->BufferOffset+3*sizeof(float),12*sizeof(float));
	shapes.addShaderStreamedParameter(geometries[0],2,Renderer::PT_VEC3,geometries[0]->BufferOffset+7*sizeof(float),12*sizeof(float));
	shapes.addShaderStreamedParameter(geometries[0],3,Renderer::PT_VEC2,geometries[0]->BufferOffset+10*sizeof(float),12*sizeof(float));
	renderables[0]=shapes.addRenderable(geometries[0],transformCube1,shaders[1],textures[0]);
	
	geometries[1]=shapes.addGeometry(Torus.verts,Torus.vertexBufferSize(),Torus.indices,Torus.numIndices,GL_TRIANGLES);
	shapes.addShaderStreamedParameter(geometries[1],0,Renderer::PT_VEC3,geometries[1]->BufferOffset,12*sizeof(float));
	shapes.addShaderStreamedParameter(geometries[1],1,Renderer::PT_VEC4,geometries[1]->BufferOffset+3*sizeof(float),12*sizeof(float));
	shapes.addShaderStreamedParameter(geometries[1],2,Renderer::PT_VEC3,geometries[1]->BufferOffset+7*sizeof(float),12*sizeof(float));
	shapes.addShaderStreamedParameter(geometries[1],3,Renderer::PT_VEC2,geometries[1]->BufferOffset+10*sizeof(float),12*sizeof(float));

	renderables[1]=shapes.addRenderable(geometries[1],transformTorus1,shaders[2],textures[2]);
	renderables[2]=shapes.addRenderable(geometries[1],transformTorus2,shaders[2],textures[2]);

	geometries[2]=shapes.addGeometry(Sphere.verts,Sphere.vertexBufferSize(),Sphere.indices,Sphere.numIndices,GL_TRIANGLES);
	shapes.addShaderStreamedParameter(geometries[2],0,Renderer::PT_VEC3,geometries[2]->BufferOffset,12*sizeof(float));
	shapes.addShaderStreamedParameter(geometries[2],1,Renderer::PT_VEC4,geometries[2]->BufferOffset+3*sizeof(float),12*sizeof(float));
 	shapes.addShaderStreamedParameter(geometries[2],2,Renderer::PT_VEC3,geometries[2]->BufferOffset+7*sizeof(float),12*sizeof(float));
	shapes.addShaderStreamedParameter(geometries[2],3,Renderer::PT_VEC2,geometries[2]->BufferOffset+10*sizeof(float),12*sizeof(float));

	renderables[3]=shapes.addRenderable(geometries[2],transformShpere1,shaders[2],textures[1]);
	renderables[4]=shapes.addRenderable(geometries[2],transformShpere2,shaders[2],textures[1]);

	geometries[3]=shapes.addGeometry(Arrow.verts,Arrow.vertexBufferSize(),Arrow.indices,Arrow.numIndices,GL_TRIANGLES);
	shapes.addShaderStreamedParameter(geometries[3],0,Renderer::PT_VEC3,geometries[3]->BufferOffset,12*sizeof(float));
	shapes.addShaderStreamedParameter(geometries[3],1,Renderer::PT_VEC4,geometries[3]->BufferOffset+3*sizeof(float),12*sizeof(float));
	shapes.addShaderStreamedParameter(geometries[3],2,Renderer::PT_VEC3,geometries[3]->BufferOffset+7*sizeof(float),12*sizeof(float));
	shapes.addShaderStreamedParameter(geometries[3],3,Renderer::PT_VEC2,geometries[3]->BufferOffset+10*sizeof(float),12*sizeof(float));

	renderables[5]=shapes.addRenderable(geometries[3],transformArrow,shaders[2],textures[2]);

	geometries[4]=shapes.addGeometry(plane.verts,plane.vertexBufferSize(),plane.indices,plane.numIndices,GL_TRIANGLES);
	shapes.addShaderStreamedParameter(geometries[4],0,Renderer::PT_VEC3,geometries[4]->BufferOffset,12*sizeof(float));
	shapes.addShaderStreamedParameter(geometries[4],1,Renderer::PT_VEC4,geometries[4]->BufferOffset+3*sizeof(float),12*sizeof(float));
	shapes.addShaderStreamedParameter(geometries[4],2,Renderer::PT_VEC3,geometries[4]->BufferOffset+7*sizeof(float),12*sizeof(float));
	shapes.addShaderStreamedParameter(geometries[4],3,Renderer::PT_VEC2,geometries[4]->BufferOffset+10*sizeof(float),12*sizeof(float));

	renderables[6]=shapes.addRenderable(geometries[4],transformPlane,shaders[2],textures[0]);
	renderables[8]=shapes.addRenderable(geometries[4],transformPlane2,shaders[6],textures[3]);
	


	geometries[5]=shapes.readBinary("Cube.bin");
	shapes.addShaderStreamedParameter(geometries[5],0,Renderer::PT_VEC3,geometries[5]->BufferOffset,8*sizeof(float));
	shapes.addShaderStreamedParameter(geometries[5],2,Renderer::PT_VEC3,geometries[5]->BufferOffset+3*sizeof(float),8*sizeof(float));
	shapes.addShaderStreamedParameter(geometries[5],3,Renderer::PT_VEC2,geometries[5]->BufferOffset+6*sizeof(float),8*sizeof(float));
	renderables[7]=shapes.addRenderable(geometries[5],transformBinary,shaders[3],textures[2]);

	geometries[6]=shapes.addGeometry(TangCube.verts,TangCube.vertexBufferSize(),TangCube.indices,TangCube.numIndices,GL_TRIANGLES);
	shapes.addShaderStreamedParameter(geometries[6],0,Renderer::PT_VEC3,geometries[6]->BufferOffset,12*sizeof(float));
	shapes.addShaderStreamedParameter(geometries[6],1,Renderer::PT_VEC4,geometries[6]->BufferOffset+3*sizeof(float),12*sizeof(float));
	shapes.addShaderStreamedParameter(geometries[6],2,Renderer::PT_VEC3,geometries[6]->BufferOffset+7*sizeof(float),12*sizeof(float));
	shapes.addShaderStreamedParameter(geometries[6],3,Renderer::PT_VEC2,geometries[6]->BufferOffset+10*sizeof(float),12*sizeof(float));

	renderables[9] =shapes.addRenderable(geometries[6],tangcubeTransform,shaders[7],textures[3]);
}