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

Pages: [1] 2
1
General / Help on Particle System-Like Rendering
« on: April 07, 2015, 01:15:47 am »
Hi, I am particularly looking for help on the implementing of a system similar to a particle system. Particularly I do not know exactly how to start with the implementing of emitters and affectors. I also want to implement a way to use animations within the article system as a part of the effects of the creation and deletion of particles.

I understand well enough how particle systems work, however I do not really know how to implement emitters and affectors to work well with the timing to keep the emission rate consistent regardless of the framerate. I know that the Thor Library has a very good implementation of one, however I am reinventing the wheel with learning purposes and I will use the code I develop to implement other things that the Thor Particle system does not allow me to do.

Thanks in advance.

2
Feature requests / Support for more primitives
« on: February 08, 2013, 06:43:23 pm »
Something simple and maybe even already planned, but I thought it wouldn't be bad to ask.

All of SFML primitives come from OGL of course, once SFML starts using OGL 2 adding all of it's primitives would be nice and grant more rendering possibilities. GL_POLYGON, GL_QUAD_STRIP and GL_LINE_LOOP are the only missing ones I think.

3
Feature requests / getPressedKey event
« on: January 23, 2013, 04:03:59 pm »
Not exactly as an event, but could qualify as one.

This feature would be used as a simple way to change the game's controls, when this event is run it polls if any key was touched and it returns the first key touched. Due to it's nature it's not logical (at least to me) for this kind of function to be inside the event loop. It could be as a way to poll for when was a key pressed through real-time keyboard input (without repetition of course), so you can easily get the code of an unknown key and use it for whatever programming you want.

sf::Keyboard::Key NewControl = sf::Keyboard::getPressedKey();
///Returns an invalid key code when no key was pressed.
///If multiple keys were pressed it returns the first one only.
///It could also have certain delay so that it keeps returning the recently pressed key for a short time.
 

This function/feature makes sense in an options menu where you want the player to easily change the input needed for the game. I suggested it as a function, but I don't know if it is really something so convenient that you can easily poll it with just that. Give your opinions towards this.

4
SFML wiki / Higher Performance Sprite Container
« on: January 10, 2013, 01:45:30 am »
I've just finished testing and debugging my container and I thought it nice to share the code in case anyone finds a use for it.

It's a container of vertices with their respective transformations, it's use is set to work with a sole texture and maximize performance in draw calls, cutting in half the time taken. It also has a good amount of shortcut functions that could be used at will and need. The link is here:

https://github.com/SFML/SFML/wiki/Source:-High-Performance-Sprite-Container

5
General / Another design question
« on: January 05, 2013, 05:14:45 pm »
This one's much simpler than the previous one, I made my own custom sprite meant to be used for groups of sprites that use the same texture and I am making the native container that allows me to handle it with ease.

The custom sprite has the four vertices and all you would normally expect with a sprite with the difference that it uses its center as a position point and that it isn't neither drawable nor transformable (self implemented transformations). The container works pretty much like a wrapper of a std::vector of vertices, however it differs from sf::VertexArray.

class AltSpriteHolder : public sf::Drawable
{

private:
        unsigned Quantity;

        sf::Texture Tex;

        std::vector<AltSprite> AS_Holder;;
        std::vector<sf::Vertex*> RefHolder;;
};
 


As you can see it needs to hold all my custom sprites and draw them accordingly. I use a vector of vertex pointers and not normal vertices because the respective vertices are already contained in the sprite and copying them everytime I need to update isn't really helping me with mantaining performances (the purpose of all this) high.

However after looking at many parts of SFML sources I got the doubt of  whether the vector of pointers will work or not at drawing time. VertexArray grants the performance boost due to reducing draw calls when using a single texture and having contiguous memory that helps it further. However while with pointers I won't have to copy anything I don't know if they'll work or not. And in the case the pointers aren't enough, the constant copying would betray the purpose of the container.

Here's the code for its draw function:

void AltSpriteHolder::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
    states.texture = &Tex;
    target.draw(RefHolder[0], static_cast<unsigned>(RefHolder.size()), sf::Quads, states);
}
 
 

Summarizing, the question is whether the pointers will actually work/draw (like a vector of sf::sprites) and be faster than a std::vector of sprites or the lack of contiguous memory will actually affect its speed badly or even make it not work.

If you have any ideas on how to make it better feel free to tell them, I'm pretty much out of them.

6
Feature requests / Texture rotation
« on: December 08, 2012, 08:47:41 pm »
Just as the title literally describes, it is something possible to do with openGL (like almost anything), but not with sfml as far as I know. It's when you want to rotate the texture (change how the texture is mapped). It makes little sense to use it that way when the texture isn't repeated, but when it is you can get nice effects.

