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

Pages: [1] 2
Graphics / sf::Text local bounds
« on: January 04, 2019, 08:58:17 pm »

Question about how to interpret the result of getLocalBounds() when called for an sf::Text object.

I've got 4 strings which I am calling getLocalBounds() on, and the results are:

[left, top, width, height]

[ 0, 3, 32, 8 ]
[ 0, 3, 35, 8 ]
[ 0, 3, 33, 8 ]
[ 0, 3, 122, 11 ]

The top variable is always 3. I would have expected it to be zero. What is the interpretation of this?


Graphics / SFML Drawing Hierarchies
« on: December 26, 2018, 01:16:42 pm »
I'm not really sure where to direct this question, so I guessed graphics as the most appropriate subforum.

I'm attempting to implement a kind of GUI toolkit for SFML. This project actually started some months ago now. I'm aware that such things already exist but I wanted a GUI library to do a specific thing which is why I started my own.

I put this project on hold and then had another idea for something else recently so I've started work on it again. I didn't actually get very far in the first place.

So far I have something like this:

1: A base class which inherits sf::Drawable. This class also adds an "event" function which events are passed to
2: Some gui objects, textbox, button, context menu, which inherit from the base class
3: Some of my gui objects are nested, ie; the context menu has context menu items

My question is about drawing these objects.

All the gui objects have a sf::RectangleShape which is used to draw the background of the object.

The override draw method calls

sf::RenderTarget target;

This is just to show the basic principle of how everything is going to work.

At the moment, for all my objects, I have a setPosition method which changes the sf::RectangleShape position.

For my example of context menu, which has a parent-child relationship in that several context menu items are children of the parent, I am unsure of how to proceed here.

One possibly solution is to use absolute positions, which is what sfml seems to want to use. In this way, if the position of the context menu is changed, then the positions of all the child items would also have to be changed.

This doesn't seem like a good solution, since I would prefer to store the relative locations of the child objects relative to the parent rather than the absolute position in the window.

Is there a better way of approaching this problem?

Window / Re: Window (not resizable) - resizeing without create() & close()
« on: December 26, 2018, 12:07:25 am »
Ok I seem to have actually found an acceptable solution:

I do:

1: window.setView(....)
2: window.setSize(...)

I assume this is an "approved solution" (ie; It's ok to do this?)


Window / Window (not resizable) - resizeing without create() & close()
« on: December 25, 2018, 11:41:47 pm »

Currently writing an app in SFML which loads an image from file and displays it.

I know I'm not doing something quite right as I get strange results. Allow me to explain the problem...

I open an SFML window, with a "default" videomode of 800x600.

The reason is that the user chooses the image to display so the VM resolution (size) is not known at start time and it is not constant during the runtime of the app.

... You can probably see where this is going, and guess what the problem is?

At some point during the app runtime the user chooses an image to display. If the image is smaller than 800 x 600, I want the (non-resizable) window to change size such that it crops itself to fit the image. To clarify, I have set sf::Style::Titlebar and sf::Style::Close to make the window "non-resizable".

First I tried to:

1: Load the image into a texture
2: Create sprite and set texture
3: Change window size to match the size given by the texture
4: Draw the sprite

I "cout" the texture size, the sprite global bounds, the sprite scale and the window size. They all agree except sprite scale which is 1.0.

However the image does not fill the window. It is smaller than the window.

My code is simple and I can provide it, but without an image to test it on (perhaps I can find one online which we can agree to all use?) it won't give the same results for everyone who runs the code...

Since this didn't work, my suspicions were that the video mode (which is larger than the texture size) was causing the issue.

In other words, the VM is 800 x 600, and the BMP image is 640 x 480... Therefore when I call window.resize(640, 480) a 800 x 600 VM is "mapped" onto a display area of 640 x 480... So obviously the bitmap will be scaled down by the same factor and it will appear smaller than 640 x 480.

This appears to be what is happening.

So the second thing I tried was:

1: Calling window.close()
2: Calling window.create() with a new VM which is the correct size (same size as sprite)

Since I was doing this in a loop it creates a flickering effect as the window is destroyed and re-made over and over.

I can sort of resolve this issue by checking to see if the window needs to be created again, rather than doing it each time... However this still causes a flickering when the "user image choice" is changed between different size images.

Is there a solution to this in SFML or would changing the VM without destroying the window require a new patch to SFML?

I assume the videomode has something to do with allocating memory for OpenGL somewhere? Is it possible for me to resize the "opengl surface" while also resizing the window?

Alternatively is this a bug in SFML?

General / Re: How to fix the CPU hidden symbol linker error?
« on: August 04, 2016, 10:50:42 pm »
Okay I've managed to get it to work...

Here's what I did...

Download the SFML source code. Unpack it. Navigate to the root directory of the unzipped source code.

vim ./SFML/src/SFML/Graphics/CMakeLists.txt

Find the line on about line 149 -ish... yours may be different, since this is line 149 AFTER I made changes... which reads:

149 # ImageLoader.cpp must be compiled with the -fno-strict-aliasing
150 # when gcc is used; otherwise saving PNGs may crash in stb_image_write
152     set_source_files_properties(${SRCROOT}/ImageLoader.cpp PROPERTIES COMPILE_FLAGS -fno-strict-aliasing)
153 endif()

Add the following lines BELOW

157     message(WARNING "Applying workaround for https://bugs.launchpad.net/ubuntu/+source/gcc-5/+bug/1568899")
158     list(APPEND GRAPHICS_EXT_LIBS "-lgcc_s -lgcc")
159 endif()

Then cd to root dir of unpacked source

cmake .
make all
sudo make install

General / Re: How to fix the CPU hidden symbol linker error?
« on: August 04, 2016, 10:02:55 pm »
So this patch must be applied to the build of the SFML libraries rather than the build of my own program which *uses* SFML?

I which case, how to I clone and apply the patch?

General / How to fix the CPU hidden symbol linker error?
« on: August 03, 2016, 09:16:12 pm »
I understand there is a well known about error which occurs on ubuntu 16.04 systems when attempting to compile and link a C++ program with the SFML libraries. The linker error is:

hidden symbol `__cpu_model' in /usr/lib/gcc/x86_64-linux-gnu/5/libgcc.a(cpuinfo.o) is referenced by DSO

There is supposed to be a fix, see here: http://web.archive.org/web/20160509014317/https://gitlab.peach-bun.com/pinion/SFML/commit/3383b4a472f0bd16a8161fb8760cd3e6333f1782.patch

However I do not understand what I'm supposed to do using this information.

Currently I compile using the following command:

g++ --std=c++11 -Wall main.cpp -lsfml-graphics -lsfml-window -lsfml-system -o a.out

What should I do to fix this linker error?

PS: Sorry to start a new thread on this - I did bump an older thread but the fix there had something to do with cmake, and I'm not using a cmake system here.

This bug also shows up in g++-4.9 under ubuntu 16.04 by the way

Is there any way to use this workaround with a command line build, eg

g++ main.o -lsfml-graphics -lsfml-window -lsfml-system -o a.out

Can I modify the above command to "make my sfml program link properly with g++5"?

Audio / Re: Continuous Audio for Synthersys
« on: August 02, 2016, 02:47:30 pm »
I've actually discovered that cmake will tell you what things it can't find - if you google them one by one it is fairly easy (for ubuntu at least) to figure out what the package names are. It's a bit of a long process however.

Audio / Re: Continuous Audio for Synthersys
« on: August 02, 2016, 02:42:00 pm »
For example "xlib" according to this page https://ubuntuforums.org/showthread.php?t=1071483 is "xorg-dev" - is that correct?

Audio / Re: Continuous Audio for Synthersys
« on: August 02, 2016, 02:40:24 pm »
Hi Laurent - bumping an old thread here, but I recently re-installed my linux system, and I can't remember what libraries I installed to compile SFML from source. (I think some were installed a long time ago, so I didn't need them previously.)

I thought perhaps it would be useful to other people to have a list of the `apt-get` packages on this page? http://www.sfml-dev.org/tutorials/2.0/compile-with-cmake.php

The names of the libraries required are listed under "Installing dependencies" - but it's not obvious how to install those libs, or what the package names are. (Although I realize this could change from system to system - but at least a list of package names for say, debian, would give a starting point for what to look for.

Audio / Re: Continuous Audio for Synthersys
« on: June 15, 2016, 07:52:03 pm »
"sudo ldconfig" fixed it

Audio / Re: Continuous Audio for Synthersys
« on: June 15, 2016, 04:35:33 pm »
Ah okay, I had missed the fact that I didn't download the "Source Code" version.

I've edited the source code to set a delay of 500 microseconds.

I've built the code using "cmake ." "make all" "sudo make install".

Now getting the runtime error: Cannot open shared object file, for libsfml-graphics.so.2.3

It wasn't obvious to me how to build SFML from source, even when following the info on this page: http://www.sfml-dev.org/tutorials/2.3/compile-with-cmake.php

What did I do wrong?

Audio / Re: Continuous Audio for Synthersys
« on: June 15, 2016, 02:05:00 pm »
Hi Laurent thanks again, that is very interesting to know.

How can I modify the 10 ms update time to something like 1 ms?

Pages: [1] 2