void OpenGLInitialization( void )
{
	// We're drawing on a white background
	glClearColor(1.0, 1.0, 1.0, 1.0);

	// Convert our xyz curves into vertex arrays
	for (uint i=0; i<curves.Size(); i++)
		drawableCurves.Add( CurveToVertexArray( curves[i] ) );

	// Covert our xyz curves into difference arrays.  TODO: This is hard coded (our difference is
	//    computed from either curve #0 or curve #6)
	for (uint i=0; i<curves.Size(); i++)
		errorCurves.Add( DifferenceToVertexArray( curves[i], curves[ i<6?0:6 ] ) );

	// Load the shaders to draw our curves; set some parameters
	draw = new IGLUShaderProgram( "shaders/drawXYZCurve.vert.glsl", 
								  "shaders/drawXYZCurve.geom.glsl",
								  "shaders/drawXYZCurve.frag.glsl" );
	draw["xRange"] = vec2( 330.0f, 843.0f );
	draw["yRange"] = vec2( -0.13f, 2.05f );

	// Load the shader to draw our axes
	drawAxes = new IGLUShaderProgram( "shaders/drawAxes.vert.glsl", 
								      "shaders/drawAxes.frag.glsl" );

	// Create the geometry for our axes
	axes = new IGLUVertexArray();
	float axesData[] = { -0.90f, -0.88f, 0.95f, -0.88f,       // x-axis line
		                 -0.88f, -0.88f, -0.88f, 0.95f,       // y-axis line
						 -0.90f, -0.6513f, -0.88f, -0.6513f,  // 0.25 tick
						 -0.90f, -0.4225f, -0.88f, -0.4225f,  // 0.5 tick
						 -0.90f, -0.1938f, -0.88f, -0.1938f,  // 0.75 tick
						 -0.90f, 0.035f, -0.88f, 0.035f,      // 1.0 tick
						 -0.90f, 0.2638f, -0.88f, 0.2638f,    // 1.25 tick
						 -0.90f, 0.4925f, -0.88f, 0.4925f,    // 1.5 tick
						 -0.90f, 0.7213f, -0.88f, 0.7213f,    // 1.75 tick
						 -0.90f, 0.95f, -0.88f, 0.95f,        // 2.0 tick
						 -0.7243f, -0.88f, -0.7243f, -0.91f,  // 400 nm tick
						 -0.5296f, -0.88f, -0.5296f, -0.91f,  // 450 nm tick
						 -0.3349f, -0.88f, -0.3349f, -0.91f,  // 500 nm tick
						 -0.1402f, -0.88f, -0.1402f, -0.91f,  // 550 nm tick
						 0.0545f, -0.88f, 0.0545f, -0.91f,    // 600 nm tick
						 0.24915f, -0.88f, 0.24915f, -0.91f,  // 650 nm tick
						 0.4438f, -0.88f, 0.4438f, -0.91f,    // 700 nm tick
						 0.6385f, -0.88f, 0.6385f, -0.91f,    // 750 nm tick
						 0.8332f, -0.88f, 0.8332f, -0.91f,    // 800 nm tick
	};
	axes->SetVertexArray( sizeof( axesData ), axesData );
	axes->EnableAttribute( IGLU_ATTRIB_VERTEX, 2, GL_FLOAT );
}
Beispiel #2
0
IGLUVertexArray *iglu::IGLUGeometry::CreateQuad( uint type, uint matlid )
{
	float *vptr = xyplane;
	if ( type & IGLU_GEOM_XZ_PLANE ) vptr = xzplane;
	if ( type & IGLU_GEOM_YZ_PLANE ) vptr = yzplane;

	IGLUVertexArray::Ptr tmp = new IGLUVertexArray();
	tmp->SetVertexArray( sizeof( xyplane ), vptr, IGLU_STATIC|IGLU_DRAW );
	tmp->EnableAttribute( IGLU_ATTRIB_VERTEX, 3, GL_FLOAT, 9 * sizeof(float), BUFFER_OFFSET(6*sizeof(float)) );
	if (type & IGLU_GEOM_USE_NORMAL) 
		tmp->EnableAttribute( IGLU_ATTRIB_NORMAL, 3, GL_FLOAT, 9 * sizeof(float), BUFFER_OFFSET(3*sizeof(float)) );
	if (type & IGLU_GEOM_USE_TEXCOORD) 
		tmp->EnableAttribute( IGLU_ATTRIB_TEXCOORD, 2, GL_FLOAT, 9 * sizeof(float), BUFFER_OFFSET(1*sizeof(float)) );

	return tmp;
}
// Do a pointwise difference between two XYZ curves and store into a renderable vertex array
IGLUVertexArray::Ptr DifferenceToVertexArray( XYZAbstract *approx, XYZAbstract *curve )
{
	IGLUVertexArray::Ptr vArr = new IGLUVertexArray();
	float *arrData = (float *)malloc( sizeof(float) * 4 * 471 );
	float *fptr = arrData;
	for (int i=360; i<=830; i++)
	{
		*(fptr++) = float(i);
		*(fptr++) = approx->X(float(i))-curve->X(float(i));
		*(fptr++) = approx->Y(float(i))-curve->Y(float(i));
		*(fptr++) = approx->Z(float(i))-curve->Z(float(i));
	}
	vArr->SetVertexArray( sizeof(float) * 4 * 471, arrData );
	vArr->EnableAttribute( IGLU_ATTRIB_VERTEX, 4, GL_FLOAT );
	free( arrData );
	return vArr;
}
Beispiel #4
0
	void VORApp::Display()
	{
#ifdef TEST
		_cpuTimer->Start();
		_gpuTimer->Start();
#endif
		_mirrorTransforms[0] *= IGLUMatrix4x4::Rotate(10,vec3(0,1,0));
		// Start timing this frame draw
		_frameRate->StartFrame();
		// Clear the screen
		glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
		
		
		size_t frustumSize = 0;
		size_t size = VirtualFrustumsCulling(frustumSize);

#ifdef TEST
		_cpuTimer->Tick();
		_gpuTimer->Tick();
		printf("VirtualFrustums Culling gpu: %lf cpu: %lf \n", _gpuTimer->Tick(), _cpuTimer->Tick());
#endif

		//size_t size = CPUVirtualFrustumsCulling(frustumSize);
		//draw stencil
		{
			_mirrorStencilFBO->Bind();
			_mirrorStencilFBO->Clear();
			_shaders[3]->Enable();
			_shaders[3]["project"]         = _camera->GetProjectionMatrix();
			_shaders[3]["model"]           = _mirrorTransforms[0];
			_shaders[3]["view"]            = _camera->GetViewMatrix();
			_mirrorObjs[0]->GetVertexArray()->Bind();
			_mirrorElementBuffer->Bind();
			//_mirrorObjs[0]->GetVertexArray()->GetElementArray()->Bind();
			glDrawElements(GL_TRIANGLES,frustumSize*3,GL_UNSIGNED_INT,0);
			//_mirrorObjs[0]->GetVertexArray()->GetElementArray()->Unbind();
			_mirrorElementBuffer->Unbind();
			_mirrorObjs[0]->GetVertexArray()->Unbind();
			_shaders[3]->Disable();
			_mirrorStencilFBO->Unbind();
		/*	IGLUDraw::Fullscreen( _mirrorStencilFBO[IGLU_COLOR0], 0 );
			return;		*/
		}
	
		_mirrorFBO->Bind();
		_mirrorFBO->Clear();
		glEnable(GL_DEPTH_TEST);	
		glEnable(GL_CULL_FACE);
		for(int i=0; i<_objReaders.size(); i++)
		{
			_shaders[2]->Enable();
			_shaders[2]["project"] = _camera->GetProjectionMatrix();	
			_shaders[2]["view"] = _camera->GetViewMatrix();
			_shaders[2]["model"]  = _objTransforms[i];
			_shaders[2]["mirrorModel"] = _mirrorTransforms[0];
			_shaders[2]["InstanceData"] = _instanceDataTex;
			_shaders[2]["lightIntensity" ] = float(1);
			_shaders[2]["matlInfoTex"]     = IGLUOBJMaterialReader::s_matlCoefBuf;
			_shaders[2]["matlTextures"]    = IGLUOBJMaterialReader::s_matlTexArray;
			_shaders[2]["lightColor"] = vec3(1.0);	
			_shaders[2]["resX"] = _camera->GetResX();
			_shaders[2]["resY"] = _camera->GetResY();
			_shaders[2]["stencilTexture"] = _mirrorStencilFBO[0];
			IGLUVertexArray::Ptr vao = _objReaders[i]->GetVertexArray();
			vao->Bind();			
			vao->GetElementArray()->Bind();			
			_indirectDrawBuffer->Bind();
			glMultiDrawElementsIndirect(	GL_TRIANGLES, 	GL_UNSIGNED_INT, 	NULL, 	size, 	0);
			_indirectDrawBuffer->Unbind();
			vao->GetElementArray()->Unbind();
			vao->Unbind();			
			_shaders[2]->Disable();			
		}
		_mirrorFBO->Unbind();
	/*	IGLUDraw::Fullscreen( _mirrorFBO[IGLU_COLOR0], 0 );
		return;*/
		_mirrorTexShader->Enable();
		_mirrorTexShader["project"]         = _camera->GetProjectionMatrix();
		_mirrorTexShader["modelview"]            = _camera->GetViewMatrix() *_mirrorTransforms[0];		
		_mirrorTexShader["mtexture"] = _mirrorFBO[0];

		_mirrorObjs[0]->GetVertexArray()->Bind();
		_mirrorElementBuffer->Bind();		
		glDrawElements(GL_TRIANGLES,frustumSize*3,GL_UNSIGNED_INT,0);		
		_mirrorElementBuffer->Unbind();
		_mirrorObjs[0]->GetVertexArray()->Unbind();

		_mirrorTexShader->Disable();

		for(int i=0; i<_objReaders.size(); i++)
		{
			_objShader->Enable();
			_objShader["project"]         = _camera->GetProjectionMatrix();
			_objShader["model"]           = _objTransforms[i];
			_objShader["view"]            = _camera->GetViewMatrix();
			_objShader["lightIntensity" ] = float(1);
			_objShader["matlInfoTex"]     = IGLUOBJMaterialReader::s_matlCoefBuf;
			_objShader["matlTextures"]    = IGLUOBJMaterialReader::s_matlTexArray;			
			_objShader["lightColor"] = _lightColor;
			_objReaders[i]->GetVertexArray()->Bind();
			_objReaders[i]->GetVertexArray()->GetElementArray()->Bind();
			glDrawElements(GL_TRIANGLES,_objReaders[i]->GetTriangleCount()*3,GL_UNSIGNED_INT,0);
			_objReaders[i]->GetVertexArray()->GetElementArray()->Unbind();
			_objReaders[i]->GetVertexArray()->Unbind();
			_objShader->Disable();
		}
		// Draw the framerate on the screen
		char buf[32];
		sprintf( buf, "%.1f fps", _frameRate->EndFrame() );
		IGLUDraw::DrawText( IGLU_FONT_VARIABLE, 0, 0, buf );
	}
