I started playing around with Oxygine and Ogmo last night when I stumbled upon this GitHub that read in the Ogmo level.

I ended up fixing the doRender method as it did not work (could just be due to it being an old version of Ogmo or something):

void OgmoLevel::doRender(const RenderState& rs) {
    auto tileLayers = this->tileLayers;
    Sprite sprite;
    for (size_t layerIndex = 0; layerIndex < tileLayers.size(); ++layerIndex) {
        auto tileLayer = &tileLayers.at(layerIndex);

        auto resAnim = project->resource->getResAnim(tileLayer->tileset->name);


        int gridXSize = tileLayer->definition->gridWidth;
        int gridYSize = tileLayer->definition->gridHeight;

        size_t columns = roomWidth / gridXSize;
        size_t rows = roomHeight / gridYSize;

        auto tiles = &tileLayer->tiles;
        size_t tilesSize = tiles->size();

        size_t i = 0;
        float yy = 0;
        for (size_t y = 0; y < rows; ++y) {
            float xx = 0;
            for (size_t x = 0; x < columns; ++x) {
                int tileID = tiles->at(i);
                if (tileID != OGMO_BLANK_TILE) 
                    int tWidth = tileLayer->tileset->tileWidth;

                    int actualRow = (tileID * tWidth / tWidth) / tWidth;
                    int actualColumn = (tileID - (actualRow * tWidth));

                    sprite.setColumnRow(actualColumn, actualRow);
                    sprite.setPosition(xx, yy);

                xx += tileLayer->definition->gridWidth;
            yy += tileLayer->definition->gridHeight;

The issue I see with this, is that the same exact rendering is happening every single frame. Normally for the tile maps, there are checks to determine whether or not the tile is on the screen. Now that is fine and all, but this time around, I know it is fully static 99% of the time and I want to render it to a texture and just continue to render that.

I've looked at the MemoryTexture and ImageData classes, but there wasn't really anything online I could find to tell me how to properly use them. Does anyone have any idea how I can achieve caching this?

(not enough rep to create proper tags)


Thanks to the helpful admin over at the Oxygine forum, I was able to figure out how to programmaticly create textures. Below is sample code on how to do it:

oxygine::file::read(fileName, fb, oxygine::error_policy::ep_show_error);

oxygine::Image tileSheetImage;
Rect r(0, 0, 16, 16);

oxygine::Image myMap;
myMap.init(1024, 1024, tileSheetImage.getFormat());

auto tile = tileSheetImage.lock().getRect(r);
spNativeTexture texture = IVideoDriver::instance->createTexture();
operations::blit(tile, myMap.lock(0,0).getRect(r));

AnimationFrame frame(texture);
sprite.setPosition(0, 0);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.