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.


Topics - metulburr

Pages: [1]
1
General / mapPixelToCoords returns
« on: December 02, 2013, 06:08:34 pm »
I dont understand why does mapPixelToCoords take in a an integer and returns a float, whereas mapCoordstoPixel takes in a float and returns an interger?
Quote
Vector2f        mapPixelToCoords (const Vector2i &point) const
        Convert a point from target coordinates to world coordinates, using the current view.
 
Vector2f        mapPixelToCoords (const Vector2i &point, const View &view) const
        Convert a point from target coordinates to world coordinates.
 
Vector2i        mapCoordsToPixel (const Vector2f &point) const
        Convert a point from world coordinates to target coordinates, using the current view.
 
Vector2i        mapCoordsToPixel (const Vector2f &point, const View &view) const
        Convert a point from world coordinates to target coordinates.

The part i am having a problem with is:
sf::Vector2f mouse = window.mapPixelToCoords(sf::Vector2i(event.mouseMove.x, event.mouseMove.y));
pixel to coords takes in an int,and returns a float...However floats are not needed. So i would rather return an integer for mouse, but yet cannot because pixels to coords must return of type Vector2f. That or have pixel to coords take in mouse as a float, but that it not possible as well. So how can i get nice flow of only integers or only floats without switching between the two?

2
General / different results on several compiles with same code
« on: November 27, 2013, 02:15:18 pm »
My obvious goal is to get a button class in which changes color on mouse hovering over the button. I have 2 problems. 1) if i recompile time after time again, sometimes it prints correctly when the mouse is inside the rectangel, sometimes it prints when the mouse is bleow the rectangle. It is different each time compiling. 2) At the time it does display correctly when the mouse is inside the rectangle, i expected it to change color bassed on is_hovering bool value. However the color never changes, yet the display messages do?

I tried minimizing it, but i am not sure how to minimize it more without losing a working example.

#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>


class Button{
    public:
        sf::Vector2f position;
        sf::RectangleShape rect;
        bool is_hovering;
        int width, height;
       
        Button(){
            rect.setFillColor(sf::Color(200,200,200));
        }
           
        void create(float w, float h, float x, float y){
            width = w;
            height = h;
            position = {x,y};
            rect.setSize(sf::Vector2f(w,h));
            rect.setPosition(position);
        }
       

       
        void update(sf::Vector2i mouse){
            if (mouse.x > position.x &&
            mouse.x < (position.x + width) &&
            mouse.y > position.y &&
            mouse.y < position.y + height){
                std::cout << "inside rect" << std::endl;
                is_hovering = true;
            }
            else
                std::cout << std::endl;
                is_hovering = false;
           
            if (is_hovering)
                rect.setFillColor(sf::Color(50,50,50));
            else
                rect.setFillColor(sf::Color(200,200,200));
        }
};

class Control{
    public:
        sf::RenderWindow window;
        sf::Clock clock;
        sf::Time frame_time = sf::seconds(1.f/60.f);
        sf::Time time = sf::Time::Zero, update_time = sf::Time::Zero;
        sf::Vector2i mouse;
        Button button;
       
        Control(){
            window.create(sf::VideoMode(600,400), "Title");
            button.create(100,20, 100,100);
            //window.setKeyRepeatEnabled(false);
        }
       
        void update(){
            mouse = sf::Mouse::getPosition(window);
           
            time = clock.restart();
            update_time += time;

            while(update_time > frame_time){
                update_time -= frame_time;
                button.update(mouse);
            }
            render();
        }
       
        void render(){
            window.clear(sf::Color::Black);
            window.draw(button.rect);
            window.display();
        }
       
        void event_handler(sf::Event event){
            while(window.pollEvent(event)){
                if (event.type == sf::Event::Closed)
                    window.close();
            }
        }
       
        void run(){
            while (window.isOpen()){
                sf::Event event;
                event_handler(event);
                update();
            }
        }
};

int main(){
    Control app;
    app.run();
}
 

3
General / window creation lag before it centers
« on: November 25, 2013, 04:48:04 am »
I figured this code to center the window on a single monitor. It does work in general. However it appears to lag for a second or two off to the top-left corner before the window moves/jumps to the center. I would consider this normal behavior, for the exception that Python/Pygame's SDL center window does not do this. It immediately creates it's window without lag in the center.

