当前位置: 首页>>代码示例>>C++>>正文


C++ MatrixF::GetData方法代码示例

本文整理汇总了C++中MatrixF::GetData方法的典型用法代码示例。如果您正苦于以下问题:C++ MatrixF::GetData方法的具体用法?C++ MatrixF::GetData怎么用?C++ MatrixF::GetData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MatrixF的用法示例。


在下文中一共展示了MatrixF::GetData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
{
    try
    {
        Image image;
        image.Load("resources/jattabox.png");

        WindowStyle style;
        style.title = U8("CGUL - 3D World");
        style.size = UCoord32(640, 480);
        style.backgroundColor = Colors::black;
        style.resizable = true;

        Window window;
        window.Create(style);

        OpenGL::Context context;
        context.Create(&window);

        GL::BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        GL::Enable(GL_BLEND);
        GL::Enable(GL_ALPHA_TEST);
        GL::Enable(GL_TEXTURE_2D);
        GL::Enable(GL_DEPTH_TEST);
        GL::Enable(GL_CULL_FACE);
        glCullFace(GL_BACK);

        UIntN program = LoadShader(U8("resources/shader.vert"), U8("resources/shader.frag"));

        UIntN box = MakeBox();

        UIntN texture;
        GL::GenTextures(1, &texture);
        GL::BindTexture(GL_TEXTURE_2D, texture);
        GL::TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        GL::TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        GL::TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        GL::TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        GL::TexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
        GL::PixelStorei(GL_UNPACK_ALIGNMENT, 1);
        GL::TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.GetWidth(), image.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, image.GetData< void >());
        GL::BindTexture(GL_TEXTURE_2D, 0);

        Timer timer;
        Float32 hue = 0.0f;
        while (window.IsOpen())
        {
            Float32 deltaTime = timer.GetDeltaTime();
            Timer::Sleep(1);
            hue = Math::Mod(hue + deltaTime * 0.125f, 1.0f);
            context.ClearColor(Color::MakeHSV(hue, 0.156862745098039f, 1.0f));

            Float32 movement = 1 + Math::Cos(hue / 10.0f);
            static Float32 rot = 0;
            rot += deltaTime / 1.0f;

            context.Viewport(0, 0, window.GetWidth(), window.GetHeight());
            context.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT);
            GL::UseProgram(program);
            //GL::UniformMatrix4fv(GL::GetUniformLocation(program, "orthoMatrix"), 1, false, Matrix::MakeOrtho2D(0, 1280, 768, 0).GetData());
            MatrixF view = MatrixF::MakeLookAt(Vector3F(Math::Cos(rot) * 50, Math::Cos(rot) * 50, Math::Sin(rot) * 50), Vector3F(0, 0, 0), Vector3F(0, -1, 0));
            MatrixF projection = MatrixF::MakePerspective(45.0, window.GetWidth() / (Float32)window.GetHeight(), 1, 1000);
            MatrixF vp = view * projection;

            MatrixF model;
            model = MatrixF::MakeScaling(Vector3F(20, 20, 20)) * model;

            //Matrix wvp = model * Matrix::MakeOrtho2D(0, 1280, 768, 0);
            MatrixF wvp = model * vp;
            GL::UniformMatrix4fv(GL::GetUniformLocation(program, "matrix"), 1, false, wvp.GetData());
            GL::Uniform1i(GL::GetUniformLocation(program, "texture"), 0);
            GL::ActiveTexture(GL_TEXTURE0);
            GL::BindTexture(GL_TEXTURE_2D, texture);
            GL::BindVertexArray(box);
            GL::DrawArrays(GL_QUADS, 0, 24);
            GL::BindVertexArray(0);
            GL::UseProgram(0);
            context.SwapBuffers();

            Window::Update();
        }
    }
    catch (Exception& e)
    {
        std::cout << e.what() << std::endl;
        std::cout << std::hex << "Error code: 0x" << e.unique << std::dec << " (decimal " << e.unique << ")" << std::endl;
    }
}
开发者ID:Zethes,项目名称:CGUL,代码行数:88,代码来源:main.cpp


注:本文中的MatrixF::GetData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。