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 - bonsairobo

Pages: [1]
1
Window / X360 controller triggers on linux
« on: July 12, 2013, 10:56:17 pm »
I'm currently trying to figure out how the triggers on an X360 controller are defined in sf::Joystick. Running jstest-gtk shows that the triggers each belong to an axis. However, I don't think those axes are exposed to SFML. X and Y are used for the left analog stick, U and V for the right analog stick, and Z and R are not defined, according to sf::Joystick::hasAxis(0, sf::Joystick::Z/R). The only other option would be that they are interpreted as buttons, and I'm not sure which ones to check.

2
Here is the library I wrote with SFML:

#include <string>
#include "SFML/Graphics.hpp"

class Window
{
public:
        sf::RenderWindow window;
        sf::Event event;

        Window(int width, int height, std::string title)
        {
                window.create(sf::VideoMode(width, height, 32), title);
        }

        void display()
        {
                window.display();
        }

        bool pollEvents()
        {
                while(window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                        {
                                window.close();
                                return false;
                        }
                        else
                                return true;
                }
        }

        void clear()
        {
                window.clear();
        }
};

extern "C" Window* new_Window(int width, int height, char title[])
{
        return new Window(width, height, title);
}

extern "C" void display_Window(Window* window)
{
        window->display();
}

extern "C" void clear_Window(Window* window)
{
        window->clear();
}

extern "C" bool pollEvents_Window(Window* window)
{
        return window->pollEvents();
}

And here is the python wrapper:

from ctypes import *
windowLib = CDLL("./Window.so")

class Window(object):
        def __init__(self, width, height, title):
                self.obj = windowLib.new_Window(width, height, bytes(title, "ascii"))
               
        def display(self):
                windowLib.display_Window(self.obj)
               
        def clear(self):
                windowLib.clear_Window(self.obj)
               
        def pollEvents(self):
                return windowLib.pollEvents_Window(self.obj)
               
window = Window(800, 600, "Title")

windowIsOpen = True
while windowIsOpen:
        windowIsOpen = window.pollEvents()
        print(windowIsOpen)
        window.clear()
        window.display()

This python script works for opening the window, but the window closes shortly afterwords.  The print function manages to print "1 1 1 0" before the window closes itself.  I'm not sure what's causing my pollEvents function to return 0.

3
This might be something funky with my own computer, but I sent one of my programs to a friend and he had the same problem.

Whenever I poll for an event as written in the code below, my program will close if I circle my mouse cursor around the top or bottom left corners of the window.

The problem is illustrated in this video: http://youtu.be/PD7-y1_H6qo?t=15s

You can try it yourself by downloading my pong game here: http://www.mediafire.com/?6xrvvtbr7qc03jo, but the same problem occurs in any program I make using the method below.

while(tetris.isOpen())
        {
                sf::Event event;
                while(tetris.pollEvent(event))
                {
                        if (event.key.code == sf::Keyboard::Escape)
                                tetris.close();
                }
        }
 

4
Graphics / Can't draw text or use text constructor [Solved]
« on: January 22, 2013, 07:55:38 pm »
#include <SFML\Graphics.hpp>
#include <iostream>
using namespace std;

#define RENDERHEIGHT 800
#define RENDERWIDTH 400

int main()
{
        sf::RenderWindow tetris(sf::VideoMode(RENDERWIDTH, RENDERHEIGHT, 32), "TETRIS");
        tetris.setFramerateLimit(60);
        tetris.setMouseCursorVisible(false);

        sf::Text text;
        text.setString("hello");
        text.setPosition(0, 0);
        text.setCharacterSize(30);
        text.setStyle(sf::Text::Bold);
        text.setColor(sf::Color::Red);

        while(tetris.isOpen())
        {
                sf::Event event;
                while(tetris.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed || event.key.code == sf::Keyboard::Escape)
                                tetris.close();
                }

                tetris.draw(text);
                tetris.display();
        }

        return 0;
}
 

I'm using SFML 2.0.  That is my exact code, which compiles, but no text is visible.  I've tried setting different positions, loading my own font (which gave me a runtime error), and on top of that, the text constructor won't accept string arguments.

sf::Text text("hello"); does not compile as VS doesn't think the constructor takes string arguments.

Any help?

Pages: [1]
anything