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

Pages: [1]
1
General / Re: Cannot seem to set SFML_DIR while using CMake.
« on: July 24, 2018, 10:24:28 pm »
All right, I think I found out thee problem. I actually need to grant read/write permission to the sfml folder. Once I did, SFML_DIR stopped being overwritten. I went overkill and just used chmod 777 -R on my lib and include folders in /usr/local/ (I will take the time to learn how to actually use chmod some day  ;D).

Unfortunately something is still wrong. As you might have noticed, I have placed the sfml libraries in a rather unconventional place (at least, I think), which is a folder called "sfml" inside /usr/local/lib/. Now I have done this to better organize the lib folder, which would be otherwise clogged with .so files all over the place. My reasoning was that by grouping all of sfml's files in a folder, I can just do a "rm -rf sfml" and be done with it if I, for instance, need to install a different version or update the library. I don't actually know if there's a better way to accomplish this (maybe something similar to the "apt-get" packages, where everything is bundled together, but easily updatable/removable using the command line), and so I just went with the most naive solution possible.

I'm telling you all this because cmake works fine as soon as I put all the .so files directly in /usr/local/lib/ instead of /usr/local/lib/sfml. If I don't, I get this:

Code: [Select]
CMake Error at /usr/local/lib/sfml/cmake/SFML/SFMLSharedTargets.cmake:139 (message):
  The imported target "sfml-system" references the file

     "/usr/local/lib/lib/libsfml-system-d.so.2.5.0"

  but this file does not exist.  Possible reasons include:

  * The file was deleted, renamed, or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and contained

     "/usr/local/lib/sfml/cmake/SFML/SFMLSharedTargets.cmake"

  but not all the files it references.

Call Stack (most recent call first):
  /usr/local/lib/sfml/cmake/SFML/SFMLConfig.cmake:116 (include)
  CMakeLists.txt:14 (find_package)


-- Configuring incomplete, errors occurred!

Consequently, if I try to use ccmake, I get a new field named SFML_DOC_DIR, which doesn't seem to change the situation, whatever the value I set it to.

2
General / Re: Cannot seem to set SFML_DIR while using CMake.
« on: July 24, 2018, 09:50:47 pm »
I looked into CMakeCache.txt and found this:

Code: [Select]
//The directory containing a CMake configuration file for SFML.
SFML_DIR:PATH=SFML_DIR-NOTFOUND

This is the whole file for completeness:

Code: [Select]
# This is the CMakeCache file.
# For build in directory: /home/dincio/code/tests/SFMLTest/build
# It was generated by CMake: /usr/local/bin/cmake
# You can edit this file to change values found and used by cmake.
# If you do not want to change any of the values, simply exit the editor.
# If you do want to change a value, simply edit, save, and exit the editor.
# The syntax for the file is as follows:
# KEY:TYPE=VALUE
# KEY is the name of a variable in the cache.
# TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT TYPE!.
# VALUE is the current value for the KEY.

########################
# EXTERNAL cache entries
########################

//Path to a program.
CMAKE_AR:FILEPATH=/usr/bin/ar

//Choose the type of build, options are: None Debug Release RelWithDebInfo
// MinSizeRel ...
CMAKE_BUILD_TYPE:STRING=

//Enable/Disable color output during build.
CMAKE_COLOR_MAKEFILE:BOOL=ON

//CXX compiler
CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/c++

//A wrapper around 'ar' adding the appropriate '--plugin' option
// for the GCC compiler
CMAKE_CXX_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar-7

//A wrapper around 'ranlib' adding the appropriate '--plugin' option
// for the GCC compiler
CMAKE_CXX_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib-7

//Flags used by the CXX compiler during all build types.
CMAKE_CXX_FLAGS:STRING=

//Flags used by the CXX compiler during DEBUG builds.
CMAKE_CXX_FLAGS_DEBUG:STRING=-g

//Flags used by the CXX compiler during MINSIZEREL builds.
CMAKE_CXX_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG

//Flags used by the CXX compiler during RELEASE builds.
CMAKE_CXX_FLAGS_RELEASE:STRING=-O3 -DNDEBUG

//Flags used by the CXX compiler during RELWITHDEBINFO builds.
CMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG

