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


C++ Framebuffer::addColor方法代码示例

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


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

示例1: main

int main()
{
    initCrashSystem();
    initMemorySystem();

    SDL_Init(SDL_INIT_EVERYTHING);

    SDL_Window *window = SDL_CreateWindow("",
                                          SDL_WINDOWPOS_UNDEFINED,
                                          SDL_WINDOWPOS_UNDEFINED,
                                          640,
                                          640,
                                           SDL_WINDOW_OPENGL
                                          |SDL_WINDOW_RESIZABLE
                                          |SDL_WINDOW_SHOWN);

    SDL_GLContext context = createContext(window);

    SDL_GL_SetSwapInterval(1);

    bool running = true;
    float frametime = 0.0f;

    Renderer *renderer = NEW(Renderer, NEW(GLBackend));
    ResourceManager *resMgr = renderer->getResourceManager();
    Scene *scene = NEW(Scene, renderer);
    Scene *quadScene = NEW(Scene, renderer);

    RenderTarget *target = NEW(RenderTarget, renderer);

    RenderTarget *textureTarget = NEW(RenderTarget, renderer);
    Framebuffer *framebuffer = textureTarget->addFramebuffer();
    framebuffer->addColor(resMgr->createTexture(Texture::Texture2D), Texture::RGBAU8_Norm_InternalFormat);
    framebuffer->addColor(resMgr->createTexture(Texture::Texture2D), Texture::Red32F_InternalFormat);
    framebuffer->addColor(resMgr->createTexture(Texture::Texture2D), Texture::RGBU8_Norm_InternalFormat);
    framebuffer->addColor(resMgr->createTexture(Texture::Texture2D), Texture::RGBAU8_Norm_InternalFormat);
    framebuffer->addColor(resMgr->createTexture(Texture::Texture2D), Texture::RGBU8_Norm_InternalFormat);
    framebuffer->addColor(resMgr->createTexture(Texture::Texture2D), Texture::RGBU8_Norm_InternalFormat);
    framebuffer->finish();

    ResPtr<Model> model = resMgr->load("res/models/dragon.json").cast<Model>();


    ResPtr<Mesh> quadMesh = resMgr->createMesh(resMgr->load("res/shaders/quad vertex.json").cast<Shader>(), Mesh::Triangles, 6);
    VertexBuffer *quadVB = quadMesh->addPositions(renderer, MeshComponent(2, MeshComponent::Float32))->getVertexBuffer();

    quadVB->alloc(sizeof(glm::vec2)*6);
    glm::vec2 *quadPositions = (glm::vec2 *)quadVB->map(false, true);
    quadPositions[0] = glm::vec2(-1.0f, -1.0f);
    quadPositions[1] = glm::vec2( 1.0f, -1.0f);
    quadPositions[2] = glm::vec2(-1.0f,  1.0f);
    quadPositions[3] = glm::vec2(-1.0f,  1.0f);
    quadPositions[4] = glm::vec2( 1.0f, -1.0f);
    quadPositions[5] = glm::vec2( 1.0f,  1.0f);
    quadVB->unmap();


    ResPtr<Material> quadMaterial = resMgr->createMaterial(
    resMgr->load("res/shaders/quad fragment.json").cast<Shader>());
    quadMaterial->mUniforms["colorTexture"] = framebuffer->getColorTexture(0);
    quadMaterial->mUniforms["depthTexture"] = framebuffer->getColorTexture(1);
    quadMaterial->mUniforms["normalTexture"] = framebuffer->getColorTexture(2);
    quadMaterial->mUniforms["materialTexture"] = framebuffer->getColorTexture(3);
    quadMaterial->mUniforms["ambientTexture"] = framebuffer->getColorTexture(4);
    quadMaterial->mUniforms["specularTexture"] = framebuffer->getColorTexture(5);
    quadMaterial->mUniforms["lightDirection"] = glm::vec3(0.0f);


    ResPtr<Model> quadModel = resMgr->createModel();
    quadModel->mLODs.push_back(LOD(quadMesh, quadMaterial, 0.0f));
    quadModel->sortLODs();

    quadScene->createEntity(quadModel);


    scene->mSkyboxTexture = resMgr->load("res/textures/enviroment texture.json").cast<Texture>();


    Entity *entity = scene->createEntity(model);

    float t = 0.0f;

    bool fullscreen = false;

    glm::vec3 cameraPosition(0.0f, 0.0f, 5.0f);
    glm::vec2 cameraAngle(3.1415f, 0.0f);
    float cameraSpeed = 3.0f;
    float cameraRotateSpeed = 1.0f;

    while (running)
    {
        Uint64 start = SDL_GetPerformanceCounter();

        SDL_Event event;

        while (SDL_PollEvent(&event))
        {
            switch (event.type)
            {
                case SDL_QUIT:
//.........这里部分代码省略.........
开发者ID:pendingchaos,项目名称:WIP8,代码行数:101,代码来源:main.cpp


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