コード例 #1
0
void RawOpenGLManager::updateAnimation( Renderable& toUpdate , const float& dt )
{


void RawOpenGLManager::updateAnimationMatricesRecurse( unsigned int boneIndex , BoneInfo* bones , Renderable& toUpdate , glm::mat4& parentMatrix )
{

}

void RawOpenGLManager::drawAll()
{
	for ( int i = 0; i < MAX_RENDERABLES && renderableInfos[i].whatGeometryIndex != nullptr; i++ )
	{
		if ( renderableInfos[i].visible )
		{
			glUseProgram( renderableInfos[i].howShaderIndex->programID );
			glBindVertexArray( renderableInfos[i].whatGeometryIndex->dataArray );

			if ( renderableInfos[i].depthTestEnabled ) glEnable( GL_DEPTH_TEST );
			else glDisable( GL_DEPTH_TEST );

			if ( renderableInfos[i].alpha )
			{
				glEnable( GL_BLEND );
				glBlendFunc( GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA );
			}
			else
			{
				glDisable( GL_BLEND );
			}

			if ( renderableInfos[i].culling == CT_NONE ) glDisable( GL_CULL_FACE );
			else
			{
				glEnable( GL_CULL_FACE );
				if ( renderableInfos[i].culling == CT_FRONT ) glCullFace( GL_FRONT );
				else if ( renderableInfos[i].culling == CT_BOTH ) glCullFace( GL_FRONT_AND_BACK );
				else glCullFace( GL_BACK );
			}

			if ( renderableInfos[i].textureID != NULL )
			{
				for ( unsigned int j = 0; j < renderableInfos[i].textureID->size; j++ )
				{
					glActiveTexture( GL_TEXTURE0 + j );
					glBindTexture( renderableInfos[i].textureID->textureIDs[j].type, renderableInfos[i].textureID->textureIDs[j].textureID );
				}
			}

			for ( int j = 0; globalUniforms[j].location != nullptr; j++ )
			{
				setUniformParameter( renderableInfos[i].howShaderIndex , globalUniforms[j].uniformName.c_str() , globalUniforms[j].type , globalUniforms[j].location );
			}

			for ( int j = 0; renderableInfos[i].uniforms[j].location != nullptr; j++ )
			{
				setUniformParameter( renderableInfos[i].howShaderIndex , renderableInfos[i].uniforms[j].uniformName.c_str() , renderableInfos[i].uniforms[j].type , renderableInfos[i].uniforms[j].location );
			}

			const char* st = renderableInfos[i].whereUniform.c_str();
			glm::quat quaternion = glm::rotate( glm::quat() , renderableInfos[i].rotate.x , glm::vec3( 1 , 0 , 0 ) ) *
				glm::rotate( glm::quat() , renderableInfos[i].rotate.y , glm::vec3( 0 , 1 , 0 ) ) *
				glm::rotate( glm::quat() , renderableInfos[i].rotate.z , glm::vec3( 0 , 0 , 1 ) );
			glm::mat4 transform = glm::translate( glm::mat4() , renderableInfos[i].translate ) * glm::mat4_cast( quaternion ) * glm::scale( glm::mat4() , renderableInfos[i].scale );

			setUniformParameter( renderableInfos[i].howShaderIndex , st , ParameterType::PT_MAT4 , &transform[0][0] );

			if ( renderableInfos[i].animationMatrices )
			{
				setUniformParameter( renderableInfos[i].howShaderIndex ,
									 renderableInfos[i].animationMatricesUniform.c_str() ,
									 PT_MAT4 ,
									 reinterpret_cast<const float*>( renderableInfos[i].animationMatrices ) ,
									 renderableInfos[i].sizeofAnimationMatrices );
			}

			glDrawElements( renderableInfos[i].whatGeometryIndex->indexingMode , renderableInfos[i].whatGeometryIndex->numIndex , GL_UNSIGNED_SHORT , ( void* ) renderableInfos[i].whatGeometryIndex->indexOffset );
		}
	}
}
コード例 #2
0
ファイル: GameWidget.cpp プロジェクト: JonECG/Cpp-Game-Engine
void GameWidget::init()
{
	glEnable( GL_TEXTURE_2D );
	glEnable( GL_DEPTH_TEST );

	ShaderInfo* textShad = addShaderInfo( "res/texture.vert", "res/texture.frag" );

	Neumont::ShapeData teapot = Neumont::ShapeGenerator::makeTeapot( 5, glm::mat4() );

	TextureInfo* brick = addTexture( "res/brick.png" );
	TextureInfo* mask = addTexture( "res/Frigate.png" );

	tightness = 40.0f;
	
	GeometryInfo* cubeGeo = loadFile( "res/cube.mod" );
	setUpAttribs( cubeGeo );
	GeometryInfo* maskGeo = loadFile( "res/Frigate.mod" );
	setUpAttribs( maskGeo );
	GeometryInfo* teapotGeo = addGeometry( teapot.verts, teapot.numVerts, teapot.indices, teapot.numIndices, GL_TRIANGLES );
	setUpAttribs( teapotGeo );

	camera = Camera( float(width())/height(), 0.1, 100 );
	camera.setFrom( glm::vec3( 0,0,4) );
	camera.setTo( glm::vec3(0,0,0) );

	renderableTests = new Renderable*[3];
	renderableTests[0] = addRenderable( maskGeo, glm::scale( glm::vec3( 0.02f ) ), textShad, mask );
	renderableTests[1] = addRenderable( cubeGeo, glm::translate( glm::vec3( -0.3, -0.4, 0 ) ) * glm::scale(glm::vec3(0.15)) , textShad, brick );


	addUniformParameter( textShad, "mvp", PT_MAT4, (float*)&camera.mvp );

	
	setUniformParameter( textShad, "amblight", PT_VEC4, (float*)&glm::vec4(0.1f,0.1f,0.1f,1) );
	setUniformParameter( textShad, "diffpos", PT_VEC4, (float*)&glm::vec4(0.0f,8.0f,0.0f,1) );
	setUniformParameter( textShad, "difflight", PT_VEC4, (float*)&glm::vec4(0.8f,0.8f,0.8f,1));
	setUniformParameter( textShad, "specColor", PT_VEC4, (float*)&glm::vec4(0.8f,0.8f,0.8f,1));
	addUniformParameter( textShad, "tightness", PT_FLOAT, (float*)&(tightness) );
	addUniformParameter( textShad, "eye", PT_VEC4, (float*)&camera.from);

	DebugShapes::addPoint( textShad, glm::translate(glm::vec3(0,2,0))*glm::rotate( glm::mat4(), 40.0f, glm::normalize( glm::vec3( -0.8f,0.4f,0.1f ) ) ) );
	DebugShapes::addPoint( textShad, glm::translate(glm::vec3(3,-2,0)), -1, true );
	DebugShapes::addLine( textShad, glm::vec3(-1, 2, 0), glm::vec3(3, 3, 1), glm::vec4(0,1,1,1), 7 );
	DebugShapes::addVector( textShad, glm::vec3(-1, 0, 0), glm::vec3(0, 0, 1), glm::vec4(1,0,1,1), 8 );
	DebugShapes::addCube( textShad, glm::translate(glm::vec3(2,2,0)), glm::vec4(1,1,0,1), 8, false );
	DebugShapes::addSphere( textShad, glm::translate(glm::vec3(-3.0f,-2.0f,0.0f)), glm::vec4(1,0.5f,0,1), 3, true );
	DebugShapes::addSphere( textShad, glm::translate(glm::vec3(3.0f,2.0f,0.0f)), glm::vec4(1,0,0,1), 6, true );

	DebugShapes::addPoint( textShad, glm::translate(glm::vec3(-3,0,-5)), -1, false );
	DebugShapes::addLine( textShad, glm::vec3(-3,2,-5), glm::vec3(3, 2, -5), glm::vec4(0,1,1,1), -1, false );
	DebugShapes::addVector( textShad, glm::vec3(-1.5f, 0, -5), glm::vec3(0, 0, 1), glm::vec4(1,0,1,1), -1, false );
	DebugShapes::addCube( textShad, glm::translate(glm::vec3(0,0,-5)), glm::vec4(1,1,0,1), -1, false );
	DebugShapes::addSphere( textShad, glm::translate(glm::vec3(3,0,-5)), glm::vec4(1,0,0,1), -1, false );

	// HIPPO
	DebugMenus::watchFloat( "FPS", fps );
	DebugMenus::watchFloat( "Delta Time", delta );
	DebugMenus::slideFloat("Specular Tightness", tightness, 0.0f, 100.0f );
	DebugMenus::slideVector( "Ship Position", shipPos, -1.0f, 1.0f );
	DebugMenus::toggleBool("Ship visible", renderableTests[0]->visible);
}