//Flags used by the linker during all build types.
CMAKE_EXE_LINKER_FLAGS:STRING=

//Flags used by the linker during DEBUG builds.
CMAKE_EXE_LINKER_FLAGS_DEBUG:STRING=

//Flags used by the linker during MINSIZEREL builds.
CMAKE_EXE_LINKER_FLAGS_MINSIZEREL:STRING=

//Flags used by the linker during RELEASE builds.
CMAKE_EXE_LINKER_FLAGS_RELEASE:STRING=

//Flags used by the linker during RELWITHDEBINFO builds.
CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO:STRING=

//Enable/Disable output of compile commands during generation.
CMAKE_EXPORT_COMPILE_COMMANDS:BOOL=OFF

//Install path prefix, prepended onto install directories.
CMAKE_INSTALL_PREFIX:PATH=/usr/local

//Path to a program.
CMAKE_LINKER:FILEPATH=/usr/bin/ld

//Path to a program.
CMAKE_MAKE_PROGRAM:FILEPATH=/usr/bin/make

//Flags used by the linker during the creation of modules during
// all build types.
CMAKE_MODULE_LINKER_FLAGS:STRING=

//Flags used by the linker during the creation of modules during
// DEBUG builds.
CMAKE_MODULE_LINKER_FLAGS_DEBUG:STRING=

//Flags used by the linker during the creation of modules during
// MINSIZEREL builds.
CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL:STRING=

//Flags used by the linker during the creation of modules during
// RELEASE builds.
CMAKE_MODULE_LINKER_FLAGS_RELEASE:STRING=

//Flags used by the linker during the creation of modules during
// RELWITHDEBINFO builds.
CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO:STRING=

//Path to a program.
CMAKE_NM:FILEPATH=/usr/bin/nm

//Path to a program.
CMAKE_OBJCOPY:FILEPATH=/usr/bin/objcopy

//Path to a program.
CMAKE_OBJDUMP:FILEPATH=/usr/bin/objdump

//Value Computed by CMake
CMAKE_PROJECT_NAME:STATIC=sfml_test

//Value Computed by CMake
CMAKE_PROJECT_VERSION:STATIC=1.0.0

//Value Computed by CMake
CMAKE_PROJECT_VERSION_MAJOR:STATIC=1

//Value Computed by CMake
CMAKE_PROJECT_VERSION_MINOR:STATIC=0

//Value Computed by CMake
CMAKE_PROJECT_VERSION_PATCH:STATIC=0

//Value Computed by CMake
CMAKE_PROJECT_VERSION_TWEAK:STATIC=

//Path to a program.
CMAKE_RANLIB:FILEPATH=/usr/bin/ranlib

//Flags used by the linker during the creation of shared libraries
// during all build types.
CMAKE_SHARED_LINKER_FLAGS:STRING=

//Flags used by the linker during the creation of shared libraries
// during DEBUG builds.
CMAKE_SHARED_LINKER_FLAGS_DEBUG:STRING=

//Flags used by the linker during the creation of shared libraries
// during MINSIZEREL builds.
CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL:STRING=

//Flags used by the linker during the creation of shared libraries
// during RELEASE builds.
CMAKE_SHARED_LINKER_FLAGS_RELEASE:STRING=

//Flags used by the linker during the creation of shared libraries
// during RELWITHDEBINFO builds.
CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO:STRING=

//If set, runtime paths are not added when installing shared libraries,
// but are added when building.
CMAKE_SKIP_INSTALL_RPATH:BOOL=NO

//If set, runtime paths are not added when using shared libraries.
CMAKE_SKIP_RPATH:BOOL=NO

//Flags used by the linker during the creation of static libraries
// during all build types.
CMAKE_STATIC_LINKER_FLAGS:STRING=

//Flags used by the linker during the creation of static libraries
// during DEBUG builds.
CMAKE_STATIC_LINKER_FLAGS_DEBUG:STRING=

//Flags used by the linker during the creation of static libraries
// during MINSIZEREL builds.
CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL:STRING=

//Flags used by the linker during the creation of static libraries
// during RELEASE builds.
CMAKE_STATIC_LINKER_FLAGS_RELEASE:STRING=

//Flags used by the linker during the creation of static libraries
// during RELWITHDEBINFO builds.
CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO:STRING=

//Path to a program.
CMAKE_STRIP:FILEPATH=/usr/bin/strip

//If this value is on, makefiles will be generated without the
// .SILENT directive, and all commands will be echoed to the console
// during the make.  This is useful for debugging only. With Visual
// Studio IDE projects all commands are done without /nologo.
CMAKE_VERBOSE_MAKEFILE:BOOL=FALSE

//The directory containing a CMake configuration file for SFML.
SFML_DIR:PATH=SFML_DIR-NOTFOUND

//Value Computed by CMake
sfml_test_BINARY_DIR:STATIC=/home/dincio/code/tests/SFMLTest/build

//Value Computed by CMake
sfml_test_SOURCE_DIR:STATIC=/home/dincio/code/tests/SFMLTest


########################
# INTERNAL cache entries
########################

//ADVANCED property for variable: CMAKE_AR
CMAKE_AR-ADVANCED:INTERNAL=1
//This is the directory where this CMakeCache.txt was created
CMAKE_CACHEFILE_DIR:INTERNAL=/home/dincio/code/tests/SFMLTest/build
//Major version of cmake used to create the current loaded cache
CMAKE_CACHE_MAJOR_VERSION:INTERNAL=3
//Minor version of cmake used to create the current loaded cache
CMAKE_CACHE_MINOR_VERSION:INTERNAL=12
//Patch version of cmake used to create the current loaded cache
CMAKE_CACHE_PATCH_VERSION:INTERNAL=20180716
//ADVANCED property for variable: CMAKE_COLOR_MAKEFILE
CMAKE_COLOR_MAKEFILE-ADVANCED:INTERNAL=1
//Path to CMake executable.
CMAKE_COMMAND:INTERNAL=/usr/local/bin/cmake
//Path to cpack program executable.
CMAKE_CPACK_COMMAND:INTERNAL=/usr/local/bin/cpack
//Path to ctest program executable.
CMAKE_CTEST_COMMAND:INTERNAL=/usr/local/bin/ctest
//ADVANCED property for variable: CMAKE_CXX_COMPILER
CMAKE_CXX_COMPILER-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_CXX_COMPILER_AR
CMAKE_CXX_COMPILER_AR-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_CXX_COMPILER_RANLIB
CMAKE_CXX_COMPILER_RANLIB-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_DEBUG-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELEASE-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
//Path to cache edit program executable.
CMAKE_EDIT_COMMAND:INTERNAL=/usr/local/bin/ccmake
//Executable file format
CMAKE_EXECUTABLE_FORMAT:INTERNAL=ELF
//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS
CMAKE_EXE_LINKER_FLAGS-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_DEBUG
CMAKE_EXE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_MINSIZEREL
CMAKE_EXE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELEASE
CMAKE_EXE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO
CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_EXPORT_COMPILE_COMMANDS
CMAKE_EXPORT_COMPILE_COMMANDS-ADVANCED:INTERNAL=1
//Name of external makefile project generator.
CMAKE_EXTRA_GENERATOR:INTERNAL=
//Name of generator.
CMAKE_GENERATOR:INTERNAL=Unix Makefiles
//Generator instance identifier.
CMAKE_GENERATOR_INSTANCE:INTERNAL=
//Name of generator platform.
CMAKE_GENERATOR_PLATFORM:INTERNAL=
//Name of generator toolset.
CMAKE_GENERATOR_TOOLSET:INTERNAL=
//Source directory with the top level CMakeLists.txt file for this
// project
CMAKE_HOME_DIRECTORY:INTERNAL=/home/dincio/code/tests/SFMLTest
//Install .so files without execute permission.
CMAKE_INSTALL_SO_NO_EXE:INTERNAL=1
//ADVANCED property for variable: CMAKE_LINKER
CMAKE_LINKER-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_MAKE_PROGRAM
CMAKE_MAKE_PROGRAM-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS
CMAKE_MODULE_LINKER_FLAGS-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_DEBUG
CMAKE_MODULE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL
CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELEASE
CMAKE_MODULE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO
CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_NM
CMAKE_NM-ADVANCED:INTERNAL=1
//number of local generators
CMAKE_NUMBER_OF_MAKEFILES:INTERNAL=1
//ADVANCED property for variable: CMAKE_OBJCOPY
CMAKE_OBJCOPY-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_OBJDUMP
CMAKE_OBJDUMP-ADVANCED:INTERNAL=1
//Platform information initialized
CMAKE_PLATFORM_INFO_INITIALIZED:INTERNAL=1
//ADVANCED property for variable: CMAKE_RANLIB
CMAKE_RANLIB-ADVANCED:INTERNAL=1
//Path to CMake installation.
CMAKE_ROOT:INTERNAL=/usr/local/share/cmake-3.12
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS
CMAKE_SHARED_LINKER_FLAGS-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_DEBUG
CMAKE_SHARED_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL
CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELEASE
CMAKE_SHARED_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO
CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_SKIP_INSTALL_RPATH
CMAKE_SKIP_INSTALL_RPATH-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_SKIP_RPATH
CMAKE_SKIP_RPATH-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS
CMAKE_STATIC_LINKER_FLAGS-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_DEBUG
CMAKE_STATIC_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL
CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELEASE
CMAKE_STATIC_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO
CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_STRIP
CMAKE_STRIP-ADVANCED:INTERNAL=1
//uname command
CMAKE_UNAME:INTERNAL=/bin/uname
//ADVANCED property for variable: CMAKE_VERBOSE_MAKEFILE
CMAKE_VERBOSE_MAKEFILE-ADVANCED:INTERNAL=1
//MODIFIED property for variable: SFML_DIR
SFML_DIR-MODIFIED:INTERNAL=ON

