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

Pages: [1] 2
1
Graphics / SFML Shaders
« on: December 22, 2011, 09:08:27 pm »
I was wondering if there was a list of shaders people have written for use with SFML? If not, would it be possible to make one (either in this thread or on the wiki)

I'm curious at some of the more interesting shaders people have come up with. I can search around the internet and find various shaders, but alot of them aren't written as purely fragment/2D (specifically SFML) and require translation to work under SFML. It would likely save myself and others lots of time if peopel who've written shaders would be willing to share :)

Assuming this is the appropriate place to post this, I'd love to see what people have come up with so I can incorporate and play with them (credit will be given if I end up using them of course)

2
Graphics / Rotating on sub-rected/animated sprites
« on: September 06, 2011, 02:25:00 am »
I have some animated sprites in a project I'm working on. I load a sprite sheet and create a set of subrects for the sheet that represent the various frames. The problem is when I rotate the sprite, it rotates the entire texture, so adding rotation ends up changing the position, even if I set the position after the rotation. For example, I have the follow drawing code


case Timing::Quarter:
               {
                  QuarterArrow[index]->SetRotation(arrow.Rotation);
                  QuarterArrow[index]->SetPosition(arrow.Position);
                  QuarterArrow[index]->Draw(window);
               }
               break;


I do this routine for 4 arrow structs, each of which draws the same sprite. Position is the same for all 4. The structs have rotations of 0, 90, 180 and 270 for the roation value.

I was expecting the 4 sprite to end up directly over top of each other, but instead they are spread out.

I figured I can overcome this by calculating an offset based off the Rotation parameter and offseting position by that, however I was hoping there was some way to do rotation just relative to the subrect, now the entire texture. Is this doable?

3
Graphics / Easy channel swap?
« on: July 27, 2011, 01:21:47 am »
I was wondering if there was a quick/easy way to swap the channels on an image/sprite.

I'm using Awesomium in my game to test some UI stuff, but for some reason when I have Awesomium push the pixel buffer to the sf::Image of my sprite, the R and B channels are swapped. This is easy to correct using shaders, or doing a pixel by pixel swap, however Id like to avoid dependency on shaders if theres another way, and the pixel by pixel swap is far to slow.

Any suggestions would be helpful

thanks

4
Graphics / Spell Effects
« on: July 15, 2011, 12:54:25 am »
If you could that'd be great.

I've been able to get okay results by either "yellowfying" all the points in the sprite or gray scaling then multiplying by yellow, but neither of them quite achieve the effect displayed in that video

5
Graphics / Spell Effects
« on: July 13, 2011, 05:36:09 am »
I'm not sure if this is outside the bounds of what this board covers, but I figured I'd ask.

I want to be able to achieve spell effects that cause a fragmenting/discoloring effect on the sprite. The first couple seconds of shows what i meant. When the enemy get's hit by an electric attack, the effect I'd like to achieve activates (in yellow).

I'll have to use shaders to do this (if I don't, other, practical ways to do it would be extremely helpful). I have no idea where to start with a shader like this (beyond the obvious - using time and base color as parameters), and was curious if someone had something similar I could use as a base, or had a good idea where to start. I know the basic of glsl, but was hoping to spare myself some pain if someone has something like this already or could provide a starting point.

Any help would be appreciated,

thanks[/url]

6
Graphics / Inverting a sprite
« on: July 13, 2011, 04:12:02 am »
I'm not sure if this is the most efficient way, but it works
Just make sure the sprite's texture is loaded to texture:


Code: [Select]
uniform sampler2D texture;

void main()
{
vec4 ref = texture2D(texture, gl_TexCoord[0].xy) * gl_Color;
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0) - ref;
gl_FragColor.a = ref.a;
}

7
Graphics / Curving a sprite/shape
« on: July 05, 2011, 02:30:54 am »
I was wondering if it's possible to curve a sprite in a radial manner? I'm asking as I'm trying to make a straight line curve into a circular shape on one end? Here's an example of what I mean.

This is a template for displaying character information in battle:



I have a green HP bar that fills the bottom bar of the template like so:



I would like to be able to wrap that bar along the loop. I know I could create the gradient bar itself with the loop shape, but that doesn't help when I need to change the subrect/scale of the gradient bar to show a loss of HP for the character.

Do I need to do direct OpenGL calls to do that? Could someone help me out, I'd appreciate it.

I'm using SFML 2 from the start of June if that matters.

Thanks

8
Graphics / Is Drawing Text slow?
« on: June 11, 2011, 07:19:44 pm »
Ah alright. I guess I was expecting drawing text to be as/nearly as fast as drawing sprites

9
Graphics / Is Drawing Text slow?
« on: June 11, 2011, 10:28:56 am »
I was curious if sf::Text is known for being slow to draw? This is with regards to SFML 2.0. I'm not sure which revision but it was downloaded/compiled within the last few weeks.

