예제 #1
0
파일: main.cpp 프로젝트: seoushi/Lavish
int main(int argc, char** argv)
{
    Display d;
	
    d.Initialize(800, 600, 24, "Tutorial 4");
	
    if( d.Show() == false )
    {
        std::cout << "Failed to open window, exiting." << std::endl;
        return 1;
    }
	
    d.ClearColor( Color::Blue() );
	
	auto m = std::make_shared<Model>("data/cube.obj");
	
	uint time = Timer::GetCurrentGameTime();
	
	auto modelTransformations = Matrix4::Translate(0.0f, 0.0f, -10.0f);
	
	float angle;
	
    while(d.Listener()->Update())
    {
		//rotate model
		angle = 90.0f * (((float)(Timer::GetCurrentGameTime() - time)) / 1000.0f);
		
		(*modelTransformations) *= (*Matrix4::RotateX(angle));
		(*modelTransformations) *= (*Matrix4::RotateY(angle));
		(*modelTransformations) *= (*Matrix4::RotateZ(angle));
		
		time = Timer::GetCurrentGameTime();


        d.ClearScreen();
        d.SetupPerspective(45.0f, 0.1f, 100.0f);
		
		m->Render(modelTransformations);
		
        d.SwapBuffers();
    }
	
    return 0;
}
예제 #2
0
파일: main.cpp 프로젝트: seoushi/Lavish
int main(int argc, char** argv)
{
    Display d;
	
    d.Initialize(800, 600, 24, "Sample 03");
	
    if( d.Show() == false )
    {
        std::cout << "Failed to open window, exiting." << std::endl;
        return 1;
    }
	
    d.ClearColor( Color::White() );
	
	
    VertexBuffer<VertexColor> vbo(3);
	
    vbo.AddElement( VertexColor( Vector3(0.0f, 0.5f, -2.0f),
                                Color::Red()));
    vbo.AddElement( VertexColor( Vector3(0.5f, -0.5f, -2.0f),
                                Color::Green()));
    vbo.AddElement( VertexColor( Vector3(-0.5f, -0.5f, -2.0f),
                                Color::Blue()));
    
    vbo.Generate();
	
	
	//load shaders
	auto ss = std::make_shared<ShaderSet>();
	auto vert = std::make_shared<Shader>("data/Shader.vert", shader::Vertex);
	auto frag = std::make_shared<Shader>("data/Shader.frag", shader::Fragment);
	
	ss->AddShader(vert);
	ss->AddShader(frag);
	
	ss->Finalize();
	
	GLint uniformId = ss->GetUniformId("translate");
	float transY = 0.0f;
	
	uint time = Timer::GetCurrentGameTime();
	
    while(d.Listener()->Update())
    {
        d.ClearScreen();
		
        d.SetupPerspective(45.0f, 0.1f, 100.0f);
        
		ss->Bind();
		
		// update the shader translation
		transY += ((float)(Timer::GetCurrentGameTime() - time)) / 200.0f;
		time = Timer::GetCurrentGameTime();
		glUniform1f(uniformId, transY);

		
        vbo.Bind();
        glDrawArrays(GL_TRIANGLES, 0, 3);
        vbo.Unbind();
		
		ss->Unbind();
		
        d.SwapBuffers();
    }
	
    return 0;
}