If I try to replace it with the path and then call cmake again it just resets to that thing again... [SFML_DIR-NOTFOUND]. The same thing happens when I use ccmake and set it there.

3
General / Re: Cannot seem to set SFML_DIR while using CMake.
« on: July 24, 2018, 07:30:19 pm »
Yes.

4
General / Cannot seem to set SFML_DIR while using CMake.
« on: July 24, 2018, 05:27:36 pm »
I'm trying to wrap my head around how the new modern CMake system works. For some reason, though, I can't seem to be able to set SFML_DIR. That is: I set it using the -D flag when calling cmake, but the project doesn't really seem to care much...

Project file structure:
Code: [Select]
~/code/tests/SFMLTest
    src
        main.cpp
    build
        <I call cmake from here>
    CMakeLists.txt

CMakeLists.txt
Code: [Select]
cmake_minimum_required(VERSION 3.5)
project(sfml_test VERSION 1.0.0 LANGUAGES CXX)

add_executable(sfml_test src/main.cpp)

target_compile_options(sfml_test PRIVATE -Werror)

target_compile_features(sfml_test PRIVATE cxx_std_17)

find_package(SFML 2.5 COMPONENTS graphics audio REQUIRED)

target_link_libraries(sfml_test
PUBLIC
sfml-graphics sfml-audio
)

CMake command:
Code: [Select]
cmake -DSFML_DIR="/usr/local/lib/sfml/cmake/SFML" ..

CMake command output:
Code: [Select]
CMake Error at CMakeLists.txt:14 (find_package):
  By not providing "FindSFML.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "SFML", but
  CMake did not find one.

  Could not find a package configuration file provided by "SFML" (requested
  version 2.5) with any of the following names:

    SFMLConfig.cmake
    sfml-config.cmake

  Add the installation prefix of "SFML" to CMAKE_PREFIX_PATH or set
  "SFML_DIR" to a directory containing one of the above files.  If "SFML"
  provides a separate development package or SDK, be sure it has been
  installed.


I have downloaded the sfml binaries for linux (as I am running Ubuntu), and moved the libs to /usr/local/lib/sfml/ and the headers to /usr/local/include/SFML.

