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

Author Topic: Texture loaded , drawn , but not shown on the screen  (Read 6445 times)

0 Members and 4 Guests are viewing this topic.

traxys

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Re: Texture loaded , drawn , but not shown on the screen
« Reply #15 on: May 28, 2014, 08:36:48 pm »
Just needed a re-build for it

lyvinhloi.cntt

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
Re: Texture loaded , drawn , but not shown on the screen
« Reply #16 on: May 29, 2014, 10:43:58 pm »
Hi there, I have almost the same problem with @traxys, so I don't create new topic, hope anybody help me to solve it :)
This is my code:
#include <SFML/Graphics.hpp>
#include <sstream>
#include <iostream>

#define WND_WIDTH 400 // Window Width
#define WND_HEIGHT 400 // Window Height
#define S_WIDTH 100  // Square Width
#define S_HEIGHT 100 // Square Height
#define SPEED 10

int main(void)
{
    sf::RenderTexture rtexture;
    rtexture.create(S_WIDTH,S_HEIGHT);
    rtexture.setSmooth(true);

    sf::Font font;
    if(!font.loadFromFile("arial.ttf")) std::cout << "Error ! Can't load font file [arial.ttf]";

    sf::Text text;
    text.setFont(font);
    text.setColor(sf::Color::Red);
    text.setString("1234");
    text.setCharacterSize(30);
    text.setOrigin((text.getLocalBounds().width+text.getLocalBounds().left)/2,(text.getLocalBounds().height+text.getLocalBounds().top)/2);
    text.setPosition(S_WIDTH/2.0,S_HEIGHT/2.0);

    sf::RectangleShape square;
    square.setOrigin(S_WIDTH/2,S_HEIGHT/2);
    square.setOutlineThickness(2);
    square.setPosition(S_WIDTH/2,S_HEIGHT/2);
    square.setSize(sf::Vector2f(S_WIDTH,S_HEIGHT));
    square.setFillColor(sf::Color::Black);

    sf::RenderWindow window(sf::VideoMode(WND_WIDTH,WND_HEIGHT),"Testing");
    window.setFramerateLimit(60);
// this is the problem
    sf::RectangleShape rect;
    rect.setTexture(&rtexture.getTexture(),true);

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

        window.clear(sf::Color::Black);
        //window.draw(rect);
        window.draw(square);
        window.draw(text);
        window.display();
    }
}
 
Humm... I've created my texture had square and text in the middle of it by using rendertexture. But I can't getTexture() to use even though I can draw on main window ( like the code above ). When comment
window.draw(square);
window.draw(text);
 
and uncomment window.draw(rect), nothing on the screen, why ?

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Texture loaded , drawn , but not shown on the screen
« Reply #17 on: May 29, 2014, 10:47:42 pm »
You don't appear to have drawn anything to the rendertexture.

lyvinhloi.cntt

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
Re: Texture loaded , drawn , but not shown on the screen
« Reply #18 on: May 29, 2014, 10:56:30 pm »
^: Okay, I missed that, but it still black screen  :-\

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Texture loaded , drawn , but not shown on the screen
« Reply #19 on: May 29, 2014, 10:59:19 pm »
Can you show a complete example where you actually draw something to your rendertexture? (preferably without the text and other drawables since they aren't relevant)

lyvinhloi.cntt

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
Re: Texture loaded , drawn , but not shown on the screen
« Reply #20 on: May 29, 2014, 11:08:31 pm »
I don't know  ;D
I just want to add my text, my square to rendertexture to draw once. ( example if there weren't error, I could draw 1 rect that had both text in the middle and border around :) )

In fact, it is black screen, I don't know how to solve ... I think it would be the same, I captured my screen, it would be shown like the top but it actually shown like the bottom :(

EDIT: Sr about my english >.<
« Last Edit: May 29, 2014, 11:10:24 pm by lyvinhloi.cntt »

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Texture loaded , drawn , but not shown on the screen
« Reply #21 on: May 29, 2014, 11:34:42 pm »
Screenshots without the code that produced them doesn't tell us anything.

It sounds like you want to draw the square and the text to the rendertexture once at the beginning, then draw the rendertexture's texture to the window every frame.  Try actually doing that.

lyvinhloi.cntt

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
Re: Texture loaded , drawn , but not shown on the screen
« Reply #22 on: May 30, 2014, 07:03:18 pm »
Tks, after clearing code and test each line, I saw that the text had been draw, but square.setFillColor(...) -> so, it will draw over it and swap those lines, it work perfectly ^^ ... thanks for reply :)