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

Pages: [1]
Graphics / Only render the contents of a view
« on: June 06, 2014, 07:50:16 am »
Yeah, this is another thread about clipping. :P I searched as best as I could but I can't seem to find a solution. I'm not very good at math so I don't doubt what I'm trying to do is really simple, but it's eluded me so far.

Basically, when I resize the window, I want to resize the view so as to fit in the window with proportional scaling, letterboxing when necessary, and center it in the window. That much is done, as you can see in the code below.

What I need to do now is make it so that nothing beyond the extents of the view rect is rendered. I can't figure out how to get the appropriate values for my Viewport.

FP.Width and FP.Height are the dimensions of the screen when it is created.

public void Resize(int width, int height)
        _sfmlWindow.Size = new Vector2u((uint) width, (uint) height);
        var targetWidth = (float) width;
        var targetHeight = (float) height;
        var scale = Math.Min(targetWidth / (float) FP.Width, targetHeight / (float) FP.Height);
        var toWidth = width / scale;
        var toHeight = height / scale;
        var x = (toWidth - FP.Width) * -0.5f;
        var y = (toHeight - FP.Height) * -0.5f;
        var viewRect = new FloatRect(x, y, toWidth, toHeight);
        var view = new View(viewRect);

Feature requests / Joystick information
« on: November 18, 2013, 11:21:51 pm »
I'm working on a game that needs to support a few different types of gamepads all with different button configurations; button 0 (A) on the Xbox controller corresponds to X on the SNES controller and it's in a completely different place. I'm sure I don't need to go into too much detail on this matter as it's pretty well known that joysticks are utter chaos.

Is there a possibility that we'll see a function to get a string name or other sort of description for a given joystick ID? It would be really nice to be able to load set up buttons based on a named configuration file à la SDL2.

Window / Unable to process specific inputs simultaneously
« on: July 26, 2013, 10:34:49 pm »
I'm having some trouble with getting input from some specific keys, and I can't think why. Using C#, but I don't think that part matters.

This works as expected (Up arrow, Spacebar, Right arrow):

The output when all three keys are held is:

However, if I change the test to use the left arrow instead of right:


The output when all three keys are held is:

It's as though the spacebar isn't registered at all. Is this just a limitation of my keyboard or the way input is handled by the OS?

DotNet / Sound recycling on .NET
« on: July 03, 2013, 03:44:49 pm »
When I use SFML with C++, I delete sound objects after they finish so as to not hit the limit of 256 sounds. How might I go about this in .NET? Is there a better way that I should be managing this?

DotNet / Utility functions missing from Shape? [Solved]
« on: May 07, 2013, 03:48:14 pm »
Was Shape.Line() removed recently? Is there a better way to duplicate its functionality?

SFML projects / New RichText class
« on: February 28, 2013, 07:45:39 pm »
I've been looking around for a way to combine multiple colors and styles in a single sf::Text.  This class came pretty close, but it doesn't have newline support, which is kind of a deal breaker, so I wrote my own. You can find it here.

