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


C++ TileLayer::add方法代码示例

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


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

示例1: multiple_texture_sample

int multiple_texture_sample(void)
{
    //GLuint shaderProgID;
    Window engineWindow("Wolfie", 600, 800);
    std::vector<Sprite> spriteVec;
    
    if (engineWindow.init() == -1)
    {
        std::cout<<"Engine initialization error"<<std::endl;
        return -1;
    }
    
    //creating shader program
    Shader shObj(FRAGMENT_SHADER_SOURCE, VERTEX_SHADER_SOURCE);
    
    if(!shObj.checkValidShaderProg())
    {
        std::cout<<"Shader compilation issues"<<std::endl;
        return -1;
    }
    
    
    Texture2D* texture1 = new Texture2D(WALL_IMG);
    Texture2D* texture2 = new Texture2D(TEXTURE_IMG);
    //texture.generate();
    
    // Transformation Calculations
    //model matrix
    glm::mat4 modelMat(1.0f);
    
    // View matrix
    glm::mat4 viewMat = glm::lookAt(
                                    glm::vec3(50,0,5), // Camera in World Space
                                    glm::vec3(50,50,0), // and looks at the origin
                                    glm::vec3(0,1,0)  // Head is up (set to 0,-1,0 to look upside-down)
                                    );
    
    //Projection Matrix
    glm::mat4 projMat = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 200.0f);
    
    // final MVP transform
    glm::mat4 mvpMat = projMat * viewMat * modelMat;
    
    //Randomization logic for sprite colors using <chrono> and <random>
    std::chrono::system_clock::time_point sysTimePoint = std::chrono::system_clock::now();
    double seed = sysTimePoint.time_since_epoch().count();
    std::mt19937 gen(seed);
    
    std::uniform_real_distribution<double> dist;
    
    
    TileLayer *spriteLayer = new TileLayer(&shObj, new BatchRenderer(), mvpMat);
    
    //super group's transformation matrix
    modelMat = glm::mat4(1.0f);
    Group* groupSuper = new Group(modelMat);
    
    
    for(int i=0 ;i < 100; i+=2)
    {
        for(int j=0; j< 100; j+=2)
        {
            groupSuper->add(new Sprite(glm::vec3(i,j,0),
                                       glm::vec2(5,5),
                                       glm::vec4(1.0f, 0.0f, 1.0f, 1.0f),
                                       texture1)
                            );
            
            groupSuper->add(new Sprite(glm::vec3(i+1,j+1,0),
                                       glm::vec2(2,2),
                                       glm::vec4(1.0f, 0.0f, 1.0f, 1.0f),
                                       texture2)
                            );
            
        }
    }
    
    // add the super group to the layer
    spriteLayer->add(groupSuper);
    
#if FPS_VIEWER
    Timer timer;
    unsigned short frames = 0;
    timer.start();
    float time = 0;
#endif
    
    // The actual Game Loop
    while(!engineWindow.isClosed())
    {
        glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
        engineWindow.clear();
        
        //body of the draw
        spriteLayer->render();
        
        engineWindow.update();
        
        if (engineWindow.isKeyPressed(GLFW_KEY_W))
            std::cout<<" W is pressed!!"<<std::endl;
//.........这里部分代码省略.........
开发者ID:tomkaith13,项目名称:Wolfie,代码行数:101,代码来源:multi_texture_sample.cpp


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