I know the idea sounds a bit wacky since it's not really used often, but it may be useful in some cases.

7
General / [Solved] Design Question: Memory usage vs Run-time speed.
« on: November 28, 2012, 01:18:00 am »
So in my game I have a class that holds an amazingly big functionality (I would not exaggerate if I said that my whole game is trash without it). Even though it's a heavy class I use it often because I need to and I think it twice before I get to increase the size in memory of the class.

My class has an x amount of bullets, a vector of polar vectors (with size x) and a whole lot of control variables. I need to have control over the original position of my bullets. I can add a new vector that contains the starting positions for each instance of the class (but it would make it heavier than it already is) or constantly convert my vector of polar vectors into normal 2-dimensional vectors. (but I am not sure of how bad can that be for run-time).

I've done a lot of refactoring of crappy code lately and I don't want to do it again at all if possible so I ask here before I program anything. I also have to take into account that the class is something that can grow much greater than it already is (function-wise), so I'd like to refine my API as much as I can so that I don't go through a bad time when refactoring (if needed) like I just did. And the API may change according to the choice I go with.

I can post some code and explain my hierarchy further if needed, just ask.

8
Feature requests / Inverting a texture/sprite
« on: November 09, 2012, 11:58:45 pm »
I was working on my sprite sheet and found something interesting that could be useful for SFML that I think it's not yet implemented, correct me if it is, or if there is another way to this via sf::Sprite.

Let's say I have a an image and I want to flip it horizontally or vertically, you can easily do it with openGL by changing the way you map the texture to the quad, but if I did that I would lose the high level awesomeness that is an sf::sprite.

This would help those who have a sprite that is visually rotated to one side (i.e. a person looking to the side, etc) and want to make the sprite "look" the other way (or being upside down) using the same sprite.

I know well that you can do the exact thing I am saying with photoshop, SAI, Gimp or any other software for digital work, but when animating something it would just be wondrous to just flip your sprite instead of making another row in your sprite sheet. It can also become a very tedious thing to do when your sprite sheet for animations is big and you can't flip (not my current case hopefully). Not to say that it will reduce the size of the image for the sprite sheet.

I was thinking in a sprite function like:

 
sf::sprite spr;  
...

spr.HorizontalFlip(); ///It would flip the sprite to the opposite direction horizontally.
spr.VerticalFlip(); ///Same but in a vertical fashion.
 

Which would work with the texture associated with the sprite being worked with.
There could also be the same functions for sf::texture in order to flip the texture whatever way you want before the setTexture() call.

I'll attach two images of my sprites to show exactly what I mean.

[attachment deleted by admin]

9
Graphics / masskiller's OpenGL noob questions
« on: October 22, 2012, 11:56:13 pm »
So I finally started working with openGL. What I want to do is to take an image and rotate it's z axis so that I can make it into a background that looks kind of 3D. I've searched around the web for tutorials over OpenGL with SFML, but all I've found is either bad explanations (or very advanced for me) or code for older SFML versions which doesn't really work even if you port it to 2.0.

Here's the code I am trying:

#include <SFML/OpenGL.hpp>
#include <SFML/Graphics.hpp>

int main()
{
   
    sf::RenderWindow window(sf::VideoMode(1280, 800, 32), "Bullet Testing");
    sf::Sprite spr;

    sf::Image M;
    M.loadFromFile("Resources\\Images\\Menus and Others\\PNG\\Stage 1 Screen Cover (Temporary).png");
    M.createMaskFromColor(sf::Color::Black);
    sf::Texture Tex;
    Tex.loadFromImage(M);
    spr.setTexture(Tex);

    sf::Event event;

    sf::Image Image;
    Image.loadFromFile("Resources\\Images\\Misc\\PNG\\Pattern Background 1.png");

    ///Attempt to work with OpenGL
        GLuint Texture = 1;
        glViewport(74, 748, 682, 678); ///Bottom-left corner, OpenGL workstage, could be the entire window for some effect working.
        glMatrixMode(GL_PROJECTION); ///Modo de la matriz.
        glLoadIdentity(); ///Matriz identidad de OpenGL.

        glClearDepth(1.f);
    glClearColor(0.f, 0.f, 0.f, 0.f);

    // Enable Z-buffer read and write
    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);



    glGenTextures(1, &Texture);
    glBindTexture(GL_TEXTURE_2D, Texture);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Image.getSize().x, Image.getSize().y, 0, GL_RGBA, GL_UNSIGNED_BYTE, Image.getPixelsPtr()); ///Added those zeros, still don't know what they do...
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

    ///Tambien se puede hacer con glTexImage2D(mismos parametros).



