Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::RenderTexture positioning?  (Read 1611 times)

0 Members and 1 Guest are viewing this topic.

LucasShadow

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
sf::RenderTexture positioning?
« on: May 24, 2012, 05:31:12 am »
I am creating a simple tile generator using sf::RenderTexture and have run into an odd problem.  The below code (minimal example) should produce a nice small patch of grass, but nothing appears but a blank screen.  Am I using the rendertexture incorrectly or is this a bug?

#include <SFML/Graphics.hpp>
#include <iostream>
#include <sstream>
#include <fstream>
#include <math.h>

using namespace std;

 int main()
 {
     sf::RenderWindow App(sf::VideoMode(800, 600), "Upgrading to SFML 2.0 Testing Environment");

     sf::Texture grassimg;
     if(!grassimg.loadFromFile("img\\Terrain\\new_grass_tile.png")) {cout << "Error" << endl;};
     sf::Sprite Tile(grassimg);
     Tile.setPosition(0,0);

     float GridX = 3, GridY = 5, CountX = 0, CountY = 0, Iso = 0;
     float TileX = grassimg.getSize().x;
     float TileY = grassimg.getSize().y;
     sf::RenderTexture bg;
     bg.create(800, 800);

     for(int i = 1; i < GridX * GridY + 1; i++)
     {
         Tile.setPosition((TileX * CountX) + (TileX/2 * Iso), (TileY/2) * CountY);
         bg.draw(Tile);

         CountX++;
         if(CountX > GridX + 1 && Iso == 0) CountX = 0, CountY++, Iso = 1;
         if(CountX > GridX + 1 && Iso == 1) CountX = 0, CountY++, Iso = 0;
     }

     sf::Sprite grassobj;
     grassobj.setTexture(bg.getTexture());
     grassobj.setPosition(0,0);

     while (App.isOpen())
     {
         sf::Event Event;
         while (App.pollEvent(Event))
         {
             if (Event.type == sf::Event::Closed)
                 App.close();
         }

         App.clear();

         App.draw(grassobj);

         App.display();
     }
     return EXIT_SUCCESS;
 }
 

LucasShadow

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: sf::RenderTexture positioning?
« Reply #1 on: May 24, 2012, 07:07:37 am »
Nevermind, I figured it out. Feel free to delete this topic since it appears I can not.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: sf::RenderTexture positioning?
« Reply #2 on: May 24, 2012, 12:44:56 pm »
I don't think Laurent deletes threads, thus if anyone ever finds this thread the solution would be to call display() on the render texture. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything