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

Pages: [1] 2
1
Feature requests / Diagonal resize cursors on Linux
« on: July 12, 2020, 05:51:22 pm »
I would like to change the mouse cursor when the mouse is at the corner of a child window in my gui, but SFML doesn't support diagonal arrows on Linux (Cursor.hpp#L65-L66).

I know that this is because X11 doesn't support those double arrows, but could directional arrows (e.g. XC_bottom_left_corner) perhaps be added?
The following would be useful, but only the last 4 are required to add support for diagonal resizing on linux.
- SizeLeft
- SizeRight
- SizeTop
- SizeBottom
- SizeTopLeft
- SizeTopRight
- SizeBottomLeft
- SizeBottomRight

On linux, all of those exist.

On windows, none of those exist. It should be easy to just display the double arrow if one of those directional sizes are requested though.

On macOS, all of those should also exist, but are undocumented just like the diagonal double arrows. I'm not sure if they are ever used on mac though, maybe it would be better to fall back to double arrows here as well (for my gui I would only try to set those directional cursors in Linux anyway and use double arrows on Windows and macOS).

Is there any chance that those cursors could be added to SFML, even though they are specific for Linux?
I've already changed my code to just load those cursors directly and only use SFML when loading other cursors, but it would be nice if I could set those cursors via SFML as well in future SFML versions (as I now have to link with Xlib myself).

2
When linking static SFML libraries on linux, cmake doesn't automatically link to GLX (while it links fine to all other SFML dependencies).

The following simple cmake script is enough to reproduce it.
cmake_minimum_required(VERSION 3.5)
project(CMake-test)

set(SFML_STATIC_LIBRARIES TRUE)
find_package(SFML 2 COMPONENTS graphics window system REQUIRED)

add_executable(Test main.cpp)
target_link_libraries(Test PRIVATE sfml-graphics)

The main.cpp file is practically empty:
#include <SFML/Graphics.hpp>
int main()
{
    sf::RenderTexture target;
}

Running make will give the following output:
(click to show/hide)

Changing SFML_STATIC_LIBRARIES to FALSE fixes it, so it only occurs when linking statically.
Adding "GLX" to the target_link_libraries line also fixes the issue.

Edit: Linking to "GL" (instead of "GLX") also fixes it (but linking to "OpenGL" doesn't).

3
General / [iOS] SFMLConfigDependencies.cmake looks for OpenGL
« on: April 08, 2018, 09:08:29 am »
When using the latest SFML version from github, I can't use SFMLConfig.cmake to find SFML when building for iOS.
On iOS the sfml-window target has to link to OpenGL ES but the SFMLConfigDependencies.cmake always looks for OpenGL, so CMake gives the following error on find_package(SFML ...)
CMake Error at /Users/texus/Desktop/SFML/build-iOS/SFMLConfigDependencies.cmake:34 (set_property):
  set_property could not find TARGET OpenGL.  Perhaps it has not yet been
  created.
Call Stack (most recent call first):
  /Users/texus/Desktop/SFML/build-iOS/SFMLConfigDependencies.cmake:55 (sfml_bind_dependency)
  /Users/texus/Desktop/SFML/build-iOS/SFMLConfig.cmake:117 (include)
  /Users/texus/Desktop/SFML/cmake/toolchains/iOS.toolchain.cmake:211 (find_package)
  CMakeLists.txt:175 (find_host_package)


4
Graphics / RenderTexture texture flipped after copying
« on: November 13, 2017, 07:26:56 pm »
Since commit 6b71456, copying a texture from a render texture causes it to be flipped.

Code to reproduce:
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(400, 200), "SFML Window");

    sf::RectangleShape shape{{100, 100}};
    shape.setFillColor(sf::Color::Red);

    sf::RenderTexture rt;
    rt.create(200, 200);
    rt.clear(sf::Color::White);
    rt.draw(shape);
    rt.display();

    sf::Sprite s1(rt.getTexture());

    sf::Texture t = rt.getTexture(); // Copy texture before passing it to sprite
    sf::Sprite s2(t);
    s2.setPosition({200, 0});

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

        window.clear();
        window.draw(s1);
        window.draw(s2);
        window.display();
    }
}

The attached images show how it looked before and after commit 6b71456.

5
Window / Android sends Delete event instead of Backspace
« on: October 22, 2017, 11:37:21 am »
SFML maps the AKEYCODE_DEL event to Keyboard::Delete (WindowImplAndroid.cpp#L623) while this is actually the backspace key. The real delete key is AKEYCODE_FORWARD_DEL.

Is this a bug or was there a reason to do this? I find it strange that I just worked around this in my code when I encountered it a few years ago. Maybe I saw this post back then and though that it would be fixed, but it looks like it was forgotten.

6
I found a case in which text rendering is broken. After spending most of my day minimizing the code, I came up with the following minimal example.
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");

    sf::Font font;
    font.loadFromFile("DejaVuSans.ttf");

    sf::Text text("Hello", font, 17);

    font.getGlyph('g', 130, false); // A character that does not occur in the text

    for (const auto c : text.getString())
        font.getGlyph(c, 130, false);

    text.setCharacterSize(130);

    sf::Text anotherText("Hello", font, 17); // Same string
    anotherText.setCharacterSize(130);

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

        window.clear();

        glEnable(GL_SCISSOR_TEST);
        GLint m_scissor[4] = {};
        glGetIntegerv(GL_SCISSOR_BOX, m_scissor);
        glScissor(0, 150, 400, 450);

        // Clear again with different color just to show clipping area
        window.clear(sf::Color::Blue);

        window.draw(anotherText);

        glScissor(m_scissor[0], m_scissor[1], m_scissor[2], m_scissor[3]);

        window.display();
    }

    return EXIT_SUCCESS;
}

Instead of showing "Hello", it shows only the top part of some letters (the "L"s are ccompletely gone). I've attached a screenshot showing the issue.

I traced back at which SFML version this problem was introduced and I found that it only started since 6b71456. SFML versions before this commit show the text correctly.

It looks like glScissor has an effect on the internal font rendering, calling glDisable(GL_SCISSOR_TEST) at the start of Font::loadGlyph and calling glEnable(GL_SCISSOR_TEST) at the end of the function seems to fix the issue.

7
DotNet / Create Font and Texture from cPointer
« on: September 24, 2016, 05:02:11 pm »
I'm writing a .Net binding for TGUI and I can't find a way to receive fonts and textures from my c++ code.

The Font and Texture class provide a constructor to create them from a cPointer, however their access specifiers don't allow using them. The one in Font is 'private' because it isn't used outside the class while the one from Texture is 'internal' because it is used in the RenderTexture constructor to get the texture from C.

I basically have to do something similar as that line in the RenderTexture constructor but with both fonts and textures, but these font and texture constructors can't be used outside the SFML.Net code.

Is there any chance that these constructors could be specified as 'protected internal'? That way they still can't be used under normal circumstances but if someone needs them they can inherit from the class and pass the cPointer from there.
Or is there another solution that I am overlooking?

8
General / [Android] Using c++11 and gnustl
« on: July 22, 2016, 12:37:14 pm »
The code that I have requires c++11 and always worked without issues because libc++ could be used (and was used by default by SFML).
The last sfml commit however removed support for c++_shared and c++_static. (Could someone perhaps link to a discussion on why libc++ support was dropped?)

I can't use stlport because it lacks c++11 support (it e.g. does not have std::shared_ptr).

My code could compile using gnustl with minor modifications (gnustl e.g. misses std::round), but SFML seems to crash when using this STL. Below is the adb logcat output of the crash when running the sfml android example with "APP_STL := gnustl_static" and "APP_ABI := x86" set in jni/Application.mk.
Code: [Select]
07-22 11:32:13.163  2998  3011 F libc    : Fatal signal 11 (SIGSEGV), code 1, fault addr 0xc730245c in tid 3011 (om.example.sfml)
07-22 11:32:13.280   950   950 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
07-22 11:32:13.280   950   950 F DEBUG   : Build fingerprint: 'Android/sdk_google_phone_x86/generic_x86:6.0/MASTER/2524533:userdebug/test-keys'
07-22 11:32:13.280   950   950 F DEBUG   : Revision: '0'
07-22 11:32:13.280   950   950 F DEBUG   : ABI: 'x86'
07-22 11:32:13.280   950   950 F DEBUG   : pid: 2998, tid: 3011, name: om.example.sfml  >>> com.example.sfml <<<
07-22 11:32:13.280   950   950 F DEBUG   : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xc730245c
07-22 11:32:13.283   950   950 F DEBUG   :     eax c730245c  ebx b734a71c  ecx c730245c  edx b7357f1c
07-22 11:32:13.283   950   950 F DEBUG   :     esi c7302454  edi ab200000
07-22 11:32:13.283   950   950 F DEBUG   :     xcs 00000073  xds 0000007b  xes 0000007b  xfs 00000007  xss 0000007b
07-22 11:32:13.283   950   950 F DEBUG   :     eip b72d3ba3  ebp ab2381f0  esp a40ff210  flags 00210286
07-22 11:32:13.285   950   950 F DEBUG   :
07-22 11:32:13.285   950   950 F DEBUG   : backtrace:
07-22 11:32:13.285   950   950 F DEBUG   :     #00 pc 00081ba3  /system/lib/libc.so (pthread_mutex_lock+11)
07-22 11:32:13.285   950   950 F DEBUG   :     #01 pc 000a281a  /system/lib/libc.so (je_arena_dalloc_large+40)
07-22 11:32:13.285   950   950 F DEBUG   :     #02 pc 000be74e  /system/lib/libc.so (je_free+830)
07-22 11:32:13.285   950   950 F DEBUG   :     #03 pc 00016c4b  /system/lib/libc.so (free+30)
07-22 11:32:13.285   950   950 F DEBUG   :     #04 pc 00009e6b  /data/app/com.example.sfml-1/lib/x86/libsfml-example.so (operator delete(void*)+27)
07-22 11:32:13.285   950   950 F DEBUG   :     #05 pc 000081f6  /data/app/com.example.sfml-1/lib/x86/libsfml-example.so (main+1494)
07-22 11:32:13.285   950   950 F DEBUG   :     #06 pc 000082d8  /data/app/com.example.sfml-1/lib/x86/libsfml-example.so (sf::priv::main(sf::priv::ActivityStates*)+152)
07-22 11:32:13.285   950   950 F DEBUG   :     #07 pc 000089b0  /data/app/com.example.sfml-1/lib/x86/libsfml-example.so (sf::priv::ThreadFunctorWithArg<void* (*)(sf::priv::ActivityStates*), sf::priv::ActivityStates*>::run()+16)
07-22 11:32:13.285   950   950 F DEBUG   :     #08 pc 0000e082  /data/app/com.example.sfml-1/lib/x86/libsfml-system.so (sf::Thread::run()+18)
07-22 11:32:13.285   950   950 F DEBUG   :     #09 pc 0000f24b  /data/app/com.example.sfml-1/lib/x86/libsfml-system.so
07-22 11:32:13.285   950   950 F DEBUG   :     #10 pc 00080a93  /system/lib/libc.so (__pthread_start(void*)+56)
07-22 11:32:13.285   950   950 F DEBUG   :     #11 pc 00021952  /system/lib/libc.so (__start_thread+25)
07-22 11:32:13.285   950   950 F DEBUG   :     #12 pc 000170b6  /system/lib/libc.so (__bionic_clone+70)

This was the cmake command used for this sfml version:
Code: [Select]
cmake -DANDROID_ABI=x86 -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/android.toolchain.cmake -DANDROID_STL=gnustl_static ..
The same crash seems to occur in older SFML versions as well, but at least in these version I was able to use c++_static (or c++_shared).

Is there a way to use c++11 on android with the latest sfml version?

9
General / sf::Keyboard::setVirtualKeyboardVisible crashes on android
« on: February 15, 2016, 05:40:40 pm »
The following code crashes on android since this commit.
#include <SFML/Window.hpp>
int main()
{
    sf::Keyboard::setVirtualKeyboardVisible(true);
}

Backtrace from adb logcat:
Code: [Select]
02-15 17:27:44.603   949   949 F DEBUG   :     #00 pc 00083606  /system/lib/libc.so (tgkill+22)
02-15 17:27:44.603   949   949 F DEBUG   :     #01 pc 000815e8  /system/lib/libc.so (pthread_kill+70)
02-15 17:27:44.603   949   949 F DEBUG   :     #02 pc 00027205  /system/lib/libc.so (raise+36)
02-15 17:27:44.603   949   949 F DEBUG   :     #03 pc 000209e4  /system/lib/libc.so (abort+80)
02-15 17:27:44.603   949   949 F DEBUG   :     #04 pc 005173cb  /system/lib/libart.so (art::Runtime::Abort()+377)
02-15 17:27:44.603   949   949 F DEBUG   :     #05 pc 0014d9f3  /system/lib/libart.so (art::LogMessage::~LogMessage()+1343)
02-15 17:27:44.603   949   949 F DEBUG   :     #06 pc 003a5252  /system/lib/libart.so (art::JavaVMExt::JniAbort(char const*, char const*)+3842)
02-15 17:27:44.603   949   949 F DEBUG   :     #07 pc 003a5eac  /system/lib/libart.so (art::JavaVMExt::JniAbortV(char const*, char const*, char*)+116)
02-15 17:27:44.603   949   949 F DEBUG   :     #08 pc 00163a10  /system/lib/libart.so (art::ScopedCheck::AbortF(char const*, ...)+62)
02-15 17:27:44.603   949   949 F DEBUG   :     #09 pc 00176f4d  /system/lib/libart.so (art::CheckJNI::DeleteRef(char const*, _JNIEnv*, _jobject*, art::IndirectRefKind)+829)
02-15 17:27:44.603   949   949 F DEBUG   :     #10 pc 001772d3  /system/lib/libart.so (art::CheckJNI::DeleteLocalRef(_JNIEnv*, _jobject*)+52)
02-15 17:27:44.603   949   949 F DEBUG   :     #11 pc 000127b4  /data/app/com.example.sfml-1/lib/x86/libsfml-window.so
02-15 17:27:44.603   949   949 F DEBUG   :     #12 pc 000092ac  /data/app/com.example.sfml-1/lib/x86/libsfml-window.so (sf::Keyboard::setVirtualKeyboardVisible(bool)+28)
02-15 17:27:44.603   949   949 F DEBUG   :     #13 pc 000020d1  /data/app/com.example.sfml-1/lib/x86/libsfml-example.so (main+33)
02-15 17:27:44.603   949   949 F DEBUG   :     #14 pc 00002178  /data/app/com.example.sfml-1/lib/x86/libsfml-example.so (sf::priv::main(sf::priv::ActivityStates*)+152)
02-15 17:27:44.603   949   949 F DEBUG   :     #15 pc 00002330  /data/app/com.example.sfml-1/lib/x86/libsfml-example.so (sf::priv::ThreadFunctorWithArg<void* (*)(sf::priv::ActivityStates*), sf::priv::ActivityStates*>::run()+16)
02-15 17:27:44.603   949   949 F DEBUG   :     #16 pc 0000e392  /data/app/com.example.sfml-1/lib/x86/libsfml-system.so (sf::Thread::run()+18)
02-15 17:27:44.603   949   949 F DEBUG   :     #17 pc 0000f54b  /data/app/com.example.sfml-1/lib/x86/libsfml-system.so
02-15 17:27:44.603   949   949 F DEBUG   :     #18 pc 00080a93  /system/lib/libc.so (__pthread_start(void*)+56)
02-15 17:27:44.603   949   949 F DEBUG   :     #19 pc 00021952  /system/lib/libc.so (__start_thread+25)
02-15 17:27:44.603   949   949 F DEBUG   :     #20 pc 000170b6  /system/lib/libc.so (__bionic_clone+70)

The issue seems to be related to this line. Removing that line and thus not deleting the lNativeActivity seems to solve the crash.

10
General / Crash on android due to font destruction
« on: February 09, 2016, 06:41:22 pm »
The following code crashes on android with the latest SFML version. The bug was introduced in this commit, earlier sfml versions don't crash on this code.
#include <SFML/Graphics.hpp>
#include <memory>

int main()
{
    std::shared_ptr<sf::Font> font3;

    sf::Font font1;
    font1.loadFromFile("sansation.ttf");

    font3 = std::make_shared<sf::Font>(font1);

    sf::Font font2;
    font2.loadFromFile("sansation.ttf");

    font3 = std::make_shared<sf::Font>(font2);
}

The backtrace that is printed in logcat:
Code: [Select]
02-09 18:10:35.218   949   949 F DEBUG   : backtrace:
02-09 18:10:35.218   949   949 F DEBUG   :     #00 pc 00058eef  /data/app/com.example.tgui-1/lib/x86/libsfml-graphics.so (FT_Stroker_Done+31)
02-09 18:10:35.218   949   949 F DEBUG   :     #01 pc 00019ea6  /data/app/com.example.tgui-1/lib/x86/libsfml-graphics.so (sf::Font::cleanup()+310)
02-09 18:10:35.218   949   949 F DEBUG   :     #02 pc 0001b91e  /data/app/com.example.tgui-1/lib/x86/libsfml-graphics.so (sf::Font::~Font()+30)
02-09 18:10:35.218   949   949 F DEBUG   :     #03 pc 00002dee  /data/app/com.example.tgui-1/lib/x86/libtgui-example.so (std::__1::__shared_ptr_emplace<sf::Font, std::__1::allocator<sf::Font> >::__on_zero_shared()+30)
02-09 18:10:35.218   949   949 F DEBUG   :     #04 pc 00089315  /data/app/com.example.tgui-1/lib/x86/libc++_shared.so (std::__1::__shared_weak_count::__release_shared()+53)
02-09 18:10:35.218   949   949 F DEBUG   :     #05 pc 00002b26  /data/app/com.example.tgui-1/lib/x86/libtgui-example.so (main+422)
02-09 18:10:35.218   949   949 F DEBUG   :     #06 pc 00002c98  /data/app/com.example.tgui-1/lib/x86/libtgui-example.so (sf::priv::main(sf::priv::ActivityStates*)+152)
02-09 18:10:35.218   949   949 F DEBUG   :     #07 pc 00002fd0  /data/app/com.example.tgui-1/lib/x86/libtgui-example.so (sf::priv::ThreadFunctorWithArg<void* (*)(sf::priv::ActivityStates*), sf::priv::ActivityStates*>::run()+16)
02-09 18:10:35.218   949   949 F DEBUG   :     #08 pc 0000e392  /data/app/com.example.tgui-1/lib/x86/libsfml-system.so (sf::Thread::run()+18)
02-09 18:10:35.218   949   949 F DEBUG   :     #09 pc 0000f54b  /data/app/com.example.tgui-1/lib/x86/libsfml-system.so
02-09 18:10:35.218   949   949 F DEBUG   :     #10 pc 00080a93  /system/lib/libc.so (__pthread_start(void*)+56)
02-09 18:10:35.218   949   949 F DEBUG   :     #11 pc 00021952  /system/lib/libc.so (__start_thread+25)
02-09 18:10:35.218   949   949 F DEBUG   :     #12 pc 000170b6  /system/lib/libc.so (__bionic_clone+70)

11
SFML projects / TGUI: GUI library for SFML
« on: September 01, 2015, 02:47:25 am »
TGUI: Texus' Graphical User Interface

Easy to use
TGUI aims to be easy to use, with only a few lines you have a fully functioning TextBox on your screen.
tgui::TextBox::Ptr textbox = tgui::TextBox::create();
textbox->setPosition(100, 50);
textbox->setSize(300, 200);
textbox->setTextSize(16);
gui.add(textbox);


Customizable
The widgets can be created by just using colors or by using images, making the look very customizable.
When widgets are created without a theme then they will use the build-in white theme (top left image). TGUI also ships with ready to use Black and BabyBlue themes (top right and bottom right images).


(click images for larger version)


Cross-platform
TGUI tries to support the same operating systems as SFML, so it supports Windows, Linux, Mac OS X and FreeBSD and provides experimental support for Raspberry Pi, Android and iOS.


Installation tutorials are available for each of these systems.


Gui Builder
A Gui Builder is included to allow easily creating and editing forms.



Unique callback system
Connecting signals is very easy:
void function() {};
button->connect("pressed", function);

But the system can detect certain parameters and fill them in with information about the event:
// str will contain the text from the button
void function2(std::string str) {};
button->connect("pressed", function2);
button->connect("pressed", [](const sf::String& str){});


Relative sizes and positions
Next to passing absolute values, you can specify positions and sizes relative to the parent.
checkbox->setPosition("30%", "20%");
editBox->setSize(400, "5%");

The widget position and size will automatically update when its parent resizes.




More information
For more information about the project, check the website which has tutorials, documentation and a few example codes. Source code can be found on GitHub.

If you have problems with getting tgui to work or if you find bugs then please open a topic on the TGUI forum.


Some images
 

 

12
SFML projects / Non-rectangular semi-transparent window
« on: June 07, 2015, 01:12:35 am »
This is just some code that I wanted to share.
It loads an image from a file and will give the window the shape of that image. You can also set the opacity of the window.

I only wrote code for Windows and Linux. I will try to have a look at OS X next month. In case I update the code you can find it on github.

Edit: The code now works on Windows, Linux and Mac.
On mac you have to compile both files, on windows and linux just Transparent.cpp.
On windows you only need the sfml libraries, on linux you also have to add "-lX11 -lXext" to the linker flags and on mac you should add "-framework Cocoa".

Transparent.cpp:
(click to show/hide)

Transparent.mm (only needed on mac)
(click to show/hide)

Result:

13
Graphics / font.getLineSpacing not correct for first line
« on: May 10, 2015, 04:58:21 pm »
The getLineSpacing apparently can't be used to determine the height of several lines of text. Suppose I have a TextBox widget which is given the size of 5*lineSpacing so that it could fit exactly 5 lines of text. The bottom part of the last line will be outside the text box because there is too much space on top. I'm not talking about the text.getLocalBounds().top here because the offset is slightly different.

The last line of the text looks like this:

The background rectangle (of which the height is calculated with getLineSpacing) is missing 9 pixels for a text size of 100.

It is a bit hard to explain so here is the full example code (I took the font from the pong example).
#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
    const unsigned int TEXT_SIZE = 100;

    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML test");
    window.setFramerateLimit(30);

    sf::Font font;
    font.loadFromFile("sansation.ttf");

    sf::Text text;
    text.setFont(font);
    text.setCharacterSize(TEXT_SIZE);
    text.setColor(sf::Color::Black);
    text.setString(L\ng\ng\ng\ng");

    sf::FloatRect bounds = text.getLocalBounds();

    sf::RectangleShape bg(sf::Vector2f(bounds.left + bounds.width, 5 * font.getLineSpacing(TEXT_SIZE)));
    bg.setPosition(text.getPosition());
    bg.setFillColor(sf::Color::Blue);

    std::cout << "bounds top = " << bounds.top << std::endl;
    std::cout << "bounds height = " << bounds.height << std::endl;
    std::cout << "full heigh = " << bounds.top + bounds.height << std::endl << std::endl;

    std::cout << "line spacing = " << font.getLineSpacing(TEXT_SIZE) << std::endl;
    std::cout << "5*lineSpacing = " << 5*font.getLineSpacing(TEXT_SIZE) << std::endl << std::endl;

    // lineHeight is character size + part of letter 'g' that lies below the baseline
    // When using this as height for the first line of text, the total height of the background rectangle is correct
    float lineHeight = text.getCharacterSize()
                       + font.getGlyph('g', TEXT_SIZE, false).bounds.height
                       + font.getGlyph('g', TEXT_SIZE, false).bounds.top;

    std::cout << "calculated line height = " << lineHeight << std::endl;
    std::cout << "lineHeight + 4*lineSpacing = " << lineHeight + 4*(font.getLineSpacing(TEXT_SIZE)) << std::endl;

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

        window.clear(sf::Color(200, 200, 200));
        window.draw(bg);
        window.draw(text);
        window.display();
    }

    return EXIT_SUCCESS;
}

The following is being printed in the terminal:
Code: [Select]
bounds top = 11
bounds height = 543
full heigh = 554

line spacing = 109
5 * lines spacing = 545

calculated line height = 118
lineHeight + 4*lineSpacing = 554

Is this a bug in SFML?
If it isn't a bug, is there any way that I can know the height of several lines of text upfront? Because I either seem to need the bounds.top or the part of the letters beneath the baseline (for which I had to hardcode the 'g' character in this example to get it).

14
DotNet / TGUI for C#
« on: June 21, 2013, 04:11:33 pm »
Update:

TGUI.Net is now released and can be found on tgui.net.


Original post:
--------------------------------------------------------------

Some time ago someone requested a c# port for TGUI.
I wanted to ask if anyone is still interested in this.

Code would look like the following (can still be changed if needed).
using System;
using SFML.Window;
using SFML.Graphics;
using TGUI;

namespace window
{
    static class Program
    {
        static public void LoadObjects ( Gui gui )
        {
            // Create the background image
            Picture picture = gui.Add (new Picture("xubuntu_bg_aluminium.jpg"));
            picture.Size = new Vector2f(800, 600);

            // Create the username label
            Label labelUsername = gui.Add (new Label());
            labelUsername.Text = "Username:";
            labelUsername.Position = new Vector2f(200, 100);

            // Create the password label
            Label labelPassword = gui.Add (new Label());
            labelPassword.Text = "Password:";
            labelPassword.Position = new Vector2f(200, 250);

            // Create the username edit box
            EditBox editBoxUsername = gui.Add (new EditBox("objects/Black.conf"), "Username");
            editBoxUsername.Size = new Vector2f(400, 40);
            editBoxUsername.Position = new Vector2f(200, 140);

            // Create the password edit box (we will copy the previously created edit box)
            EditBox editBoxPassword = gui.Add(new EditBox(editBoxUsername), "Password");
            editBoxPassword.Position = new Vector2f(200, 290);
            editBoxPassword.PasswordCharacter = "*";

            // Create the login button
            Button button = gui.Add (new Button("objects/Black.conf"));
            button.Size = new Vector2f(260, 60);
            button.Position = new Vector2f(270, 440);
            button.Text = "Login";
            button.CallbackId = 1;
            button.LeftMouseClickedCallback += OnButtonClick;
        }

        static void Main ()
        {
            // Create the window
            RenderWindow window = new RenderWindow (new VideoMode(800, 600), "TGUI.Net Login Screen Example");
            Gui gui = new Gui (window);

            window.Closed += OnClosed;

            // Load the font
            gui.GlobalFont = new Font("Fonts/DejaVuSans.ttf");

            // Load the objects
            LoadObjects (gui);

            // Main loop
            while (window.IsOpen())
            {
                // Process events
                window.DispatchEvents ();

                window.Clear();
                gui.Draw();
                window.Display();
            }
        }

        static void OnClosed(object sender, EventArgs e)
        {
            ((Window)sender).Close ();
        }

        static void OnButtonClick(object sender, MouseCallbackArgs e)
        {
            // Get the username and password
            EditBox editBoxUsername = ((Button)sender).Parent.Get<EditBox>("Username");
            EditBox editBoxPassword = ((Button)sender).Parent.Get<EditBox>("Password");

            System.Console.WriteLine("Username: " + editBoxUsername.Text);
            System.Console.WriteLine("Password: " + editBoxPassword.Text);
        }
    }
}
 

Which would give the following result:

15
Graphics / Calling Text.setString before RenderTexture.create
« on: May 27, 2012, 03:01:46 pm »
I am having a problem with the RenderTexture.
If I call e.g. sf::Text::setString before calling sf::RenderTexture::create then I get a strange result.

In the example code below I am first setting the string to "abcde" before the create call and after the create call I set it to "test". Only the "e" will be drawn on the screen. After looking into this I found out that only the a, b, c, d or e letters would be drawn. So the letters that were not used before the create call are simply not drawn.
Calling window.draw(text) instead of drawing the render texture has the same result!

#include <SFML/Graphics.hpp>

int main()
{
    // Create a new render-window
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
   
    // Create a new render-texture
    sf::RenderTexture texture;
   
    sf::Text text;
    text.setString("abcde");
   
    if (!texture.create(500, 500))
        return -1;
   
    text.setString("test");

    // The main loop
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }
       
        // Clear the whole texture with red color
        texture.clear(sf::Color::Red);

        // Draw the text on the texture
        texture.draw(text);
       
        // We're done drawing to the texture
        texture.display();
       
        // Now we start rendering to the window, clear it first
        window.clear();
       
        // Draw the texture
        sf::Sprite sprite(texture.getTexture());
        window.draw(sprite);
       
        // End the current frame and display its contents on screen
        window.display();
    }
}

I am on a Mac OS X Lion with SFML2-RC.

EDIT:
I tested it in my VirtualBox and both windows and linux could display the word "test" correctly.
I did also notice however that the texture was drawn a few pixels lower on my windows xp. The red rectangle didn't start at top position 0.

Pages: [1] 2
anything