window.setFramerateLimit(60);
sf::Clock FrameCount;
while (window.isOpen())
    {

        window.pushGLStates();
        window.draw(spr);
        window.popGLStates();

        glBegin();
        ///Stuff.
        glEnd();

        window.display();

        ///glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); Is it necessary even if you have window.clear???

        window.clear();


        while (window.pollEvent(event))
        { if (event.type == sf::Event::Closed) window.close(); }

     }

      return 0;
    }
 

I get some compiling errors, mainly an "Invalid conversion between unsigned char to GLenum" error and finally that glTexImage2D doesn't have enough arguments.

Edit: I kind of fixed the compilation errors I had (by adding 0 in two parameters I still don't know what they work for) and now I'm just getting a bunch of undefined references to all gl calls in the file.

Any help is appreciated.

10
Graphics / Image Deformation in SFML
« on: October 20, 2012, 02:38:13 am »
Say I want to take an image that is a straight line with colors effects and whatnot, does SFML allow me to deform that image into a shape? I want to make a laser that bends as it moves using only one image, so I was wondering if this was possible as I had never seen it before in SFML.

11
Feature requests / HSL Color Standard
« on: October 07, 2012, 06:15:42 am »
I'd like to propose to add the HSL (Hue, Saturation, Luminance) Coloring to SFML.

I have been investigating HSL Coloring system for a bit, while it's true that it's nowhere near as useful as RGBA is, however it allows easy color transformations such as colorizing an image with a given color in an easy way.

Here's an example: http://www.tannerhelland.com/3552/colorize-image-vb6/

This cannot be done in an easy way with RGB and I think that it would give the library another powerful tool if implemented. I don't think that HSL is good for being able to be used the same way as RGB, yet still to be able to colorize and manipulate colors in that way and give the user that freedom is what gave me the idea to suggest this into SFML.

So what do you think about this? Is it a good idea or not practical at all? I am implementing it myself for my game, but I think it'd be nice to see this in a future version of SFML.

12
General / Implementation of a progressive drawing method
« on: October 05, 2012, 02:08:02 am »
For my game I need to implement a method that draws some sprites that appear progressively. It's a variation of the draw that draws sprites contained in a std::vector according to an offset of time I give the class. Once it draws one of the sprites that sprite will always be drawn and the next one will be pondered whether it will be drawn or not (depending on time). My current method does that partially, it does do the waiting and once something was drawn it will keep on being drawn. However the time is not exact and the drawing order isn't sequential.

Here's the code:

void BulletPlacer::drawOnce(sf::RenderTarget& target)
        {
            for (unsigned i = 0; i < UseIndex; ++i)
            {   if ( ( Time.getElapsedTime() >= Tick ) || Checker[i])
                {
                    target.draw(ShotVec[i]);

                    if(!Checker[i])
                    { Checker[i] = true; }

                    if (Time.getElapsedTime() >= Tick)
                    { Time.restart(); }
                }
            }
        }

The time needs to be exact, if Tick is 0.1 seconds then it has to draw the sprites each 0.1 secs and it is supposed not  to be able to draw ShotVec[5] before ShotVec[0] to give an example. I'm out of ideas, so I come here for guidance.

13
General / [Solved] Advantages in the usage of a RenderTexture
« on: October 02, 2012, 11:21:31 pm »
So I want to set a fixed static image that shows scores, lives and has a rectangular frame where the game will be used in. After reading the doc I thought of using a RenderTexture and after making tests so as to realize that they worked for me (I have intel graphics) and realizing they do work I chose to use the rendertexture and made it work well.


The question is: What is the optimization for using unmovable backgrounds on rendertextures? I could have perfectly done the setting of a background with a normal sprite, instead of having a sprite draw and display in the rendertexture and then having another sprite drawing in the window to make it visible. According to the doc, you are encouraged to do the latter, I'd just like to know what benefits does it give or if I am not using it properly.

I'd also like to propose the creation of a thread of general small questions. Making a thread for every detail I don't understand well isn't something I am fond with.

14
Graphics / [Solved] Setting partial color to a texture
« on: September 29, 2012, 05:41:21 am »
Just a small question I couldn't find anywhere else: Is there a way to change color to a sprite or texture directly (without messing with the image first) other than setColor? I want to color some parts of the sprite, but not all of it (mainly leave the white in the image intact), it can be easily done handling the image first, but I know that's not very good timewise.

Edit: Just read a bit further and realized that you can't do it directly, sorry for the dumb mistake of having made this thread (tried deleting it, but it wouldn't allow me).

15
General / [Solved] Ways to raise FPS
« on: September 25, 2012, 03:54:32 am »
My problem is simple, my FPS count is around 30 or less when drawing around 1000 sprites and even when drawing little as 40 or less sprites I can't get it to raise from 50 (using 60 as a maximum) no matter how much I optimize, the problem seems to get worse when I use many textures.