Thanks in advance for any response :) know that I am by no means a CMake expert (even though I'm trying really hard to become one).

5
Graphics / Re: Rotation going nuts
« on: July 08, 2017, 12:27:52 am »
Oh yes sorry I haven't noticed that... Still, it would have become a problem later, since I only positioned one entity at position (0, 0) for testing purposes, and so the position did not interfere with the origin. So the problem persists... for some reason it only comes up when I rotate and translate at the same time... maybe that has something to do with it.

6
Graphics / Re: Rotation going nuts
« on: July 07, 2017, 11:26:04 pm »
mHitBox is a vector containing the size the texture used by the entity (it is what happens by default om the MovingEntity constructor).

7
Graphics / Re: Rotation going nuts
« on: July 07, 2017, 11:24:48 pm »
Yes of course, here:

Ferri(float maxSpeed, float accelerationIntensity):
   MovingEntity(gTextureProvider.getMedia("ferri")),
   mMaxSpeed(maxSpeed),
   mAccelerationIntensity(accelerationIntensity) {
   setOrigin(mHitBox.x / 2.f + getPosition().x, mHitBox.y / 2.f + getPosition().y);
}

8
Graphics / Rotation going nuts
« on: July 07, 2017, 09:09:42 pm »
Hello again.

I'm trying to make a simple Entity system for a 2D bullet hell game. Each frame, I calculate the velocity and position of each entity and render it on the screen using a temporary sf::RectangleShape. All was going well untill I attempted to make an entity rotate. The first thing that came to mind was to pass the temporary
sf::RectangleShape to the draw function of the current render target (I'm refering to the parameter of the sf::Drawable::draw method, inherited by Entity) along with the transform of the entity (which of course also inherits from sf::Transformable) through the render states, and it all worked as expected... until I tyed to rotate an entity while it was moving. This made the entity suddenly change position by a drastic offset (often going offscreen) without any apparent reason. Initially, I thought that this had to do with the origin of the entity, but even by moving the origin every frame along with the position, the problem persisted.

Here is the draw function:
void Entity::draw(sf::RenderTarget& target, sf::RenderStates states) const {
    sf::RectangleShape rectangle(mHitBox);
    rectangle.setTexture(mTexture);

    states.transform = getTransform();
    target.draw(rectangle, states);
}

And here is the function where movement takes place:
void MovingEntity::handleLogic(sf::RenderWindow& window, const sf::Time& timeElapsed) {
    //accelerate entity
    mVelocity += mAcceleration * timeElapsed.asSeconds();

    //simulate next position
    auto displacement = mVelocity * timeElapsed.asSeconds();
    auto futurePos = getPosition() + displacement;

    //check border collisions
    auto borders = sf::Vector2f(window.getSize()) - mHitBox;
    if(futurePos.x < 0 || futurePos.x > borders.x) {
        mVelocity.x = 0;
        mAcceleration.x = 0;
        if(futurePos.x < 0)
            futurePos.x = 0;
        else if(futurePos.x > borders.x)
            futurePos.x = borders.x;
    }
    if(futurePos.y < 0 || futurePos.y > borders.y) {
        mVelocity.y = 0;
        mAcceleration.y = 0;
        if(futurePos.y < 0)
            futurePos.y = 0;
        else if(futurePos.y > borders.y)
            futurePos.y = borders.y;
    }

    //move entity
    move(displacement);
}

And here's where I do the rotation:
void Ferri::vHandleLogic(sf::RenderWindow& window, const sf::Time& timeElapsed) {
    //move Ferri
    if(sf::Keyboard::isKeyPressed(sf::Keyboard::W)) {
        mAcceleration.x = 0;
        mAcceleration.y = -1;
    }
    else if(sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
        mAcceleration.x = 1;
        mAcceleration.y = 0;
    }
    else if(sf::Keyboard::isKeyPressed(sf::Keyboard::S)) {
        mAcceleration.x = 0;
        mAcceleration.y = 1;
    }
    else if(sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
        mAcceleration.x = -1;
        mAcceleration.y = 0;
    }
    else if(sf::Keyboard::isKeyPressed(sf::Keyboard::R)) {
        rotate(1);
    }
    else {
        mAcceleration.x = 0;
        mAcceleration.y = 0;
    }
    mAcceleration *= mAccelerationIntensity;

    //don't get over the limit velocity
    float speed = std::sqrt(std::pow(mVelocity.x, 2) + std::pow(mVelocity.y, 2));
    if(speed >= mMaxSpeed) {
        mVelocity.x = mVelocity.x / speed * mMaxSpeed;
        mVelocity.y = mVelocity.y / speed * mMaxSpeed;
    }
}

That's all. I really hope I'm not missing a stupid bug or something...

9
Graphics / Apply a View to a Transformable
« on: March 03, 2017, 11:23:56 pm »
Hello  ;D

I'm coding up a GUI library for sfml and I'm trying to make it work along with views and viewports.

Basically, I want an object of type Interface, which inherits from Transformable, to accept a view and then draw itself relative to that view.

Unfortunately, I can't seem to find a way to implement all of this... I've tried getting the transformation of the view with getTransform() and apply it to the transformation element of states before drawing, but it didn't work as I expected it too...

Thanks in advance for any help.

10
Ok I've been playing around some more with the code and the bug jst seems to be conncted to vertex arrays and zooming in general. Every time I zoom a vertex array by modifying the window dimensions (even if I only use 1 with the default view and viewport), weird lines appear all over... this happens only at particular levels of zooming.

11
Sorry for the long wait, but I couldn't work on the project for some time and kind of forgot about it... ayways, I have the fallowing video devices:

 -) Intel(R) HD Graphics 530
 -) NVIDIA GeForce GTX 950M

