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

Pages: [1]
Window / Shift + Key creates unknown event in SFML 2.3
« on: October 10, 2015, 10:23:42 am »
I recently upgraded from SFML 2.2 to 2.3.2, and at first the upgrade seemed seamless, with no compiler errors. But I discovered I couldn't open my console (Which is opened with 'LControl + LShift + C'). After doing some testing it seems like inputting a key on its own (A, B, C etc.) gives the expected key code, but inputting shift and a key gives an unknown key code. I know this bug was  reported a few years ago but since it worked in the previous version I don't know why it would be broken again. I'm using Ubuntu 14.04 (Linux) and the problem occurs with both my normal keyboard and the on-screen keyboard.


Only just saw this, I can try to compile SFML myself but I have no experience with it

Graphics / Overlapping "smooth" textures have slight black outlines
« on: August 24, 2015, 10:56:13 am »
I'm making a city building game, so when the view is zoomed out I have to set all the textures to smooth, otherwise the buildings look odd and lines start to disappear. But, when I set the textures to smooth, a blurry black outline appears in all the places where two sprites overlap. I've tried changing the anti-aliasing level of the window, but nothing changes.

SFML Version: 2.2
Ubuntu Version: 14.04
Graphics Card: Nvidia GTX 750 Ti

(It's very hard to see at first, but when you see it once, it's hard to un-see)

