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

Pages: 1 2 3 [4] 5 6 ... 10
46
Graphics / Drawing Text with an outline
« on: November 03, 2010, 10:09:18 pm »
Well, after a few hours, I managed to come up with something that works decently. Took quite some time to come up with the right algorithm to preserve the alpha values properly.

Code: [Select]
uniform sampler2D tex;
uniform vec2 texSize;
uniform vec4 outlineColor;
void main(void)
{
vec2 off = 1.0 / texSize;
vec2 tc = gl_TexCoord[0].st;

vec4 c = texture2D(tex, tc);
vec4 n = texture2D(tex, vec2(tc.x, tc.y - off.y));
vec4 e = texture2D(tex, vec2(tc.x + off.x, tc.y));
vec4 s = texture2D(tex, vec2(tc.x, tc.y + off.y));
vec4 w = texture2D(tex, vec2(tc.x - off.x, tc.y));

vec4 origColor = c * gl_Color;

float ua = 0.0;
ua = mix(ua, 1.0, c.a);
ua = mix(ua, 1.0, n.a);
ua = mix(ua, 1.0, e.a);
ua = mix(ua, 1.0, s.a);
ua = mix(ua, 1.0, w.a);

vec4 underColor = outlineColor * vec4(ua);

gl_FragColor = underColor;
gl_FragColor = mix(gl_FragColor, origColor, origColor.a);

if (gl_FragColor.a > 0.0)
gl_FragColor.a = 1.0;
}


There is a little issue with the display of the first character. It seems SFML adds a little white block to the top-left corner of a font bitmap, so that ends up making a little artifact display for the first character. In theory, it'll also show artifacts if there are any font characters without padding between them in the font texture. Could get rid of this by just clamping the texture coordinates, but don't know of any way of finding the specified coordinates for the draw call without passing them as a parameter (which would require modifying SFML to update that parameter before each character is drawn).

Edit: Updated the shader. Kinda disappointed in myself for not realizing to take this approach initially. Was too stuck on the idea of recognizing when the edge has been reached.

47
Graphics / Drawing Text with an outline
« on: November 03, 2010, 07:36:42 pm »
The problem with doing it inside of a font file directly, or applying it to a font using SetPixel, is that you are increasing the amount of memory used to store your fonts. With using a font with outlines built-in, it also introduces a lot more hassle.

Ideally, you want to be able to just say "use outline", and it draws with outlines with no reduction to performance and takes up no extra memory. With shaders, this is likely possible since not many of us are going to be bottlenecked on the fragment processing (unless you are already using some heavy shaders).

48
Graphics / Drawing Text with an outline
« on: November 03, 2010, 09:00:43 am »
Quote from: "Laurent"
Quote
namely the ability to look up the size of the texture so you could actually use a pixel scale

If that's the only thing you need, you can send it manually to the shader through a variable.


That was what I had in mind at first, too, but didn't realize at the time that Font had a GetImage method (clearly I didn't look very hard). Maybe I'll play around with it again and see if I can whip up something.

49
Graphics / Drawing Text with an outline
« on: November 03, 2010, 08:22:05 am »
I personally do this right now by drawing the text 5 times. Draw the background using the offsets of (0,1),(1,0),(0,-1),(-1,0) (up,down,left,right) and then the normal text. Inefficient? You betcha! But it gets the job done.

I have looked into doing this with shaders, but I couldn't find any decent way of doing it without some of the features of newer version of GLSL (namely the ability to look up the size of the texture so you could actually use a pixel scale).

50
General discussions / Automatic batching in sfml2 branch
« on: November 03, 2010, 01:32:42 am »
You would only want to draw to an off-screen surface (RenderImage) if your particles do not change each frame. That'd be a pretty boring particle effect, though.

Drawing to another surface every frame will only reduce the frame rate since the render target has to be changed every so often, plus you are using more resources.

I have particle effects in my engine, and just drawing like any other sprite works just fine. Granted, it is far from ideal since that is a lot of calls, but from what I have seen, draw calls do not have as much overhead in OpenGL as they do in DirectX.