Also, as I kept working on the project, I unfortunately encountered some other bugs related to vertex arrays. For instance, when I draw a lot of them (like three layers, one on top of the other), black lines come out of no where (look at attachment for details).

I also found out that the bug is connected to using the viewport, since the lines only show themselves when I set the viewport of the currect view to be half the size of the screen. Strangely, though, they also show up when the viewport is of the same size as that of the window but only if I render two layers of vertex arrays (I basically draw two of them, one on top of the other)... I have to admit that I am rather confused  ;D

The same bug also seems to be connected to the texture rects of the vertex arrays, as the lines are really just a piece of the texture which is near them in the tile sheet I'm using. Hope this helps diagnosing a solution...

thanks for the reply.

12
I found out that the problem was in the way I drew the area tiles. In a more general way: whenever I use a "double layer" vertex array (in other words, a vertex array that consists of two layers of quads, one rendered on top of the other) things start to break and lag. Still though, I can't figure why this happens or if this is even supposed to be a sfml bug.

P.S. I know nothing of OpenGL and of how vertex arrays work under the hood (apart from seeing the sfml github repository).

13
So I made this gamish thing that uses a quickly-and-poorly made custom GUI library to manage the player interface. This thing currently consists in the drawing of a tile map, which is implemented using a sf::VertexArray of quads (basically a copy of the tutorial one...) and a TextBox object, also implemented using a vertex array of quads (since the tutorial made it look so efficent I figured I'd just spam it everywhere in my design :P). The problem is that the two don't seem to get along nicely... when I try to draw them at the same time, the game crashes. This is what the debugger says about the crash (I'm using CodeBlocks with a recent version of mingw):


#0 0x53eb9f83   ig9icd32!RegisterProcTableCallback() (C:\WINDOWS\SysWOW64\ig9icd32.dll:??)
#1 0x53fea39c   ig9icd32!RegisterProcTableCallback() (C:\WINDOWS\SysWOW64\ig9icd32.dll:??)
#2 0x5409c9d4   ig9icd32!RegisterProcTableCallback() (C:\WINDOWS\SysWOW64\ig9icd32.dll:??)
#3 0x5409c642   ig9icd32!RegisterProcTableCallback() (C:\WINDOWS\SysWOW64\ig9icd32.dll:??)
#4 0x5409c3e2   ig9icd32!RegisterProcTableCallback() (C:\WINDOWS\SysWOW64\ig9icd32.dll:??)
#5 0x53ebea1a   ig9icd32!RegisterProcTableCallback() (C:\WINDOWS\SysWOW64\ig9icd32.dll:??)
#6 0x53ebeadf   ig9icd32!RegisterProcTableCallback() (C:\WINDOWS\SysWOW64\ig9icd32.dll:??)
#7 0x54208ad3   ig9icd32!RegisterProcTableCallback() (C:\WINDOWS\SysWOW64\ig9icd32.dll:??)
#8 0x66b9c466   sf::RenderTarget::draw(sf::Vertex const*, unsigned int, sf::PrimitiveType, sf::RenderStates const&) () (C:\Code\C\sfml\Wars\sfml-graphics-2.dll:??)
#9 0x66baa258   sf::VertexArray::draw(sf::RenderTarget&, sf::RenderStates) const() (C:\Code\C\sfml\Wars\sfml-graphics-2.dll:??)
#10 0x66b9b87c   sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&) () (C:\Code\C\sfml\Wars\sfml-graphics-2.dll:??)
#11 0x403a75   _fu21___ZSt4cout() (C:\Code\C\sfml\Wars\src\interface\TextBox.cpp:101)

And here's the part of the code where the game breaks:
//draw
void TextBox::parentDraw(sf::RenderTarget& target, sf::RenderStates states) const {
    //if no font is set, abort
    assert(mTextInfo.font);
    //update vertices if necessary
    if(mNeedToUpdateVertices){
        std::cout << "text: " << mTextInfo.text << "\n\n";
        mNeedToUpdateVertices = false;
        //calculate new vertex array size needed
        //(updated constantly when special (not printable) characters
        // are handled and used at the end to resize the vertex array)
        size_t verticesNum = 0;
        for(const auto& ele : mTextInfo.text) verticesNum++;
        mVertices.resize(verticesNum * 4);
        //adjust vertex array
        const auto& newText = mTextInfo.text;
        unsigned int lineOffset = getBounds().left;
        unsigned int verticalOffset = getBounds().top + mTextInfo.font->getLineSpacing(mTextInfo.charSize);
        for(size_t j = 0, vj = 0; j < newText.size(); j++, vj++){
            //handle special characters
            if(newText[j] == '\n'){
                verticesNum--;
                vj--;
                lineOffset = getBounds().left;
                verticalOffset += mTextInfo.font->getLineSpacing(mTextInfo.charSize);
            }
            //handle letters (non-handled characters are rendered as letters)
            else {
                //handle space
                if(newText[j] == ' '){
                    //generate a new line
                    auto futLineOffset = lineOffset;
                    auto k = j + 1;
                    for(; newText[k] != ' ' && newText[k] != '\n' && k < newText.size(); k++){
                        futLineOffset += mTextInfo.font->getGlyph(newText[k], mTextInfo.charSize, false).advance;
                    }
                    if(futLineOffset > getBounds().width){
                        verticesNum--;
                        j++;
                        lineOffset = getBounds().left;
                        verticalOffset += mTextInfo.font->getLineSpacing(mTextInfo.charSize);
                    }
                }
                //change vertex quad associated with letter
                auto glyph = mTextInfo.font->getGlyph(newText[j], mTextInfo.charSize, false);
                auto bRect = glyph.bounds;
                float kerning = 0;
                //handle kerning
                if(j < newText.size() - 1)
                    kerning = mTextInfo.font->getKerning(newText[j], newText[j+1], mTextInfo.charSize);
                //set glyph bounds within text box
                bRect.left = lineOffset + kerning;
                lineOffset += glyph.advance + kerning;
                bRect.top += verticalOffset;
                //get texture rect
                const auto& tRect = glyph.textureRect;
                //convert glyph into vertex quad
                mVertices[vj*4]      = sf::Vertex({bRect.left, bRect.top},                               {tRect.left, tRect.top});
                mVertices[vj*4 + 1]  = sf::Vertex({bRect.left + bRect.width, bRect.top},                 {tRect.left + tRect.width, tRect.top});
                mVertices[vj*4 + 2]  = sf::Vertex({bRect.left + bRect.width, bRect.top + bRect.height},  {tRect.left + tRect.width, tRect.top + tRect.height});
                mVertices[vj*4 + 3]  = sf::Vertex({bRect.left, bRect.top + bRect.height},                {tRect.left, tRect.top + tRect.height});
            }
            //handle horizontal overflow
            if(lineOffset >= getBounds().width){
                lineOffset = getBounds().left;
                verticalOffset += mTextInfo.font->getLineSpacing(mTextInfo.charSize);
            }
        }
        //resize vertex array if necessary (special characters were encountered)
        if(mVertices.getVertexCount() != verticesNum * 4)
            mVertices.resize(verticesNum * 4);
    }
    //set transform
    states.transform *= getTransform();
    //set texture
    states.texture = &(mTextInfo.font->getTexture(mTextInfo.charSize));
    //draw vertex array to render target
    target.draw(mVertices, states);
}
 

Again, the problem only comes up when I draw a TextBox object (or really anything else - even using an object from a less-poorly made GUI library, such as TGUI, causes a segmentation fault) in conjunction with the tilemap; which is implemented as such (I'll only put the draw method here, but I'm willing to post more code on request):

void World::draw(sf::RenderTarget& target, sf::RenderStates states) const {
    if(mNeedToUpdateVertices){
        //update vertices if needed
        for(int x = 0; x < mWidth; x++){
            for(int y = 0; y < mHeight; y++){
                if(mNeedToUpdateAllVertices || mPositionsToUpdate[y * mWidth + x]){
                    //determine which tile to show
                    auto tile = getTile({x, y});
                    sf::IntRect groundTR;
                    if(tile.up == UpTile::Air){
                        groundTR = sf::IntRect(gTerrainTileModels[tile.terrain].info.textureRect);
                    }
                    else{
                        groundTR = sf::IntRect(gUpTileModels[tile.up].info.textureRect);
                    }
                    //add up/terrain vertices
                    updateQuadAtPosition(sf::Vector2i(x, y), groundTR, false);
                    //add area vertices
                    updateQuadAtPosition(sf::Vector2i(x, y), gUpTileModels[tile.area].info.textureRect, true);
                }
            }
        }
        //render entities
        for(const auto& entity : mEntities){
            const auto& pos = entity->getPosition();
            if(mNeedToUpdateAllVertices || mPositionsToUpdate[pos.y * mWidth + pos.x])
                updateQuadAtPosition(pos, entity->getTextureRect(), false);
        }
    }
    //apply transform
    states.transform = getTransform();
    //set texture
    states.texture = mTileSheetTexture;
    //reset positions to update
    mNeedToUpdateVertices = false;
    mNeedToUpdateAllVertices = false;
    for(auto q = mPositionsToUpdate.begin(); q != mPositionsToUpdate.end(); ++q)
        *q = false;
    //render vertices
    target.draw(mVertices, states);
}

void World::updateQuadAtPosition(const sf::Vector2i& pos, const sf::IntRect& textureRect, bool isArea) const {
    auto index = (pos.y * mWidth + pos.x) * 8;
    if(isArea) index += 4;
    sf::FloatRect rr = {pos.x * World::TILE_WIDTH,
                        pos.y * World::TILE_HEIGHT,
                        World::TILE_WIDTH,
                        World::TILE_HEIGHT};
    const auto& tr = textureRect;
    //add up/terrain vertices
    mVertices[index]     = sf::Vertex({rr.left, rr.top},                        {tr.left, tr.top});
    mVertices[index + 1] = sf::Vertex({rr.left + rr.width, rr.top},             {tr.left + tr.width, tr.top});
    mVertices[index + 2] = sf::Vertex({rr.left + rr.width, rr.top + rr.height}, {tr.left + tr.width, tr.top + tr.height});
    mVertices[index + 3] = sf::Vertex({rr.left, rr.top + rr.height},            {tr.left, tr.top + tr.height});
}
 

And here's where I draw the two:
void MatchHandler::handleDrawing()
{
    //draw player view of world
    auto standardView = mWindow->getDefaultView();
    auto playerView = mPlayer->calcView();
    playerView.setViewport(sf::FloatRect(0.f, 0.f, 0.5, 1.f));
    mWindow->setView(playerView);
    mWindow->draw(*mWorld);
    //draw player interface
    mWindow->setView(standardView);
    mWindow->draw(*(mPlayerInterface->getChild("message_box")));
}
 

I know this is a long question, but I really tried everything before posting. Also, I repeat, the problem is not specific to this instance of it, and happens even when I use other GUI libraries or just anything that is implemented using sf::VertexArray.

Thaks in advance for any response  ;D.

Pages: [1]