The interface is a direct copy of sf::Text (except for findCharacterPos; I'm not sure how to do this at the moment). It's a drawable and transformable, so you can use it just like any other class.

Currently it has a minimal markup parser built in with support for colors and bold, italic, and underlined text. You can use the built-in color names (includes all the ones that are predefined in sf::Color) or HTML-style hex color codes, and define your own color names as well. The parser could probably use some memory optimization, but it only runs when you set the text, and runs quickly at that.

And here's a screenshot, because everyone loves them.  ;D

Graphics / Using OpenGL without additional libraries
« on: January 21, 2012, 06:55:47 am »
I want to expand my modest little engine to support basic 3D, so I've been looking around for some good OpenGL tutorials. Unfortunately, so far they've all been less than preferable for one of two reasons:
    Deprecated practices; fixed-function pipeline or glBegin / glEnd
    External libraries; GLUT, GLFW, etc

I'm using SFML2. Can anybody point me at a good resource that would allow me to learn modern OpenGL without using any other libraries?

If it's possible to use GLUT/GLFW in tandem with SFML, I'm not against that option.  :wink:

Graphics / Auto-zoom view
« on: August 04, 2011, 09:11:12 pm »
I'm trying to implement a camera that pans and zooms to always keep a set of points in view. Currently I center a sf::View on the average position of all objects in a std::vector< const sf::Vector2f* >, and that hasn't given me any trouble. Zooming is proving to be a pain though.

What I want to do is zoom out if any point is further from the center than a given distance, or zoom in if a point is less than a certain distance, with some kind of buffer. I've already tried using sf::Rect<>::Contains (unpredictable and choppy) and getting the length of a line between the center of the view and the points (unreliable as the view zooms out). Anybody have any tips?

Graphics / View inside a view
« on: March 12, 2011, 03:24:17 am »
I feel like this is ridiculously easy, but I haven't been able to think of how to do it.

Is there a way to embed a sf::View inside another? I'm working on a GUI and this would make it so much easier to handle scrollable widget views, drop-down boxes, tabs, etc.

Graphics / Drawables manager [Solved]
« on: February 23, 2011, 06:37:56 am »
I'm trying to clean up my render loop and I thought this might work, since It works fine with a vector of Sprites/Shapes etc.:

Code: [Select]

std::vector< sf::drawable > Drawables;


for (unsigned int i = 0; i < Drawables.size(); i++)

However the compilation fails with these errors:

/usr/include/c++/4.4/ext/new_allocator.h||In member function ‘void __gnu_cxx::new_allocator<_Tp>::construct(_Tp*, const _Tp&) [with _Tp = sf::Drawable]’:|
/usr/include/c++/4.4/bits/stl_vector.h|737|instantiated from ‘void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = sf::Drawable, _Alloc = std::allocator<sf::Drawable>]’|
/home/jake/Projects/CodeBlocks workspaces/Meander/main.cpp|76|instantiated from here|
/usr/include/c++/4.4/ext/new_allocator.h|105|error: cannot allocate an object of abstract type ‘sf::Drawable’|
/usr/include/SFML/Graphics/Drawable.hpp|59|note:   because the following virtual functions are pure within ‘sf::Drawable’:|
/usr/include/SFML/Graphics/Drawable.hpp|341|note:    virtual void sf::Drawable::Render(sf::RenderTarget&) const|
/usr/include/c++/4.4/bits/vector.tcc||In member function ‘void std::vector<_Tp, _Alloc>::_M_insert_aux(__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >, const _Tp&) [with _Tp = sf::Drawable, _Alloc = std::allocator<sf::Drawable>]’:|
/usr/include/c++/4.4/bits/stl_vector.h|741|instantiated from ‘void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = sf::Drawable, _Alloc = std::allocator<sf::Drawable>]’|
/home/jake/Projects/CodeBlocks workspaces/Meander/main.cpp|76|instantiated from here|
/usr/include/c++/4.4/bits/vector.tcc|306|error: cannot allocate an object of abstract type ‘sf::Drawable’|
/usr/include/SFML/Graphics/Drawable.hpp|59|note:   since type ‘sf::Drawable’ has pure virtual functions|
/usr/include/c++/4.4/bits/vector.tcc|306|error: cannot declare variable ‘__x_copy’ to be of abstract type ‘sf::Drawable’|
/usr/include/SFML/Graphics/Drawable.hpp|59|note:   since type ‘sf::Drawable’ has pure virtual functions|
/usr/include/c++/4.4/bits/stl_uninitialized.h|117|instantiated from ‘_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = sf::Drawable*, _ForwardIterator = sf::Drawable*]’|
/usr/include/c++/4.4/bits/stl_uninitialized.h|257|instantiated from ‘_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = sf::Drawable*, _ForwardIterator = sf::Drawable*, _Tp = sf::Drawable]’|
/usr/include/c++/4.4/bits/stl_uninitialized.h|267|instantiated from ‘_ForwardIterator std::__uninitialized_move_a(_InputIterator, _InputIterator, _ForwardIterator, _Allocator&) [with _InputIterator = sf::Drawable*, _ForwardIterator = sf::Drawable*, _Allocator = std::allocator<sf::Drawable>]’|
/usr/include/c++/4.4/bits/vector.tcc|338|instantiated from ‘void std::vector<_Tp, _Alloc>::_M_insert_aux(__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >, const _Tp&) [with _Tp = sf::Drawable, _Alloc = std::allocator<sf::Drawable>]’|
/usr/include/c++/4.4/bits/stl_vector.h|741|instantiated from ‘void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = sf::Drawable, _Alloc = std::allocator<sf::Drawable>]’|
/home/jake/Projects/CodeBlocks workspaces/Meander/main.cpp|76|instantiated from here|
/usr/include/c++/4.4/bits/stl_uninitialized.h|74|error: cannot allocate an object of abstract type ‘sf::Drawable’|
/usr/include/SFML/Graphics/Drawable.hpp|59|note:   since type ‘sf::Drawable’ has pure virtual functions|

which leads me to believe that a base class with pure virtual functions cannot be added to a vector. So:

Does anyone have a suggestion on how I would implement this?

Graphics / sf::Rect array (Solved)
« on: October 25, 2010, 12:25:45 am »
I'm trying to use a for loop to check a Vector for an sf::FloatRect that contains a given coordinate set. However, when I do this:

Code: [Select]

sf::FloatRect Restraint[2];
Restraint[0](Left, Top, Width, Height);

my compiler complains:

error: expected constructor, destructor, or type conversion before ‘(’ token

Is this a mistake I'm making, or a bug in the library? Any insight would be appreciated.

SFML: 1.5
OS: Linux
Compiler: g++
IDE: Code::Blocks

Pages: [1]