Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
int main(int argc, char** argv)
{
	int ScreenWidth = 800;
	int ScreenHeight = 600;

	Display d;

	d.Initialize(ScreenWidth, ScreenHeight, 24, "Sample 06");

	if( d.Show() == false )
	{
		std::cout << "Failed to open window, exiting." << std::endl;
		return 1;
	}

	Font font;
	font.Load("data/arial-32.lfd", "data/arial-32.png");

	d.ClearColor( Color::Blue() );
		
	
	std::wstring text = L"The quick brown fox jumps over the lazy dog.!@#$%^&*()";
	auto textPos = Matrix4::Translate((float)(ScreenWidth / 2) - (font.StringWidth(text) / 2), 
										 (float)ScreenHeight / 2,
										 0);
	
    while(d.Listener()->Update())
	{
		d.ClearScreen();
		d.Setup2d();

		font.DrawString(text, textPos);
		
		d.SwapBuffers();
    }
	
    return 0;
}
Ejemplo n.º 3
0
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;
}