I was working on the user interface for my game, and most of my text is composed of a class called OutlineText.

OutlineText contains 5 sf::Text objects. A quick view of the class with non relevant functions removed is as follows:

Code: [Select]
class OutlinedText
{
public:
        void Draw(sf::RenderWindow &window)
{
window.Draw(BackgroundText);
window.Draw(BackgroundTextXNeg);
window.Draw(BackgroundTextY);
window.Draw(BackgroundTextYNeg);
                window.Draw(BaseText);
        }
protected:
std::string text;
sf::Text BaseText;
sf::Text BackgroundText;
sf::Text BackgroundTextXNeg;
sf::Text BackgroundTextY;
sf::Text BackgroundTextYNeg;
}


I make heavy use of this class to produce an outlined effect around my central text. (I.E. BaseText would be white and the other 4 would be black to give it the appearance of being outlined in black) If someone has a better suggestion on how to do this, that'd be great, but for now this does work.

I added a few instances (36 OutlinedText so 180 sf::Text instances) of this class and i saw a pretty noticeable increase in CPU usage versus when I was drawing tile maps/some other images(the number of tiles plus other images that are rendered can easily more then 200) For instance at 800x600x32, 150fps it went from 2-3% CPU usage with the tilemap/others in debug to 7-8+% CPU usage in debug and from ~0% CPU usage in release to 1-2+% CPU usage in release - not a huge concern right now, but the interface isn't done so usage is only going to go up. Profiling my code did show rendering Text to be the hot path. So I was curious if I'm supposed to be seeing this increase? Or perhaps something is off about my setup.

If it makes a difference, the text is colored a variety of colors (all at default alphas) and I'm using 3 different fonts amongst the various OutlinedText instances. This is compiled in Visual Studio 2010 under windows 7 x64, and release mode is set to Full Optimization.

For Clairty, Here's an example screenshot showing the Outlined Text. Note that if I draw everything except the text below the character portraits (i.e. the tilemap, picture stack to the right, character portraits etc. the cpu usage is at the low levels I stated above. Pardon the messiness, Those graphics are there to show my point)
http://garyoak.com/samples/Screenshot1.png

And the First page of the code profile showing the render text is the hot path (plus what it break down to)
http://garyoak.com/samples/Sampling.png

Thanks in advance

10
Window / Handling User Input
« on: April 19, 2011, 06:40:42 pm »
This is abit more of a conceptual question, but I figured this was likely the best place to ask. I looking for advice and I was wondering how other people handle input in their games.

For my game, which is primarily an RPG, but it has some action elements where the player will need to time their inputs carefully.

The way I designed mine, at least at the moment, was to have a separate class that's part of the game as a whole. Every Key Event/Joystick Event/Mouse Event is fed into that class, and the class will map the various types of input to ingame actions using maps like below:

Code: [Select]
std::map<sf::Key::Code, InputActions> KeyMapper;
std::map<sf::Key::Code, InputActions> KeyMapper2;
std::map<unsigned int, InputActions> JoyMapper;


where InputActions is an enum for the various actions in the game (Up, Down, Left, Right, Cancel, Confirm, Start, Select, etc.).

The input class has a bool array
Code: [Select]
bool ActionSet[InputCount]; that is used to indicate what inputs are currently held. I activate the inputs as follows (the below are for keyboard keys, the joysticks use something similar)

Code: [Select]

//Used when the input module supports only one key active at a time
void HandleSingleKey(sf::Key::Code &key, bool released = false)
{
                      if (!released)
                      {  
for (int i = 0; i < InputCount; ++i)
{
if (i != sf::Mouse::Button::Left && i != sf::Mouse::Button::Right)
ActionSet[i] = false;
}
                        }
auto it = KeyMapper.find(key);
if (it != KeyMapper.end())
ActionSet[it->second] = !released;
}

//Used when the input module supports multiple keys at a time
void HandleMultiKey(sf::Key::Code &key, bool released = false)
{
auto it = KeyMapper.find(key);
if (it != KeyMapper.end())
{
ActionSet[it->second] = !released;
}
}


I'm currently only testing with multiple inputs enabled (the HandleMultKey function).

Basically, each object that needs to handle user input will be fed a pointer to this input module, and the current game time at the start of each loop iteration. It is up to the object to determine if it is ready to resample the input and find the changes in user input (like below). InputRes represents how much time needs to elapse between each input sampling

Code: [Select]
void QTriadGame::UpdateInput(InputModule* module, float time)
{
if (time - LastInputUpdate > InputRes )
{
                        //Omitted Code Handling inputs by looking up active keys from module
                        LastInputUpdate = time;
              }
}



