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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - lyvinhloi.cntt

Pages: [1]
1
Thanks for the answer  :-\ ..

2
Oh .. uhm ...
I want to change the coordinates system of window from the top-left to the bottom-left to easy to draw my sprites.

3
Graphics / Re: Texture loaded , drawn , but not shown on the screen
« 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 :)

4
Graphics / Re: Texture loaded , drawn , but not shown on the screen
« 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 >.<

5
Graphics / Re: Texture loaded , drawn , but not shown on the screen
« on: May 29, 2014, 10:56:30 pm »
^: Okay, I missed that, but it still black screen  :-\

6
Graphics / Re: Texture loaded , drawn , but not shown on the screen
« 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 ?

7
Graphics / Re: How to check whether rectangle intersect with Line ?
« on: May 19, 2014, 05:07:44 pm »
Haha ... I'm idiot >.< Just thinking in another side ^^
Ok thanks guys, problem solved...

8
Graphics / How to check whether rectangle intersect with Line ?
« on: May 18, 2014, 12:17:51 pm »
Ok I have this code:
#include <iostream>
#include <SFML/Graphics.hpp>

int main(void)
{
//    sf::RenderWindow window(sf::VideoMode(800,600),"Testing");
//    window.setFramerateLimit(60);

    sf::VertexArray line(sf::Lines,2);
    line[0].position = sf::Vector2f(200,300);
    line[1].position = sf::Vector2f(600,300);

    sf::Rect<float> rect2(line.getBounds());
    sf::Rect<float> rect(200,100,300,200);

    sf::VertexArray drawrect(sf::Quads,4);
    drawrect[0].position = sf::Vector2f(100,200);
    drawrect[1].position = sf::Vector2f(400,200);
    drawrect[2].position = sf::Vector2f(400,400);
    drawrect[3].position = sf::Vector2f(100,400);

//    while (window.isOpen())
//    {
//        window.clear(sf::Color::Black);
//        window.draw(line);
//        window.draw(drawrect);
//        window.display();
//    }
    std::cout << rect.intersects(rect2);
}
 
You can uncomment to see what I have createn.
When I run this code, it always show 0 which mean there aren't intersection. But I think it should be 1, why not ?
If I were wrong, how to correct it ? I mean .. [ the title ] :D

9
Graphics / Re: Problem about sf::Text and sf::Sprite/Circle...
« on: May 15, 2014, 04:48:11 pm »
Sorry about my code because I don't know how to setting up  ;D
One more about sf::CircleShape is the top and left attributes of circle.getGlobalBounds().(top/left):
When I set my circle at position (0,0), those attributes aren't equal zero. If so, how to know the circle do touch to the left/right/top/bottom edge of console window or not?
p/s: Below is the screen captured show that top and left value when I run

10
Graphics / Problem about sf::Text and sf::Sprite/Circle...
« on: May 15, 2014, 04:22:16 pm »
I'm new here, I've learned SFML for 3 days, and got a problem @@.
I really don't know how to set position of sf::Text to the center of sf::CircleShape, have a look at the code below:
#include <SFML/Graphics.hpp>
#include <iostream>

int main(void)
{
    sf::RenderWindow window(sf::VideoMode(800,600),"Object");
    window.setFramerateLimit(60);

    sf::Font font;
    if (!font.loadFromFile("arial.ttf")) std::cout << "Couldn't load font file!" << std::endl;

    sf::Text text;
    text.setFont(font);
    text.setPosition(10,10);
    text.setColor(sf::Color::Red);
    text.setString("A");
    text.setCharacterSize(100);

    sf::CircleShape circle;
    circle.setFillColor(sf::Color::White);
    circle.setPosition(10,10);
    circle.setRadius(100);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed || sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) window.close();
        }
        window.clear(sf::Color::Black);
        window.draw(circle);
        window.draw(text);
        window.display();
    }
}
 

Well, the text has only 1 char and has big size ( easy to see ), I've set its position to (10,10) but it doesn't. Seem like (10,about 20 or 30). How to solve this problem ?

Pages: [1]
anything