예제 #1
0
void InitApp(float width, float height)
{
	vec2 min, max;
	//fill in the blank
	min.x = -width/2;
	min.y = -height/2;
	max.x = width/2;
	max.y = height/2;

	pApp = new App();
	Screen* pScreen = new Screen(min.x, min.y, max.x, max.y); // create the screen so you can start using gl functions!
	//programs
	ProgramManager* pProgramManager = ProgramManager::GetProgramManager();
	int programID = pProgramManager->CreateProgram("vertex2.vert", "fragment2.frag");
	pProgramManager->AddProgram("program1", programID);
	//now add textures and programs to the App
	TextureManager* pTextureManager = TextureManager::GetTextureManager();
	pTextureManager->AddTexture("images/picture.png");
	
	//add objects
	vec2 quadDimensions = {512.0f, 512.0f};
	GLuint indices[6] = {0, 1, 3, 3, 1, 2};
	pScreen->SetMatrixUniform(); // set the projection matrix
	Quad* pQuad = new Quad(&quadDimensions, indices, 6, "images/picture.png", "program1");
	pScreen->AddObject(pQuad);
	pApp->AddObject(pScreen);
}
/*!
	Initialize the scene, reserve shaders, compile and cache program

	\param[in] None.
	\return None

*/
void ObjLoader::InitModel()
{
	ProgramManager* ProgramManagerObj   = MapRenderHandler->RendererProgramManager();
	Transform*	TransformObj            = MapRenderHandler->RendererTransform();


	if (! ( program = ProgramManagerObj->Program( ( char * )"PolkaShader" ) ) )
	{
		program = ProgramManagerObj->ProgramInit( ( char * )"PolkaShader" );
		ProgramManagerObj->AddProgram( program );
	}

	program->VertexShader	= ShaderManager::ShaderInit( VERTEX_SHADER_PRG,	GL_VERTEX_SHADER	);
	program->FragmentShader	= ShaderManager::ShaderInit( FRAGMENT_SHADER_PRG, GL_FRAGMENT_SHADER	);

    //////////////////////////////////////////////////////
    /////////// Vertex shader //////////////////////////
    //////////////////////////////////////////////////////
	CACHE *m = reserveCache( VERTEX_SHADER_PRG, true );

	if( m ) {
		if( !ShaderManager::ShaderCompile( program->VertexShader, ( char * )m->buffer, 1 ) ) exit( 1 );
        freeCache( m );
	}

    /////////// Fragment shader //////////////////////////
	m = reserveCache( FRAGMENT_SHADER_PRG, true );
	if( m ) {
		if( !ShaderManager::ShaderCompile( program->FragmentShader, ( char * )m->buffer, 1 ) ) exit( 2 );
        freeCache( m );
	}

    if( !ProgramManagerObj->ProgramLink( program, 1 ) ) exit( 3 );

    // Use Phong Shade Program
    glUseProgram( program->ProgramID );
    
    char MaterialAmbient   = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"MaterialAmbient");
    char MaterialSpecular  = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"MaterialSpecular");
    char MaterialDiffuse   = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"MaterialDiffuse");
    char LightAmbient      = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"LightAmbient");
    char LightSpecular     = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"LightSpecular");
    char LightDiffuse      = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"LightDiffuse");
    char ShininessFactor   = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"ShininessFactor");
    char LightPosition     = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"LightPosition");
        timer              = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"Time");
    toggleIndex           = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"toggleDiscardBehaviour");
    char Side              = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"Side");
    char DotSize           = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"DotSize");
    
    char ModelColor           = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"ModelColor");
    char DotColor           = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"DotColor");
    char BackSideModelColor           = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"BackSideModelColor");
    char BackSideDotColor           = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"BackSideDotColor");
    
    if (MaterialAmbient >= 0){
        glUniform3f(MaterialAmbient, 0.04f, 0.04f, 0.04f);
    }
    
    if (MaterialSpecular >= 0){
        glUniform3f(MaterialSpecular, 1.0, 0.5, 0.5);
    }
    
    glm::vec3 color = glm::vec3(1.0, 1.0, 1.0);
    if (MaterialDiffuse >= 0){
        glUniform3f(MaterialDiffuse, color.r, color.g, color.b);
    }

    if (LightAmbient >= 0){
        glUniform3f(LightAmbient, 1.0f, 1.0f, 1.0f);
    }
    
    if (LightSpecular >= 0){
        glUniform3f(LightSpecular, 1.0, 1.0, 1.0);
    }

    if (LightDiffuse >= 0){
        glUniform3f(LightDiffuse, 1.0f, 1.0f, 1.0f);
    }

    if (ShininessFactor >= 0){
        glUniform1f(ShininessFactor, 40);
    }
    
    if (LightPosition >= 0){
        glUniform3f(LightPosition, 0.0, 0.0, 10.0 );
    }

    if ( toggleIndex >= 0 ){
        glUniform1i(toggleIndex, (int)toggle);
    }
    
    if ( Side >= 0 ){
        glUniform1f(Side, 0.30);
    }
    
    if ( DotSize >= 0 ){
        glUniform1f(DotSize, 0.13);
    }
    
    if (ModelColor >= 0){
        glUniform3f(ModelColor, 1.0, 1.0, 1.0 );
    }
    
    if (DotColor >= 0){
        glUniform3f(DotColor, 0.4, 0.5, 1.0 );
    }
    
    if (BackSideModelColor >= 0){
        glUniform3f(BackSideModelColor, 0.0, 1.0, 0.0 );
    }
    
    if (BackSideDotColor >= 0){
        glUniform3f(BackSideDotColor, 1.0, 1.0, 1.0 );
    }
    
    MVP = ProgramManagerObj->ProgramGetUniformLocation( program, ( char* )"ModelViewProjectionMatrix" );
    MV  = ProgramManagerObj->ProgramGetUniformLocation( program, ( char* )"ModelViewMatrix" );
    NormalMatrix  = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"NormalMatrix");
    

    return;
}
/*!
	Initialize the scene, reserve shaders, compile and cache program

	\param[in] None.
	\return None

*/
void ObjLoader::InitModel()
{
	ProgramManager* ProgramManagerObj   = MapRenderHandler->RendererProgramManager();
	Transform*	TransformObj            = MapRenderHandler->RendererTransform();


	if (! ( program = ProgramManagerObj->Program( ( char * )"ADSShader" ) ) )
	{
		program = ProgramManagerObj->ProgramInit( ( char * )"ADSShader" );
		ProgramManagerObj->AddProgram( program );
	}

	program->VertexShader	= ShaderManager::ShaderInit( VERTEX_SHADER_PRG,	GL_VERTEX_SHADER	);
	program->FragmentShader	= ShaderManager::ShaderInit( FRAGMENT_SHADER_PRG, GL_FRAGMENT_SHADER	);

    //////////////////////////////////////////////////////
    /////////// Vertex shader //////////////////////////
    //////////////////////////////////////////////////////
	CACHE *m = reserveCache( VERTEX_SHADER_PRG, true );

	if( m ) {
		if( !ShaderManager::ShaderCompile( program->VertexShader, ( char * )m->buffer, 1 ) ) exit( 1 );
        freeCache( m );
	}

    /////////// Fragment shader //////////////////////////
	m = reserveCache( FRAGMENT_SHADER_PRG, true );
	if( m ) {
		if( !ShaderManager::ShaderCompile( program->FragmentShader, ( char * )m->buffer, 1 ) ) exit( 2 );
        freeCache( m );
	}

    if( !ProgramManagerObj->ProgramLink( program, 1 ) ) exit( 3 );

    // Use Phong Shade Program
    glUseProgram( program->ProgramID );
    
    char MaterialAmbient   = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"MaterialAmbient");
    char MaterialSpecular  = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"MaterialSpecular");
    char MaterialDiffuse   = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"MaterialDiffuse");
    char LightAmbient      = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"LightAmbient");
    char LightSpecular     = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"LightSpecular");
    char LightDiffuse      = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"LightDiffuse");
    char ShininessFactor   = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"ShininessFactor");
    char LightPosition     = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"LightPosition");
    char ModelColor        = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"ModelColor");
    char DotColor          = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"DotColor");
    char Side              = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"Side");
    
    if (MaterialAmbient >= 0){
        glUniform3f(MaterialAmbient, 0.04f, 0.04f, 0.04f);
    }
    
    if (MaterialSpecular >= 0){
        glUniform3f(MaterialSpecular, 1.0, 1.0, 1.0);
    }
    
    glm::vec3 color = glm::vec3(1.0, 1.0, 0.0);
    if (MaterialDiffuse >= 0){
        glUniform3f(MaterialDiffuse, color.r, color.g, color.b);
    }
    
    if (LightAmbient >= 0){
        glUniform3f(LightAmbient, 1.0f, 1.0f, 1.0f);
    }
    
    if (LightSpecular >= 0){
        glUniform3f(LightSpecular, 1.0, 1.0, 1.0);
    }
    
    if (LightDiffuse >= 0){
        glUniform3f(LightDiffuse, 1.0f, 1.0f, 1.0f);
    }
    
    if (ShininessFactor >= 0){
        glUniform1f(ShininessFactor, 40);
    }
    
    if ( LightPosition >= 0 ){
        glm::vec3 lightPosition(0.0, 5.0, 10);
        glUniform3fv(LightPosition, 1, (float*)&lightPosition);
    }
    
    if ( ModelColor >= 0 ){
        glm::vec3 mColor(0.50, 0.50, 1.0);
        glUniform3fv(ModelColor, 1, (float*)&mColor);
    }

    if ( DotColor >= 0 ){
        glm::vec3 dColor(1.0, 1.0, 10);
        glUniform3fv(DotColor, 1, (float*)&dColor);
    }
    
    if ( Side >= 0 ){
        glUniform1f(Side, 80);
    }
    

    MVP = ProgramManagerObj->ProgramGetUniformLocation( program, ( char* )"ModelViewProjectionMatrix" );
    MV  = ProgramManagerObj->ProgramGetUniformLocation( program, ( char* )"ModelViewMatrix" );
    NormalMatrix  = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"NormalMatrix");
    
    return;
}
/*!
	Initialize the scene, reserve shaders, compile and cache program

	\param[in] None.
	\return None

*/
void ObjLoader::InitModel()
{
	ProgramManager* ProgramManagerObj   = MapRenderHandler->RendererProgramManager();
	Transform*	TransformObj            = MapRenderHandler->RendererTransform();


	if (! ( program = ProgramManagerObj->Program( ( char * )"SpecularShader" ) ) )
	{
		program = ProgramManagerObj->ProgramInit( ( char * )"SpecularShader" );
		ProgramManagerObj->AddProgram( program );
	}

	program->VertexShader	= ShaderManager::ShaderInit( VERTEX_SHADER_PRG,	GL_VERTEX_SHADER	);
	program->FragmentShader	= ShaderManager::ShaderInit( FRAGMENT_SHADER_PRG, GL_FRAGMENT_SHADER	);

    /////////// Vertex shader //////////////////////////
	CACHE *m = reserveCache( VERTEX_SHADER_PRG, true );

	if( m ) {
		if( !ShaderManager::ShaderCompile( program->VertexShader, ( char * )m->buffer, 1 ) ) exit( 1 );
        freeCache( m );
	}

    /////////// Fragment shader //////////////////////////
	m = reserveCache( FRAGMENT_SHADER_PRG, true );
	if( m ) {
		if( !ShaderManager::ShaderCompile( program->FragmentShader, ( char * )m->buffer, 1 ) ) exit( 2 );
        freeCache( m );
	}

    if( !ProgramManagerObj->ProgramLink( program, 1 ) ) exit( 3 );

    glUseProgram( program->ProgramID );
    
    char MaterialSpecular  = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"MaterialSpecular");
    char LightSpecular     = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"LightSpecular");
    char ShininessFactor   = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"ShininessFactor");
    char LightPosition     = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"LightPosition");

    if (MaterialSpecular >= 0){
        glUniform3f(MaterialSpecular, 1.0, 0.5, 0.5);
    }
    
    if (LightSpecular >= 0){
        glUniform3f(LightSpecular, 1.0, 1.0, 1.0);
    }

    if (ShininessFactor >= 0){
        glUniform1f(ShininessFactor, 40);
    }
    
    if (LightPosition >= 0){
        glm::vec3 lightPosition(0.0, 0.0, 10.0);
        glUniform3fv(LightPosition, 1, (float*)&lightPosition);
    }
    
    MVP = ProgramManagerObj->ProgramGetUniformLocation( program, ( char* )"ModelViewProjectionMatrix" );
    MV  = ProgramManagerObj->ProgramGetUniformLocation( program, ( char* )"ModelViewMatrix" );
    NormalMatrix  = ProgramManagerObj->ProgramGetUniformLocation(program, (char*)"NormalMatrix");

    return;
}