So i am assuming it is me doing something wrong in coding it. I just do not know what?

The code stripped down to min:
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>

class Control{
    public:
        sf::RenderWindow window;
        unsigned int monitor[2] = {sf::VideoMode::getDesktopMode().width, sf::VideoMode::getDesktopMode().height},
            screen[2] = {800,600};
        std::string title = "SFML test";
       
        Control(){
            window.create(sf::VideoMode(screen[0], screen[1]), title);
            center_window();
        }
       
        void center_window(){
            window.setPosition(
                sf::Vector2i(
                    (monitor[0] / 2) - (screen[0] / 2),
                    (monitor[1] / 2) - (screen[1] / 2)
                )
            );
        }
       
        void events(sf::Event e){
            while(window.pollEvent(e)){
                if (e.type == sf::Event::Closed){
                    window.close();
                }
            }
        }
       
        void render(){
            window.clear();
            window.display();
        }
       
        void run(){
            while (window.isOpen()){
                sf::Event event;
                events(event);
                //update();
                render();
            }
        }
};

int main(){
    Control app;
    app.run();
}
 

EDIT:
actually it is not like 2 seconds but more like a half a second. It is just enough to notice the difference between SDL centering.

4
General / determine multiple monitors or not
« on: November 25, 2013, 04:22:23 am »
I know SFML does not yet support multiple monitors, more than one fullscreen, etc. I was however, looking for a method to determine whether there was a second montior hooked up or not. I have no idea how to test in windows, but the only thing i can think of in linux is xrandr.
metulburr@laptop:~$ xrandr
Screen 0: minimum 8 x 8, current 3200 x 1080, maximum 8192 x 8192
VGA-0 disconnected (normal left inverted right x axis y axis)
TV-0 disconnected (normal left inverted right x axis y axis)
LVDS-0 connected 1280x800+0+0 (normal left inverted right x axis y axis) 331mm x 207mm
   1280x800       60.0*+
HDMI-0 connected 1920x1080+1280+0 (normal left inverted right x axis y axis) 886mm x 498mm
   1920x1080      60.0*+   59.9     24.0     30.0     30.0  
   1440x480       30.0  
   1360x768       60.0  
   1360x765       60.0  
   1280x1024      60.0  
   1280x720       60.0     59.9  
   1024x768       60.0  
   800x600        60.3  
   720x480        59.9     30.0  
   640x480        59.9     59.9  
metulburr@laptop:~$
Of course i am not exactly sure on how to parse the output in c++. Is there at least a method in SFML to test whether there is a lone monitor or not?

5
General / missing sfml-graphics-2.dll
« on: November 15, 2013, 04:08:25 pm »
I get the error:
missing sfml-graphics-2.dll
when i try to compile SFML under windows. I walked through the tutorial.

Path to SFML
C:\SFML-2.1\

to confirm... in compiler settings for code blocks i changed:
compiler
C:\SFML-2.1\include

linker
C:\SFML-2.1\lib

settings->#defines
SFML_STATIC

linker settings:
sfml-graphics
sfml-window
sfml-system
sfml-network

enabled flag for c++11



windows 8
code blocks mingw
SFML 2.1


I think that was it. I don't really see a problem?

6
General / random speed in movement
« on: November 13, 2013, 06:13:21 am »
When moving the object, the obj will jump from slow to fast, vice versa if held down long enough. I had it at what seemed a steady speed, but that was before i read that section in the SFML book. In which that said to add a second while loop in for logic updates as opposed to rendering. The theory sounds good, but i cannot figure out why i cannot get it to work. This process is new to me as in Pygame i just used clock.tick(60), but i am assuming that it used an internal sleep method for 60 FPS.

well anyway, this is the code. It is not exactly like the book, as i was trying to implement into my style. The problem lies in Control::update()
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>

class Rect{
    public:
        int speed = 100;
        sf::Vector2f position;
        sf::RectangleShape rect;
        bool moving_up = false,
            moving_down = false,
            moving_right = false,
            moving_left = false;
           
        Rect(){
            position = {100,100};
            rect.setSize(sf::Vector2f(100,100));
            rect.setPosition(position);
            rect.setFillColor(sf::Color::Red);
        }
       
