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

Pages: [1]
1
Feature requests / Vertex Attributes on shaders
« on: March 03, 2012, 07:59:18 am »
Quote from: "Laurent"

I know that it can be frustrating, but I don't want to go in this direction.


Ah it's not frustrating, it's nice to have an answer though. Thanks for taking the time to respond =)

2
Feature requests / Vertex Attributes on shaders
« on: March 02, 2012, 06:46:29 am »
Hi all,

I've recently decided to start giving back to this project, something that always bothered me was the lack of support of vertex attributes within ones shaders. With raw opengl, it is an ugly interface to deal with.

I decided my way of contributing would be to come up with an implementation of vertex attributes. However, I do not know everything there is when it comes to this, so I'm asking for some help with design considerations (the hardest part, I know).

Essentially, I must start out by stating I believe a clean separation of Vertex and Fragment shaders into separate files would be beneficial, but ignoring that I would add the following method with several overrides to the shader class:

Code: [Select]
void Shader::SetVertexAttribute(const std::string& name, const std::vector<float>& v);
bool Shader::SetVertexAttribute(const std::string& name, const std::vector<int>& v);
bool Shader::SetVertexAttribute(const std::string& name, const std::vector<Vector2f>& v);
bool Shader::SetVertexAttribute(const std::string& name, const std::vector<Vector3f>& v);


etc...

Rationale, it should be up to the user to get their data into a coherent format, as supporting something such as

Code: [Select]
bool Shader::SetVertexAttribute(const std::string& name, void *data);

would be asking for bugs.

I spent awhile going through a couple different implementation strategies, and what I came up with to be the cleanest/most straight-forward implementation would be to give sf::Shader a private collection of VertexAttribute objects.

When the "user" calls SetVertexAttribute(...) on a "vertex shader" internally the shader would look in a lookup table (ie: map/unordered_map<string, VertexAttribute>) if it already has an object with that name.

If the shader did not have a vertex attribute associated with the provided name, it would construct a new VertexAttribute with the data provided by the user.

The first question I have, with the above (very possibly naive) implementation would be, what does the shader do if it already contains an entry with the "name" provided by the user in the SetVertexAttribute() method call? The best solution I came up with was to have the SetVertexAttribute() method return false, printing to standard error. That seems to be the only solution...

Second consideration, the user passes their data by reference. Does this mean that the VertexAttribute object does not need to keep a copy of the users data? The reason I ask is, suppose for whatever reason, internally, we want to offloadthe user's data (vertex attribute data) back to the CPU, temporarily, it would be easy to do if our VertexAttribute class kept a copy of the user's data.

Third consideration, we assume the user wants the attribute activated immediately, however is it the best course of action to immediatly call
Code: [Select]
glBufferData(...) // copying their data to the GPU or to perhaps queue allocation the memory until another time?

I really hope to go somewhere with this, what do you guys think? Am I totally off-base with this? Does it seem doable? Do you think having a method "SetVertexAttribute()" on a non-specific shader-type is ridiculous?? (does shader need to be split into vertex and fragment seperately) ??. I would love any feedback I can get, I would really like to be able to give back to this project, I use sfml sometimes just to get an opengl window and do the rest of the code with raw opengl (3d stuff). However I really like the abstraction sf::Shader promises, it would be really useful someday to get it up the point of being able to use on any type of shader, but for now I'd love to at least begin working towards getting vertex attributes accessible through sf::Shader.

Laurent thank you for working on this project, please let me know if this is a terrible idea.

3
Window / read input from file
« on: September 26, 2011, 04:06:41 am »
Hey there,

I was wondering if there was a way to convert all keyboard/button names from string to their enum.

I read in the tutorial that you can do a straight char representation -> sf::keyboard::key enum for characters/numbers, but what about things such as "Back."

In my situation, I'm reading key bindings from a file, such as this:

Code: [Select]
<?xml version="1.0" encoding="UTF-8" ?>
<Root>
  <Keyboard>
    <a action="MoveLeft"></a>
    <s action="MoveDown"></s>
    <d action="MoveRight"></d>
    <w action="MoveUp"></w>
    <F12 action="whatevs"></F12>
  </Keyboard>
</Root>


I use xml to parse this the way I want it, but everything comes out as a string. I need to do a conversion from, say std::string("f12") -> sf::keyboard::F12. I didn't see anything, and the only constant-time way I can think to solve this is to create an std::map with all the key/values defined within it (the map of course allowing constant time lookup). This would allow me to do something such as return _myMap.at("F12") and have a sf::keyboard::key returned, or something similar.