The only places you can really use an off-screen surface for performance gains by drawing less is if you:
1. Have relatively static images (you don't need to update the RenderImage much... exactly how much depends on other variables)
2. The RenderImage you are creating is relatively complex (a bunch of overlaid sprites, like a GUI system)
3. The cost of managing the updates and tracking the state is relatively low

For many games, the number of places you can utilize an off-screen cache is relatively low, and it can add an incredible amount of complexity to your render logic. So my opinion - don't bother trying to cache parts of the screen.

If you want to display more than your system can handle, you're going to want to try to find some other ways to "cheat" it. Draw larger particles instead of smaller ones. Cluster multiple particles together in a single sprite to make it appear like there are really more. Make use of fragment shaders where you can. Etc.

Quote
I SDL I used to blit all my particles onto a surface and then drew the surface to the screen. Any way of replicating this behavior?


That is exactly the same as you are describing for SFML, and its very easy  with SFML 2.0. Its just that it doesn't bring any benefit unless the particles in your particle system are completely static.

51
SFML projects / NetGore - C# open source MORPG engine
« on: November 02, 2010, 07:29:54 am »
Version 0.3.2 has been released. :)

52
General discussions / Window Resize, Causes Major Window Glitching
« on: October 15, 2010, 10:01:54 pm »
Re-encode: http://www.netgore.com/temp/sfmlvidpostreenc.mkv (6.3 MB)

Even still, I'm not sure what I am looking at.

53
SFML projects / NetGore - C# open source MORPG engine
« on: October 14, 2010, 11:02:52 am »
Just recently released version 0.3.0 which implements a huge amount of new stuff, including taking advantage of more of SFML's features - namely shaders and RenderImages to improve the light handling and add refractions (see water in second screenshot). The demo game's visuals have also been improved, upgrading it from "super ugly" to just "regular ugly". :wink:

Some screenshots:


(more here)

Site: www.netgore.com

54
Graphics / SFML PNG Images
« on: October 09, 2010, 09:30:32 pm »
Alpha is read and properly utilized.

On a related note, not all images can be read even if the format is supported. So if you try to load a PNG (or any image) and get an error, try saving it with another program. I personally use Paint.NET since it has never given me any issues but still provides good PNG compression.

This error is a pretty rare occurrence, but can be tough to find if you don't know about it, so figured it is worth mentioning. :)

55
Graphics / How can I 'mask' an image
« on: September 29, 2010, 03:10:34 am »
I don't think there is any simple way to actually apply a mask in the traditional sense of a mask, but you can set an image to make a certain color transparent with sf::Image::CreateMaskFromColor.

56
Graphics / Is it possible to hide the mouse cursor?
« on: September 29, 2010, 12:54:34 am »

57
Graphics / Renderimage upside down?
« on: September 28, 2010, 08:17:52 pm »
Call RenderImage.Display() before you read from the RenderImage, so right before this line:

Code: [Select]
base.MainWindow.Draw(new Sprite(this.MainBuffer.RenderBufferImage.Image));

58
General / Fairly unnerving problem
« on: September 27, 2010, 01:22:02 am »
Are you sure its your HDD, and not your video card whining? Or some other component?

Just for the record, I also hear some kind of whine from some piece of hardware when I use SFML with shaders. I just figured it was my GPU under stress or "something".

*shrugs*

59
Graphics / Weird results with blur shader
« on: September 22, 2010, 11:03:03 pm »
No problem, glad it was that simple. :)

Was the purpose of the offset to grab 1 texel in each direction and blur them all together? If so, you might want to instead calculate by using an offset of:

pixelOffset / textureSize

You can get the texture size using textureSize(), but I think that is only in later version of GLSL, so you will have to pass the size as a parameter.

60
Graphics / Weird results with blur shader
« on: September 22, 2010, 07:50:59 pm »
At a quick glance, you might want to try using a smaller offset.

Pages: 1 2 3 [4] 5 6 ... 10
anything