        void update(sf::Time delta){
           
            sf::Vector2f movement(0,0);
            if (moving_up)
                movement.y -= speed;
            if (moving_down)
                movement.y += speed;
            if (moving_left)
                movement.x -= speed;
            if (moving_right)
                movement.x += speed;
            move(movement * delta.asSeconds());
            rect.setPosition(position);
        }
       
        void move(sf::Vector2f movement){
            position += movement;
        }
};

class Control{
    public:
        sf::RenderWindow window;
        sf::Clock clock;
        sf::Time frame_time = sf::seconds(1.f/60.f);
        sf::Time time = sf::Time::Zero, update_time = sf::Time::Zero;
        Rect obj;
       
        Control(){
            window.create(sf::VideoMode(600,400), "Title");
            //window.setKeyRepeatEnabled(false);
        }
       
        void update(sf::Event event){
            time = clock.restart();
            update_time += time;

            while(update_time > frame_time){
                update_time -= frame_time;
                obj.update(time);
            }
            render();
        }
       
        void render(){
            window.clear(sf::Color::Black);
            window.draw(obj.rect);
            window.display();
        }
       
        void input_handler(sf::Keyboard::Key key, bool is_pressed){
            if (key == sf::Keyboard::W)
                obj.moving_up = is_pressed;
            else if (key == sf::Keyboard::S)
                obj.moving_down = is_pressed;
            else if (key == sf::Keyboard::D)
                obj.moving_right = is_pressed;
            else if (key == sf::Keyboard::A)
                obj.moving_left = is_pressed;
        }
       
        void event_handler(sf::Event event){
            while(window.pollEvent(event)){
                if (event.type == sf::Event::Closed)
                    window.close();
                else if (event.type == sf::Event::KeyPressed)
                    input_handler(event.key.code, true);
                else if (event.type == sf::Event::KeyReleased)
                    input_handler(event.key.code, false);
            }
        }
       
        void run(){
            while (window.isOpen()){
                sf::Event event;
                event_handler(event);
                update(event);
            }
        }
};

int main(){
    Control app;
    app.run();
}

 

7
General / checking for collision against an object
« on: November 12, 2013, 10:48:48 pm »
I come from python/pygame where the methods are made for you. However looking through sfml, i dont see such methods as in pygame. such as rect.collidepoint() for mouse or rect.colliderect() for collision test against another rect. Do you have to make these yourself in sfml?

If so i am not quite sure on how to make these functions.
I set up the base classes, i am just not sure on how to check if the mouse is inside the rect or not?

#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>

class Rect{
    public:
        sf::RectangleShape rect;
       
        Rect(){
            rect.setSize(sf::Vector2f(100,100));
            rect.setPosition(sf::Vector2f(10,10));
            rect.setFillColor(sf::Color::Red);
        }
};

class Control{
    public:
        sf::RenderWindow window;
        Rect obj;
       
        Control(){
            window.create(sf::VideoMode(600,400), "Title");
            window.setKeyRepeatEnabled(false);
        }
       
        void update(sf::Event event){
            window.clear(sf::Color::Black);
            window.draw(obj.rect);
            window.display();
        }
       
        void event_handler(sf::Event event){
            while(window.pollEvent(event)){
                if (event.type == sf::Event::Closed){
                    window.close();
                }
            }
        }
       
        void run(){
            while (window.isOpen()){
                sf::Event event;
                event_handler(event);
                update(event);
            }
        }
};

int main(){
    Control app;
    app.run();
}

 

8
Network / downloading image for sfml resource use
« on: November 12, 2013, 05:19:17 am »
I havent dabbed at all yet into network of sfml yet. My overall goal was to make a function in which could download an image for me so that i could use it as a sprite. I skimmed the network docs but i dont see such related exactly to it. I pieced together code from what i found on these forums. However the object http was not mentioned in the thread as to what is was. So i guessed as if it was sf::Http. However when doing that though i get errors. I am not sure what exactly is wrong? What am i missing?

#include <SFML/Network.hpp>
#include <fstream>

int main(){
    std::string url = "http://s1297.photobucket.com/user/metulburr/media/walker_zpsbd2d34be.png.html";
    sf::Http http;
    sf::Http::Request req(url);
    sf::Http::Response image_res = http.sendRequest(req);

    std::string body = image_res.getBody();
    std::ofstream file;
    file.open("tux.png", std::ios::binary);
    file.write(body.c_str(), body.size());
    file.close();
}

