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

Pages: 1 ... 6 7 [8] 9 10 ... 34
106
Graphics / Re: glFlush() error.
« on: September 21, 2020, 11:45:07 am »
I can't say for sure without knowing how your asset manager works. It seems really odd to me that you have to construct a texture from the return value like this

sf::Texture(AssetManager::LoadTexture(path));

when really you want to be able to do something like

sf::Texture& myTex = AssetManager::loadTexture(path);

The SFML Game Development book has a good chapter on resource management, the source of which is also available.

107
Graphics / Re: glFlush() error.
« on: September 20, 2020, 12:19:16 pm »
The error is quite possibly caused by the fact that this line

m_Texture = sf::Texture(AssetManager::LoadTexture(path));


is copying the texture at least once. You should be storing references to your textures in the sprite, not copies.

To start with ensure that your asset manager returns a reference to the held textures, else you'll be getting a copy here (you haven't shared the code for your asset manager). It should look something like
sf::Texture& AssetManager::loadTexture(const std::string& path)

Then use a reference (or a pointer) to sf::Texture in your sprite class and use an initialiser list to  set it up correctly on construction.

As a side note: placing your asset manager as a sprite member is somewhat redundant, you'll be creating a new asset manager with every sprite. The idea of asset managers is that a single instance exists which can share its held resources with multiple sprites (or other types eg sounds etc). I'd suggest refactoring your sprite class to something like:

class Sprite {
public:
        sf::Texture& m_Texture;
        sf::Sprite m_Sprite;

        sf::Vector2f sprite_scale;
        sf::Vector2u original_size;
        sf::Vector2f texture_size;

        Sprite(sf::Texture&,sf::IntRect rect,sf::Vector2f size);    
};

Sprite::Sprite(sf::Texture& texture, sf::IntRect rect, sf::Vector2f size)
    : m_texture(texture),
    m_sprite(texture)
 {
        m_Sprite.setTextureRect(rect);

        original_size = m_Texture.getSize();

        texture_size.x = static_cast<float>(original_size.x);
        texture_size.y = static_cast<float>(original_size.y);

        sprite_scale.x = size.x / texture_size.x;
        sprite_scale.y = size.y / texture_size.y;

        m_Sprite.setScale(sf::Vector2f(sprite_scale.x, sprite_scale.y));
        m_Sprite.setOrigin(sf::Vector2f(original_size.x / 2, original_size.y / 2));

}

 

Note that the texture is passed purely by reference, removing any copy operations (which should hopefully fix your OpenGL error). The sprite and texture members are both initialised with an initialiser list (which you should be using in all of your constructors, btw).To use this sprite class make sure to add a single instance of your asset manager to your game class (or wherever your sprites are created) then pass texture references from it like so:

Sprite spr1(m_assetManager.loadTexture(path), rect, size);
Sprite spr2(m_assetManager.loadTexture(otherPath), otherRect, otherSize);
 

This way your asset manager *owns* a single instance of each texture, references to which are passed out and shared with as many sprites which need them.






Although when all is said an done you can remove the sf::Texture member entirely: the sf::Sprite member will hold a reference for you and all your texture queries can be done through sf::Sprite::getTexture()

108
Graphics / Re: Ragdolls in SFML
« on: September 19, 2020, 11:11:32 pm »
You probably want a physics engine like box2D or chipmunk, your favourite search engine can point you in the right direction to some ragdoll tutorials. Then you can render the output with SFML.

109
Audio / Re: Audio library source available?
« on: September 09, 2020, 07:27:33 pm »
Yes. The source for SFML's audio library is here: https://github.com/SFML/SFML/tree/master/src/SFML/Audio and the source for the OpenAL library is here: https://github.com/kcat/openal-soft

110
Graphics / Re: Saving vertex Array as image
« on: September 02, 2020, 12:48:19 am »
You're doing it pretty much how I would, so if you're getting unusual results it sounds like you're trying to capture the image after calling window.clear() but before window.display(), when the window is in a partially written state. Make sure the window is in a complete state before trying to update a texture from it, or you could potentially use a render texture, by drawing everything you want to capture to that first, once, then using renderTexture.getTexture().copyToImage() to save the file.

111
Graphics / Re: Just cannot get sf::Text to draw without crash
« on: September 02, 2020, 12:38:37 am »
All I can suggest is go back to basics. Check your environment. Make sure you don't have more than one or an old version of sfml installed. Check your headers match the installation of the library and haven't been copied from a different installation. Ensure that debug libraries are linked to the debug builds and release libraries are linked to the release build. If all else fails try a different compiler, like clang or msvc. At least that way you should be able to eliminate some possibilities.

112
Graphics / Re: Just cannot get sf::Text to draw without crash
« on: August 27, 2020, 12:17:40 pm »
Try creating the RenderWindow first before you do anything else. It probably initialises OpenGL stuff required by sf::Font.

113
From what I understand from the nanogui docs what you're doing won't work because your 'screen' variable is just a pointer to the nanogui Screen class. According to the documentation nanogui uses glfw for window creation, and you can get a pointer to the GLFWwindow using the glfwWindow() function in the Screen class. Once you have that you can include glfw3native.h which provides a series of platform specific functions for returning native window handles. On macOS I assume you need glfwGetCocoaWindow ()

114
General / Re: Using opengl
« on: July 14, 2020, 01:56:53 pm »
Sorry for hijacking this thread somewhat :) - Yes the remake still has 3D elements, which are created using standard sf::VertexArrays and some vertex shader trickery, rather than using OpenGL directly (so I guess it depends on your definition of 'pure'). I posted some experiments on twitter in the past, and the source is here if anyone feels like digging around.

EDIT: In fact a better exxample might be this:  ;D

115
General / Re: Using opengl
« on: July 12, 2020, 11:27:17 pm »
Just for clarity: the first example (space racers) actually mixed opengl with SFML. However the remake uses 'pure' SFML :)

As for books, I highly recommend https://www.packtpub.com/game-development/sfml-game-development over any of the other SFML-centric books which I've read (and https://gameprogrammingpatterns.com/contents.html is also worth a read too)

116
Graphics / Re: Enemies path following
« on: July 10, 2020, 08:49:11 pm »
To tell if you've overshot your target position you can take the dot product of your velocity vector with the vector from your position to the target. If both vectors are pointing in the same direction (ie the target is still in front) the dot product will be greater than 0. If it is less than 0 then you have passed the target point, and can update to the next point on your path.

I've created a sample gist, with comments, here: https://gist.github.com/fallahn/8a1dfe8c7a480dbdb9c314c90f8ea919

117
SFML projects / Castle Clamber - Potions Update (1.5) Released!
« on: May 15, 2020, 11:52:47 am »
The latest update for Castle Clamber is now live! Here's a summary of what's included:

New features:
  • New potion power ups with a variety of effects, each with its own advantage or disadvantage in different situations
  • More achievements
  • Updated background artwork
  • Revamped menus with full controller support
  • Analogue controller input now affects player movement
  • Multi-threaded map loader for buttery smooth transitions

Fixes:
  • Removed bbcode from news ticker
  • Prevent showing incorrect level time if no personal best found
  • Fix players sticking to crates when pushing them off the edge of a platform
  • Fix players falling through more than one floor when dropping through a platform and touching a wall
  • Fix being able to infinitely farm the Magic Hat for points
  • Game is paused automatically when opening the steam overlay
  • Game is paused automatically if a controller is disconnected
  • Game starts in full screen mode when running steam in big picture

The most notable addition is the new potions - these drop at random from defeated enemies or broken crates. Collect one by running over it, and it'll cast its spell for a limited time. Each colour potion has a different effect which can help (or hinder!) the player in a given situation. Keep an eye on the duration icon at the bottom of the screen to see when it runs out.



Also in this update is full controller support for Xbox controllers and direct input devices, thanks to the updated navigation control for the menus. Now you can easily enjoy Castle Clamber from the couch in big picture mode in Steam!

118
It's been a LONG time since I worked on this (as I pretty much abandoned it in favour of tmxlite), so my memory is somewhat foggy. I think the quick and dirty solution would be to just increase the border until it covers the viewable area:

    const std::size_t borderSize = 3; //adjust this

    bounds.left -= static_cast<float>(m_tileWidth * borderSize);
    bounds.top -= static_cast<float>(m_tileHeight * borderSize);
    bounds.width += static_cast<float>(m_tileWidth * (2 * borderSize));
    bounds.height += static_cast<float>(m_tileHeight * (2 * borderSize));

 

119
Graphics / Re: Problem Loading Images on App Bundle on Mac os x
« on: April 08, 2020, 10:48:51 am »
The SFML xcode templates folder contains source for doing this in ResourcePath.hpp and ResourcePath.mm https://github.com/SFML/SFML/tree/master/tools/xcode/templates/SFML/SFML%20App.xctemplate

This will return a string containing path that you can prepend to the paths of your images and other resources.

120
Graphics / Re: GL_INVALID_OPERATION messages pop up when loading textures.
« on: February 23, 2020, 05:40:38 pm »
It's probably caused when the textures get copied, which happen at the very least when you push back a texture into the vector, and also internally to the vector every time it resizes (which will get worse the bigger the vector gets). Storing a texture in a vector is also very prone to the white square problem. Consider perhaps using a vector of std::unique_ptr or maybe even some sort of resource holder such as this or this.

Pages: 1 ... 6 7 [8] 9 10 ... 34
anything