// Draw
void display ( void )
{
	int j=0;
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	glLineWidth( GLfloat(lineWidth) );

	if (!useErrors)
	{
		// Bind and setup the shader
		draw->Enable();
		draw["xRange"] = vec2( 330.0f, 843.0f );
		draw["yRange"] = vec2( -0.13f, 2.05f );
		draw["useXYZ"]    = vec3( displayX ? 1.0f : 0.0f, 
								  displayY ? 1.0f : 0.0f, 
								  displayZ ? 1.0f : 0.0f );
			// For each curve, check if it's selected to be display, if so, draw it
			for (uint i=0; i<drawableCurves.Size(); i++)
			{
				// Check if this curve was selected to be drawn
				if ( curveSelection[i]->GetValue() )
				{
					draw["xColor"] = colorArr[j++];
					draw["yColor"] = colorArr[j++];
					draw["zColor"] = colorArr[j++];
					drawableCurves[i]->DrawArrays( GL_LINE_STRIP, 0, 471 );
				}
			}
		draw->Disable();

		// After drawing the curve, draw the axes
		drawAxes->Enable();
			axes->DrawArrays( GL_LINES, 0, 38 );
		drawAxes->Disable();
	}
	else
	{
		// Bind and setup the shader
		draw->Enable();
		draw["xRange"] = vec2( 330.0f, 843.0f );
		draw["yRange"] = vec2( -0.25f, 0.25f );
		draw["useXYZ"]    = vec3( displayX ? 1.0f : 0.0f, 
								  displayY ? 1.0f : 0.0f, 
								  displayZ ? 1.0f : 0.0f );
			// For each curve, check if it's selected to be display, if so, draw it
			for (uint i=0; i<errorCurves.Size(); i++)
			{
				// Check if this curve was selected to be drawn
				if ( curveSelection[i]->GetValue() )
				{
					draw["xColor"] = colorArr[j++];
					draw["yColor"] = colorArr[j++];
					draw["zColor"] = colorArr[j++];
					errorCurves[i]->DrawArrays( GL_LINE_STRIP, 0, 471 );
				}
			}
		draw->Disable();
	}

	// Draw the labels
	for (int i=0; i<10; i++)
		IGLUDraw::DrawColorText( IGLU_FONT_VARIABLE, 
		                         int(textOffsetFactor.X()*labels[i].x), 
								 int(textOffsetFactor.Y()*labels[i].y), 
								 color::Gray80, labels[i].name, textOffsetFactor.X() );
}