the thread i am talking about is:
http://en.sfml-dev.org/forums/index.php?topic=8160.0

9
General / window has no member draw error
« on: November 11, 2013, 08:08:51 am »
I was going through a video tutorial, and the person first shows drawing an image to the screen. However the put window.draw(image_obj) to draw to their screen...when i do the same i get an error for sf::Window has no member draw? My intentions was that is what is suppose to draw the image to screen as shown on the tutorial. The video is using sfml 2.0 and i am using 2.1.

#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>

class Control{
    public:
        sf::Window window;
        sf::Time time;
        sf::Clock clock;
        sf::Sprite player;
        sf::Texture texture;
       
        Control(){
            window.create(sf::VideoMode(600,400), "Title");
            window.setKeyRepeatEnabled(false);
            if(!(texture.loadFromFile("/home/metulburr/Pictures/explode.jpeg")))
                std::cout << "could not load image" << std::endl;
            player.setTexture(texture);
        }
       
        void run(){
            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(player);
                window.display();
                time = clock.restart();
            }
        }
};

int main(){
    Control app;
    app.run();
}

 

and i get the error:
est.cpp: In member function ‘void Control::run()’:
test.cpp:29:24: error: ‘class sf::Window’ has no member named ‘clear’
                 window.clear(sf::Color::Black);
                        ^
test.cpp:30:24: error: ‘class sf::Window’ has no member named ‘draw’
                 window.draw(player);
                        ^


 



10
General / odd error when compiling sfml
« on: November 08, 2013, 04:06:47 am »
history:
It was not 3 hours ago i was going through a tutorial on sfml and compiling it fine, then got an error saying directory was not there. Throughout the process, i had trouble with g++, so i purged g++ from my ubuntu and reinstalled.

I also reinstalled some pre-reqs, but i still get the same error:
sudo apt-get install libpthread-stubs0-dev libgl1-mesa-dev  libx11-dev libxrandr-dev libfreetype6-dev libglew1.5-dev libjpeg8-dev libsndfile1-dev libopenal-dev cmake
 

after reinstalling i now get this error:

libGL error: failed to load driver: swrast
libGL error: Try again with LIBGL_DEBUG=verbose for more details.
 

after putting in that argument i get this error:
g++: error: LIBGL_DEBUG=verbose: No such file or directory

I am not really sure where to go after this. I have spent the better part of tonight messing with the error i had with g++, and now that i have that working well, i seem to be stuck yet again at sfml. I am not really sure what intially sparked the problem in the first place as i was just compiling sfml between tutorials at the time, not installing, not hcanging config files, or not updating or anything. So its odd that it just seemed to happen out of thin air.


g++  -std=c++11  -Wall -o "%e" "%f" -lsfml-audio -lsfml-graphics -lsfml-window -lsfml-system &&"./%e"
sfml 2.1 on ubuntu 13.04
gcc version 4.7.3

EDIT:
i initially had g++ 4.8 earleir today, and that was working fine. But now i keep getting problems when i switch to it, thus me now having 4.7.3. I am not sure if the version differences are something or not?

11
General / movement without keyboard input
« on: October 08, 2013, 07:25:07 pm »
in this code i tried to make a basic circle move via wasd key combo, but as soon as i start it up the circle starts moving to the left without keyboard input?

#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

class Control{
    public:
        sf::RenderWindow window;
        sf::CircleShape circle;
        bool move_up, move_down, move_left, move_right;
        //int speed = 1;
       
        Control()
        : window(sf::VideoMode(600, 480), "test")
        , circle(){
            circle.setRadius(40.f);
            circle.setPosition(100.f, 100.f);
            circle.setFillColor(sf::Color::Cyan);
        }
        void run(){
            while (window.isOpen()){
                process_events();
                update();
                render();
            }
        }
        void process_events(){
            sf::Event event;
            while (window.pollEvent(event)){
                if (event.type == sf::Event::Closed){
                    window.close();
                }
                else if (event.type == sf::Event::KeyPressed){
                    handler(event.key.code, true);
                }
                else if (event.type == sf::Event::KeyReleased){
                    handler(event.key.code, false);
                }
               
            }
        }
        void handler(sf::Keyboard::Key key, bool is_pressed){
            if (key == sf::Keyboard::W)
                move_up = is_pressed;
            else if (key == sf::Keyboard::S)
                move_down = is_pressed;
            else if (key == sf::Keyboard::A)
                move_left = is_pressed;
            else if (key == sf::Keyboard::D)
                move_right = is_pressed;
        }
       