Here's my concerns about the way I'm doing it:

 As you can tell form the earlier, I'm relying on the Released event to tell me when to mark an input as invalid. I noticed while debugging that if the program was paused during input handling, the released event would fail. I'm worried about this happening once the game is running normally, and I'm not entirely sure how to deal with it. Anything involving timeouts could be bad as it's possible the user holds down a button for an extended period of time.

Additionally, I'm likely going to need to know later on when the key became active, so I might change my array from a bool array to an array of bools/float where float indicates the gametime when that input became active

It just feels like I'm making this more complicated then it needs to be, so I was looking for some advice/suggestions or how other people did their use input.

Thanks in advance

11
Graphics / Map Scrolling (C#)
« on: December 19, 2010, 11:34:03 pm »
I posted this before but realized that it was a bad way to post it. i created a small sample project to demonstrate the problem I'm having. Should be clearer then last time.

Basically, I want to use views to scroll through maps in a game I'm making. However, i only want the view to scroll if the player has move over half the x/y resolution in x/y, otherwise I just want to move the character sprite while leaving the map alone. Moving the sprite is easy enough, I just increment or decrement the sprites position by the size of a tile over some period of time. When the character's s[rite position has passed half the x/y resolution, I then proceed to increment the character map position while leaving the sprite position alone. The drawing routine will detect that the character's map position is sufficiently large, and will create a new view by the appropriate value.

What I have now, sort of works, but I'm having trouble/losing coordinates when transitioning between moving the character sprite and moving the map. If someone could take a look at my code and help me out with it, our post how they handled map scrolling with views, I'd greatly appreciate it.

Thanks :)

Sample:
http://www.garyoak.com/MapScrollingExample2.zip

12
Graphics / Best Way To Translate (move) A Sprite?
« on: November 21, 2010, 08:54:29 am »
I had a question about what the best way is to move a sprite from point A to point B over a period of time. I have a method to do so as part of my sprite class, but I noticed it can sometimes be a bit jerky/rough looking when the translation is over a length of more then a few pixels. I was wondering if anyone could give me some suggestions on how to do it better. Basically, here is what I'm doing right now (it's in C# but the logic should be pretty straightforward):

My Sprite class has a method called SlideSprite that looks like this.

Code: [Select]
public void SlideSprite(Vector2 targetPosition, TickCount elapsedTime, TickCount currentTime)
        {
            this.targetPosition = targetPosition;
            this.targettime = currentTime + elapsedTime;
            _lastTranslationUpdate = currentTime;
            if (elapsedTime > 0)
            {
                translationVector = Vector2.Subtract(targetPosition, this.Position);
                translationVector = new Vector2(translationVector.X / elapsedTime, translationVector.Y / elapsedTime);
            }
        }


TickCount is just a measure of game time in milliseconds. targetPosition is the co-ordinates to move the sprite too, elapsed is how many milliseconds the sprite has to move to its target position, and currentTime is the current game time (again in ms).

The sprite implements another method called Update that is called whenever a drawing loop begins, but before any drawing occurs. The update method basically looks like this:

Code: [Select]
public virtual void Update(TickCount currentTime)
        {
            if (translationVector != Vector2.Zero)
            {
                TickCount elapsed = currentTime - _lastTranslationUpdate;
                if (currentTime < targettime)
                {

                    this.Position = Vector2.Add(this.Position, Vector2.Multiply(translationVector, elapsed));
                }
                else
                {
                    this.Position = targetPosition;
                    translationVector = Vector2.Zero;
                    if (spritesettled != null)
                        spritesettled.Invoke();
                }
                _lastTranslationUpdate = currentTime;
                //if (this.Position.X
            }
            if (animType != AnimType.None && isPlaying)
            {
                UpdateFrameIndex(currentTime);
            }

        }


Any tips on how to make this faster/smoother? I'm currently running my game at 60 FPS. I was thinking about splitting the Update component of the game into a seperate thread, and jsut making sure i add locks anywhere necessary.

13
Graphics / Transparency Gradient
« on: November 17, 2010, 07:48:59 pm »
I was wondering if it's possible to have a sprite who's tranparency changes from side to the other? For instance, I have a sprite that I want to be fully visible at the top but then fade to transparent by the time I hit the bottom. Would you have to use shaders for this?

Thanks

14
Graphics / Drawing Text with an outline
« on: November 07, 2010, 06:36:08 am »
Thanks spodi, the way you mentioned before worked, Ill give the shader a try later

15
Graphics / Drawing Text with an outline
« on: November 03, 2010, 07:28:33 am »
I was wondering if it's possible to draw a text object so that the font has an outline?

for instance, if I have a white font, I may want to put a thin black border around it to accentuate it. I'd assume it'd be possible via shaders, but I was wondering if there was a way that doesnt rely on shaders.

I'm using the .net bindings for SFML so that may be a possible limitation.

If anyone has an idea how to do this that they could share, that'd be great.

Thanks

Pages: [1] 2