Graphics / Fullscreen disables second monitor
« on: August 15, 2015, 10:37:22 am »
As a gamer myself (with two monitors), I hate when games do this. Basically, when I go into fullscreen mode, all my moinitors go black for a few seconds, but the second monitor never turns on until I quit the game, and then all the windows on my second monitor get moved to my primary one. If the window isn't the correct resolution, my monitor decides to auto-adjust at whatever resolution the game is at, and then don't change back after quitting the game. I'm currently on Linux (Ubuntu specifically), and I haven't tested windows, but since almost all games on Linux use OpenGL (and I'm pretty sure SFML does too) is there any way to fix this?

I'd assume I don't need a minimal example since its obvious how to go into fullscreen in SFML

This is a very odd and specific circumstance but, I recently exposed some of the classes from SFML (I hope that's allowed) to Lua with a C++ header-only library called LuaBridge (https://github.com/vinniefalco/LuaBridge). Most of the classes were exposed just fine (but sf::Event because LuaBridge doesn't like Enums or Unions), but after trying to use sf::Text I get an error. My error is that I get a Segmentation Fault after I create a sf::Text object, then set the font with a sf::Font object (and no, the reference isn't destroyed because this doesn't happen with sf::Texture and sf::Sprite).

Here is my C++ code to expose some SFML classes, and run a lua script called script.lua:

#include <string>

#include <SFML/Graphics.hpp>

#include <lua.hpp>
#include <LuaBridge.h>

//Wrapper for sf::Text:
class TextWrap
        sf::Text member;

        void setCharacterSize(const int& newSize) {member.setCharacterSize(newSize);}
        int getCharacterSize() {return member.getCharacterSize();}

        void setColor(const sf::Color& newColor) {member.setColor(newColor);}
        sf::Color getColor() {return member.getColor();}

        void setFont(const sf::Font& newFont) {member.setFont(newFont);}
        const sf::Font* getFont() {return member.getFont();}

        void setPosition(const sf::Vector2f& newPosition) {member.setPosition(newPosition);}
        sf::Vector2f getPosition() {return member.getPosition();}

        void setRotation(const float& rotation) {member.setRotation(rotation);}
        float getRotation() {return member.getRotation();}

        void setScale(const sf::Vector2f& newScale) {member.setScale(newScale);}
        sf::Vector2f getScale() {return member.getScale();}

        void setString(const std::string& text) {member.setString(text);}
        std::string getString() {return member.getString();}

        void move(const sf::Vector2f& movePos) {member.move(movePos);}
        void rotate(const float& rotation) {member.rotate(rotation);}
        void scale(const sf::Vector2f& scaleAmount) {member.scale(scaleAmount);}

        sf::Text getMember() {return member;}

class WindowWrap
        sf::RenderWindow member;

        void createWindowed(const unsigned int width, const unsigned int height, const std::string& title)
        void close() {member.close();}

        void clear(const sf::Color& clearColour) {member.clear(clearColour);}
        void display() {member.display();}
        void draw(TextWrap& text) {member.draw(text.getMember());}

int main()
    lua_State* L = luaL_newstate();
        .addConstructor<void(*)(float, float)>()
        .addData("x", &sf::Vector2f::x)
        .addData("y", &sf::Vector2f::y)
        .addConstructor<void(*)(int, int)>()
        .addData("x", &sf::Vector2i::x)
        .addData("y", &sf::Vector2i::y)

        .addConstructor<void(*)(unsigned int, unsigned int, unsigned int, unsigned int)>()
        .addData("r", &sf::Color::r)
        .addData("g", &sf::Color::g)
        .addData("b", &sf::Color::b)
        .addData("a", &sf::Color::a)

        .addFunction("loadFromFile", &sf::Font::loadFromFile)
        .addFunction("setCharacterSize", &TextWrap::setCharacterSize)
        .addFunction("getCharacterSize", &TextWrap::getCharacterSize)
        .addFunction("setColor", &TextWrap::setColor)
        .addFunction("getColor", &TextWrap::getColor)
        .addFunction("setFont", &TextWrap::setFont)
        .addFunction("getFont", &TextWrap::getFont)
        .addFunction("setPosition", &TextWrap::setPosition)
        .addFunction("getPosition", &TextWrap::getPosition)
        .addFunction("setRotation", &TextWrap::setRotation)
        .addFunction("getRotation", &TextWrap::getRotation)
        .addFunction("setScale", &TextWrap::setScale)
        .addFunction("getScale", &TextWrap::getScale)
        .addFunction("setString", &TextWrap::setString)
        .addFunction("getString", &TextWrap::getString)
        .addFunction("move", &TextWrap::move)
        .addFunction("rotate", &TextWrap::rotate)
        .addFunction("scale", &TextWrap::scale)

        .addFunction("createWindowed", &WindowWrap::createWindowed)
        .addFunction("close", &WindowWrap::close)
        .addFunction("clear", &WindowWrap::clear)
        .addFunction("display", &WindowWrap::display)
        .addFunction("draw", &WindowWrap::draw)

    WindowWrap mainWindow; //This is defined here so C++ knows if the main application is open
    mainWindow.createWindowed(800, 600, "Lua Test");
    luabridge::push(L, &mainWindow);
    lua_setglobal(L, "mainWindow");

    luaL_dofile(L, "./script.lua");

Here is script.lua:

text = Text();
text:setPosition(Vector2f(100, 100));
text:setString("Hello World");
font = Font();
text:setFont(font); --If I remove this I don't get a Segmentation Fault
mainWindow:drawText(text); --But the Segmentation Fault happens here

The chances of someone being familiar with C++, SFML, LuaBridge and Lua are very low, so I don't expect someone to know exactly why, but just to have an idea or suggestion.

Details I forgot:
  • OS: Ubuntu 14.04
  • Graphics Card: NVIDIA GTX 750 Ti (Not sure if it matters)
  • SFML Version: 2.1

Debugger Callstack:

Code: [Select]
#0 0x7ffff7bb4dcc sf::Font::getTexture(unsigned int) const() (/usr/lib/x86_64-linux-gnu/libsfml-graphics.so.2:??)
#1 0x7ffff7bcdd3e sf::Text::draw(sf::RenderTarget&, sf::RenderStates) const() (/usr/lib/x86_64-linux-gnu/libsfml-graphics.so.2:??)
#2 0x7ffff7bc6b17 sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&) () (/usr/lib/x86_64-linux-gnu/libsfml-graphics.so.2:??)
#3 0x407439 WindowWrap::drawText(this=0x7fffffffe0f0, text=...) (/home/ben/Documents/Programming/C++/Projects/TEST/main.cpp:56)
#4 0x410686 luabridge::FuncTraits<void (WindowWrap::*)(TextWrap&) (../../Resources/External/Cross-Platform/LuaBridge/detail/FuncTraits.h:209)
#5 0x40e774 luabridge::CFunc::CallMember<void (WindowWrap::*)(TextWrap&) (../../Resources/External/Cross-Platform/LuaBridge/detail/CFunctions.h:313)
#6 0x7ffff756561d ??() (/usr/lib/x86_64-linux-gnu/liblua5.2.so.0:??)
#7 0x7ffff75709b4 ??() (/usr/lib/x86_64-linux-gnu/liblua5.2.so.0:??)
#8 0x7ffff7565989 ??() (/usr/lib/x86_64-linux-gnu/liblua5.2.so.0:??)
#9 0x7ffff7564fac ??() (/usr/lib/x86_64-linux-gnu/liblua5.2.so.0:??)
#10 0x7ffff7565bc1 ??() (/usr/lib/x86_64-linux-gnu/liblua5.2.so.0:??)
#11 0x7ffff7561c9d lua_pcallk() (/usr/lib/x86_64-linux-gnu/liblua5.2.so.0:??)
#12 0x404523 main() (/home/ben/Documents/Programming/C++/Projects/TEST/main.cpp:181)

Graphics / Scale sf::Texture
« on: June 20, 2015, 02:55:29 pm »
I see that sf::Sprite has sf::Sprite::setScale() and sf::Sprite::scale() functions, and I feel it would be better if I could scale my master texture, instead of the thousands of sprites that use that texture. I considered loading the image file into a texture, setting the sprite and scaling it, then putting the sprite into an image, then putting it into the original texture (which is way too long and doesn't even work). I'm not implying I want a sf:Texture::setScale() function, just that I want to know how I can achieve this (maybe even an algorithm that scales a pixel array)

I had an idea where I created a class which stored textures in a vector, then all the other objects could have a pointer to the necessary texture in the vector, so that they could draw without needing their own copy. That idea didn't work because I got just a white square, which according to the tutorials means it can't find the texture. There are two ways I could get around this, I could have every object have a copy of its own texture (as stated above), or I could do sf::Sprite::setTexture every time I need to draw, which brings me to the question, which would be faster? The reason I am hesitant to have lots of copies of the same texture is because the game I am developing is a 2D tile based game (similar to terraria or starbound), and I don't think having lots of copies of the same dirt texture would be a good idea

General / Segmentation error with example code and Ubuntu
« on: March 31, 2015, 12:29:33 pm »
When I tried to compile the example code (from here: http://www.sfml-dev.org/tutorials/2.2/start-linux.php),  the desired green circle appears for a short amount of time (less than a second usually), then the window closes and the terminal says Segmentation error (core dumping). On my previous OS (Windows 7) the example works perfectly, and doesn't close unexpectedly.

After running the Code::Blocks debugger, I picked out a piece of text that seems to be appropriate:
Program received signal SIGSEGV, Segmentation fault. In sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&) () (/home/ben/Documents/C++ Programming/Resources/SFML-2.2/lib/libsfml-graphics.so.2.2.0)

Specs and Versions:
Ubuntu Version: 14.04 (64 bit)
SFML Version: 2.2
IDE: Code::Blocks

Pages: [1]