        void update(){
            sf::Vector2f movement(0.f, 0.f);
            if (move_up)
                movement.y -= 1.f;
            if (move_down)
                movement.y += 1.f;
            if (move_left)
                movement.x -= 1.f;
            if (move_right)
                movement.x += 1.f;
               
            circle.move(movement);
        }
       
        void render(){
            window.clear();
            window.draw(circle);
            window.display();
        }
   
};

int main(){
    Control app;
    app.run();
}
 

12
General / no windows pops up
« on: October 08, 2013, 05:33:16 am »
I am not sure why a SFML windows does not appear when compiled and executed. I am on ubuntu, downloaded sfml from ubuntu repos. I am assuming ubuntu has the oldest version 1.6, but i am not sure on how to tell. I dont get any error messages when compiling, but no window appears.

I am compiling it via:
g++ -Wall -o "%e" "%f" -lsfml-audio -lsfml-graphics -lsfml-window -lsfml-system
under geany's IDE

#include <SFML/Graphics.hpp>

int main()
{
    // Create the main rendering window
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
   
    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

        // Clear the screen (fill it with black color)
        App.Clear();

        // Display window contents on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}
 

13
General / better tutorial for SFML?
« on: August 28, 2011, 11:51:32 pm »
i am ok at running the console apps and can figure out why things are there and what they are for, but using SFML i cant seem to follow what is going on(therefore unable to use it without copying and pasting peoples responses for my program)

1) At what point should i depart from console programs (becuz they are kind of boring), i can make small (very small) text games, somewhat know how to use classes, loops, etc.

2) SFML seems to have trouble explaining things well when going from console to SFML.

3) i read through the tutorials on this site, and they are not very (console to SFML) friendly. I have to keep posting questions on Cplusplus forums due to most answers on the beginners forum are regarding console apps.

4) is there a tutorial for beginners starting SFML directly from console learning??? if so please reply

5) what exactly can u use SFML for?  2D games, GUI programs(i guess meaning like a windows app) ( like menu selection for the game?). if you wanted to make 3D games, why could you not use SFML and just use their libraries for menus and make your own classes for the 3D?

Thanks in Advance,
metulburr

14
General / installing question
« on: August 24, 2011, 09:05:36 am »
i am not really great at working with the terminal in linux, but anyways i downloaded SFML 1.6 for linux
http://www.sfml-dev.org/tutorials/1.6/start-linux.php

http://www.sfml-dev.org/tutorials/1.6/start-linux.php

under installing SFML is says "Once you have downloaded and extracted the files to your hard drive, you must install the SFML headers and library files to the appropriate location. To do so, you just have to go to the SFML-x.y directory and type "sudo make install".

id dont know what it means by going to the SFML-x.y directory?
then i did this

[/code]metulburr@metulburrPC ~/SFML-1.6 $ sudo make install
[sudo] password for metulburr:
make[1]: Entering directory `/home/metulburr/SFML-1.6/src/SFML'
make[2]: Entering directory `/home/metulburr/SFML-1.6/src/SFML/System'
make[2]: Leaving directory `/home/metulburr/SFML-1.6/src/SFML/System'
make[2]: Entering directory `/home/metulburr/SFML-1.6/src/SFML/Window'
make[2]: Leaving directory `/home/metulburr/SFML-1.6/src/SFML/Window'
make[2]: Entering directory `/home/metulburr/SFML-1.6/src/SFML/Network'
make[2]: Leaving directory `/home/metulburr/SFML-1.6/src/SFML/Network'
make[2]: Entering directory `/home/metulburr/SFML-1.6/src/SFML/Graphics'
make[2]: Leaving directory `/home/metulburr/SFML-1.6/src/SFML/Graphics'
make[2]: Entering directory `/home/metulburr/SFML-1.6/src/SFML/Audio'
make[2]: Leaving directory `/home/metulburr/SFML-1.6/src/SFML/Audio'
make[1]: Leaving directory `/home/metulburr/SFML-1.6/src/SFML'[code]

did i do this right? could someone  walk me through this process?

Pages: [1]
anything