The entire code for the issue is a bunch of classes and files, so I doubt I could post a minimal example of it that could be analyzable in an easy way. I'll just post the main function and explain what all the objects do.

const int num = 10;
const unsigned radius = 25;

int main()
{
   sf::RenderWindow window(sf::VideoMode(800, 600), "Bullet Testing");
   sf::Event event;
   sf::Time FrameTime = sf::seconds(1.f);
   sf::Time T = sf::seconds(1.5);
   bool check = false;

   TextureHolder Hold;
   Hold.setBasicTextures();
///What the name says.

   unsigned n = 0;

   BulletPlacer Put(num, num);
///Quantity as first parameter and bullets to be used as second.
   BulletPlacer Put2(num, num);
   BulletPlacer Put3(num, num);
   BulletPlacer Put4(num, num);

   Put.setBulletProperties(Hold, sf::Color(255, 0, 0, 255), sf::Vector2f(200.f, 100.f),1.f, 1);
/// TextureHolder, Color, Position, Speed, and Type (to know which texture to use).
   Put2.setBulletProperties(Hold, sf::Color(0, 255, 0, 255), sf::Vector2f(400.f, 300.f),1.5, 7);
   Put3.setBulletProperties(Hold, sf::Color(0, 0, 255, 255), sf::Vector2f(600.f, 100.f),1.f, 2);
   Put4.setBulletProperties(Hold, sf::Color(250, 50, 120, 255), sf::Vector2f(400.f, 400.f),1.f, 3);

   Put.ShotCircleCalculate(num, radius);
///Amount of bullets to be used and radius of the circle.
   Put2.ShotCircleCalculate(num, radius);
   Put3.ShotCircleCalculate(num, radius);
   Put4.ShotCircleCalculate(num, radius);

   Put.Bit = Put.ShotList.begin();
   Put2.Bit = Put2.ShotList.begin();
   Put3.Bit = Put3.ShotList.begin();
   Put4.Bit = Put4.ShotList.begin();

   std::list<Bullet>::iterator C = Put.Bit;
   std::list<Bullet>::iterator D = Put2.Bit;
   std::list<Bullet>::iterator E = Put3.Bit;
   std::list<Bullet>::iterator F = Put4.Bit;

window.setFramerateLimit(60);

sf::Clock Time, FrameCount;
///Clocks for frame counting and controlling when to draw the second BulletPlacer.
while (window.isOpen())
    {  
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
               {
                 window.close();
                 Hold.~TextureHolder();
                 Put.~BulletPlacer();
                 Put2.~BulletPlacer();
                 Put3.~BulletPlacer();
                 Put4.~BulletPlacer();
               }
        }
        window.clear();

        if(FrameCount.getElapsedTime() <= FrameTime)
        { ++n; }
        else
        { std::cout << "Frames Per Second: " << n << std::endl; n = 0; FrameCount.restart(); }

        Put.CLinearMove();
        Put3.CLinearMove();
        Put4.CLinearMove();

        if(Time.getElapsedTime() >= T)
        { Put2.CLinearMove(); check = true; }

        C = Put.ShotList.begin();
        D = Put2.ShotList.begin();
        E = Put3.ShotList.begin();
        F = Put4.ShotList.begin();

        for (unsigned i = 0; i < num; ++i)
        { if(C != Put.ShotList.end() && E != Put3.ShotList.end() && F != Put4.ShotList.end())
            { window.draw(*C); ++C; window.draw(*E); ++E; window.draw(*F); ++F; }
          else
              break;

          if (check)
          { if(D != Put2.ShotList.end())
            {window.draw(*D); ++D;}
            else
                break;
          }
        }

        window.display();
    }
    return 0;

}

 

BulletPlacer is a container for Bullets (using a std::list for bullet objects), which have many variables and methods to control movement from a contained sprite, it does inherit from drawable, but not from transformable.

TextureHolder is a container for textures and images to be used (then again a std::list for textures and images), BulletPlacer gets a reference to it in order to give the sprites within the bullets something to draw.

What the program does is draw the amount of usable bullets in the BulletPlacer object in a circle, the amount determines angle frequency in the circle, once placed they inmediately start moving linearly based on their given angle. I had a pretty inefficient code at first, then fixed it but the FPS didn't go up at all, it stayed the same. It goes slower the more bullets you put in the BulletPlacer, but even with a small amount there is still a loss of 10 FPS.

I've fixed all I know I can and still have gotten no results in that matter. If this were to be not enough I can provide a minimal code, but I'd rather only do it unless it's truly needed since I would have to compress a lot of code.  Thanks in advance for all help I may get.

Pages: [1] 2