This would however require a map with every keyboard / mouse "button/click" in it. I don't mind doing this, if there is no other way I have missed.

Thanks!!

4
Graphics / sf::shape placeholder point
« on: September 23, 2011, 01:32:56 am »
Yup. Thanks for the clarification. They were indeed loading out of order, thank you for the explanation.

5
Graphics / sf::shape placeholder point
« on: September 22, 2011, 10:11:49 pm »
Hi,

I am curious if I am missing something obvious.

Sf::Shape when constructed has the default "point" added to it at 0,0.

I'm reading a bunch of points out of a file, and constructing the corresponding shape based on the number of points read from the file.

When I read 4 points (which should be a rect), then go to render it, there are 5 points total.

Here's the code:

Code: [Select]
void SafeSetProperties(std::map<std::string, boost::variant<int, float, std::string, sf::Vector2f> > properties)
{
// constant string values for the function
static const std::string verticeCount = "VerticeCount";
static const std::string vertices = "Vertices";

// read in all of the vertices
if(properties.count(verticeCount) > 0)
{
const int numVertices = boost::get<int>(properties[verticeCount]);
for(auto i = 0; i < numVertices; ++i) {
std::ostringstream oss;
oss << vertices << i;
_polygonShape.AddPoint(boost::get<sf::Vector2f>(properties[oss.str()]));

}

}


Here's the resulting image (ignore the red triangle, different shape):


I'm aware of the static function sf::Shape::Rectangle, but this means I need to add a switch based on the number of points (that would make the code less maintainable, more complex, however you want to say it).

My question, why is the default placeholder point of (0,0) added to all shape's? Is there a reason why there is no way to override this behavior?

I could dive into the source code, remove the point being added in the constructor, but is that the only way?

I would like not to have to modify my sfml code (if I ever distribute, I wouldn't want a custom version of SFML).

Opening Shape.cpp we can see where this happens

Code: [Select]
////////////////////////////////////////////////////////////
Shape::Shape() :
myOutline         (0.f),
myIsFillEnabled   (true),
myIsOutlineEnabled(true),
myIsCompiled      (false)
{
    // Put a placeholder for the center of the shape
    myPoints.push_back(Point());
}

6
Graphics / Standalone header Graphics/Sprite.hpp doesn't compile
« on: September 17, 2011, 09:46:16 am »
I figured it out, at one point I was trying to return a sf::Sprite from a function, the error probably coming from the fact there is no copy constructor defined?

7
Graphics / Standalone header Graphics/Sprite.hpp doesn't compile
« on: September 16, 2011, 04:03:11 am »
I can't seem to get this fix to work.

In sprite.hpp I defined the destructor (right below the constructor) public, ie:

Code: [Select]
class SFML_API Sprite : public Drawable
{
public :

    ////////////////////////////////////////////////////////////
    /// \brief Default constructor
    ///
    /// Creates an empty sprite with no source texture.
    ///
    ////////////////////////////////////////////////////////////
    Sprite();
    ~Sprite();

    ////////////////////////////////////////////////////////////
    /// \brief Construct the sprite from a source texture
    ///
    /// \see SetTexture
    ///
    ////////////////////////////////////////////////////////////
    explicit Sprite(const Texture& texture);


In Sprite.cpp, I defined the destructor,

Code: [Select]
////////////////////////////////////////////////////////////
Sprite::Sprite(const Texture& texture) :
Drawable    (),
mySubRect   (0, 0, 1, 1),
myIsFlippedX(false),
myIsFlippedY(false)
{
    SetTexture(texture);
}

Sprite::~Sprite()
{

}


After which I rebuilt the SFML project, copied the new DLL's to my project's BIN directory (where the dll's were previously) and rebuild (vs 2010). I still get the error,

Code: [Select]

c:\sfml 2.0\include\sfml\system\resourceptr.inl(51): error C2027: use of undefined type 'sf::Texture'
3>          c:\sfml 2.0\include\sfml\graphics\renderer.hpp(42) : see declaration of 'sf::Texture'
3>          c:\sfml 2.0\include\sfml\system\resourceptr.inl(47) : while compiling class template member function 'sf::ResourcePtr<T>::ResourcePtr(const sf::ResourcePtr<T> &)'
3>          with
3>          [
3>              T=sf::Texture
3>          ]
3>          c:\sfml 2.0\include\sfml\graphics\sprite.hpp(208) : see reference to class template instantiation 'sf::ResourcePtr<T>' being compiled
3>          with
3>          [
3>              T=sf::Texture
3>          ]
3>c:\sfml 2.0\include\sfml\system\resourceptr.inl(51): error C2227: left of '->Connect' must point to class/struct/union/generic type
3>c:\sfml 2.0\include\sfml\system\resourceptr.inl(60): error C2027: use of undefined type 'sf::Texture'
3>          c:\sfml 2.0\include\sfml\graphics\renderer.hpp(42) : see declaration of 'sf::Texture'
3>          c:\sfml 2.0\include\sfml\system\resourceptr.inl(58) : while compiling class template member function 'sf::ResourcePtr<T>::~ResourcePtr(void)'
3>          with
3>          [
3>              T=sf::Texture
3>          ]
3>c:\sfml 2.0\include\sfml\system\resourceptr.inl(60): error C2227: left of '->Disconnect' must point to class/struct/union/generic type
3>c:\sfml 2.0\include\sfml\system\resourceptr.inl(69): error C2027: use of undefined type 'sf::Texture'
3>          c:\sfml 2.0\include\sfml\graphics\renderer.hpp(42) : see declaration of 'sf::Texture'
3>          c:\sfml 2.0\include\sfml\system\resourceptr.inl(67) : while compiling class template member function 'sf::ResourcePtr<T> &sf::ResourcePtr<T>::operator =(const sf::ResourcePtr<T> &)'
3>          with
3>          [
3>              T=sf::Texture
3>          ]
3>c:\sfml 2.0\include\sfml\system\resourceptr.inl(69): error C2227: left of '->Disconnect' must point to class/struct/union/generic type
3>c:\sfml 2.0\include\sfml\system\resourceptr.inl(74): error C2027: use of undefined type 'sf::Texture'
3>          c:\sfml 2.0\include\sfml\graphics\renderer.hpp(42) : see declaration of 'sf::Texture'
3>c:\sfml 2.0\include\sfml\system\resourceptr.inl(74): error C2227: left of '->Connect' must point to class/struct/union/generic type
3>  PolygonRenderer.hpp
3>  main.cpp
3>  GameImageManager.cpp
3>  Generating Code...
3>
3>Build FAILED.


Did I miss a step, or forget something otherwise?

Thanks,
Short

8
General discussions / undefined type sf::Texture
« on: September 16, 2011, 03:16:16 am »
Thank you for all the work you've done, do not apologize!!

9
General discussions / undefined type sf::Texture
« on: September 15, 2011, 08:19:40 am »
Hi there,

I compiled sf 2.0 using visual studio 2010, and I went to #include <SFML\Graphics\Sprite.hpp> which gets loaded correctly.

When I compile my program (with this file being included) I get the following errors:

Code: [Select]

c:\sfml 2.0\include\sfml\system\resourceptr.inl(60): error C2027: use of undefined type 'sf::Texture'
2>          c:\sfml 2.0\include\sfml\graphics\renderer.hpp(42) : see declaration of 'sf::Texture'
2>          c:\sfml 2.0\include\sfml\system\resourceptr.inl(58) : while compiling class template member function 'sf::ResourcePtr<T>::~ResourcePtr(void)'
2>          with
2>          [
2>              T=sf::Texture
2>          ]
2>          c:\sfml 2.0\include\sfml\graphics\sprite.hpp(207) : see reference to class template instantiation 'sf::ResourcePtr<T>' being compiled
2>          with
2>          [
2>              T=sf::Texture
2>          ]
2>c:\sfml 2.0\include\sfml\system\resourceptr.inl(60): error C2227: left of '->Disconnect' must point to class/struct/union/generic type
2>
2>Build FAILED.


I will post the file, just for completeness (it is small). Currently I have every instance of the sprite i want to initialize commented out, so I'll leave it like that.

Code: [Select]
#ifndef _SPRITECOMPONENT_HPP_
#define _SPRITECOMPONENT_HPP_
#include <string>
#include <SFML\Graphics\Sprite.hpp>
#include "../System/IComponent.hpp"
#include "../System/ISystemLog.hpp"
namespace Components
{
class SpriteComponent : public IComponent
{
public:

SpriteComponent(const sf::Sprite sprite) : IComponent("Sprite")//, _sprite(sprite)
{

}

~SpriteComponent() { }

/*const sf::Sprite GetSprite() const
{
return _sprite;
}*/

// abstract overrides
void SetProperties(std::map<std::string, boost::variant<int, std::string> > properties)
{
//_sprite = boost::get<sf::Sprite>(properties["sprite"]);
}

void Update() { }

private:
//sf::Sprite _sprite;
};

}

#endif


I'm running windows 7, with visual studio 2010. I am developing in C++.

Does anyone see anything that would point to why it thinks sf::Texture is undefined??

Thanks,
Short

Pages: [1]
anything