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

Pages: 1 ... 3 4 [5] 6 7 ... 10
61
SFML projects / Re: The 2D Game - drawing a tilemap with a shader
« on: December 11, 2012, 01:16:11 am »
http://blog.tojicode.com/2012/07/sprite-tile-maps-on-gpu.html#more

Gives a decent overview of it and provides the code (although not C++, nor SFML, the shaders are glsl and it's fairly easy to convert) with a permissive license.

62
Graphics / Re: How do I get the boundaries of an Sf::Text object?
« on: December 10, 2012, 06:22:07 am »
Unless you're using a 1x1 pixel texture, which seems unlikely, you need to adjust the scaling factors.

63
General / Re: Rand() not working?
« on: December 09, 2012, 03:43:52 am »
srand() should be called one time in your program.

64
System / Re: multithreading and srand
« on: December 08, 2012, 10:54:00 am »
Quote
I have visual studio 2008. There is no support <random> and rand_r (drand48_r).

All that says to me is that you didn't actually take the time to read the material in the link.

65
Indeed, that does result in some artifacts, and they do disappear when the transparent lines are drawn.   Odd.



No time to dwell on it now.  =)

66
System / Re: multithreading and srand
« on: December 08, 2012, 06:33:06 am »

68
Seems to work fine for me with or without the lines being drawn.

69
However, this blends the entire render texture into the confines of the sprite, not just the region the sprite covers, resulting in each projectile becoming a square texture on the sf::RenderTexture, and without any of the blending I wanted.

In:
        vec4 spritepixel = texture2D(projectiletex, gl_TexCoord[0].xy);
        vec4 bgpixel = texture2D(bgtex, gl_TexCoord[0].xy);

The TexCoords are in normalized device coordinates (0-1.0).  You just need to scale the screen coordinates down to size (and flip the y coord.)

    ivec2 b_tex  = textureSize2D(bgtex, 0) ;
    vec2 coord = gl_FragCoord.xy/b_tex ;
    coord.y = 1.0f-coord.y ;

    vec4 spritepixel = texture2D(projectiletex, gl_TexCoord[0].xy);
    vec4 bgpixel = texture2D(bgtex, coord);
 


I'm a bit confused on the specifics of what you're doing with the projectile texture.

70
General / Re: SFML 2.0 Shader Masking
« on: December 06, 2012, 11:11:39 pm »
Yes.   gimp -  I think I used a 10 pixel radius for the effect.

71
Feature requests / Re: Get Sprite Screen position
« on: December 06, 2012, 11:09:55 pm »
If you tell the graphics system to draw something somewhere, do you then need to ask the graphics system where you told it to draw?  Maybe it would make more sense to remember what you told it.

Do moving objects that are not drawn on the screen stop moving and lose the ability to collide with other objects?

Quadtrees are usually defined in terms of world coordinates.

72
Graphics / Re: Order of drawing vertices in vertexarray
« on: December 06, 2012, 08:15:46 am »
Quote
When glDrawArrays is called, it uses count sequential elements from each enabled array to construct a sequence of geometric primitives, beginning with element first.

Found here.

73
Graphics / Re: Order of drawing vertices in vertexarray
« on: December 06, 2012, 05:51:39 am »
OpenGL draws them in order and I didn't see any reordering in the source for sf::RenderTarget.  Seems like a safe assumption.

74
Graphics / Re: sf::Text Garbled When Objects are Drawn Underneath
« on: December 05, 2012, 05:16:04 am »
http://en.sfml-dev.org/forums/index.php?topic=9561.0

The search function seems a bit reluctant lately.

75
Graphics / Re: Transparencies with VertexArray tilemaps
« on: December 05, 2012, 04:30:26 am »
If you've got a couple 640x480 images laying around, you can try out the following:

#include <SFML\Graphics.hpp>

void main()
{
    sf::RenderWindow window(sf::VideoMode(640, 480), "SFML - Transparency");
   
    sf::Texture base ;
    base.loadFromFile("base.png");

    sf::Texture overlay ;
    overlay.loadFromFile("overlay.png") ;

    sf::Vertex wholeScreen[] =
    {
       sf::Vertex(sf::Vector2f(  0,  0), sf::Vector2f(  0,  0)),
       sf::Vertex(sf::Vector2f(639,  0), sf::Vector2f(639,  0)),
       sf::Vertex(sf::Vector2f(  0,479), sf::Vector2f(  0,479)),
       sf::Vertex(sf::Vector2f(639,479), sf::Vector2f(639,479))
    };

    float overlayOpacity = 0.5f ;

    sf::Shader transparency ;
    transparency.loadFromFile("transparency.frag", sf::Shader::Fragment) ;
    transparency.setParameter("opacity", overlayOpacity) ;
    transparency.setParameter("texture", sf::Shader::CurrentTexture) ;

    sf::RenderStates overlayStates ;
    overlayStates.blendMode = sf::BlendAlpha ;
    overlayStates.shader = &transparency ;
    overlayStates.texture = &overlay ;

    while ( window.isOpen() )
    {
        sf::Event event ;
        while ( window.pollEvent(event) )
        {
            if ( event.type == sf::Event::Closed )
                window.close() ;
            else if ( event.type == sf::Event::KeyReleased )
            {
                if ( event.key.code == sf::Keyboard::Equal )
                    if ( (overlayOpacity += 0.1f) > 0.9f )
                        overlayOpacity = 1.0f ;

                if ( event.key.code == sf::Keyboard::Dash )
                    if ( (overlayOpacity -= 0.1f) < 0.1f )
                        overlayOpacity = 0.0f ;
            }
        }

        transparency.setParameter("opacity", overlayOpacity) ;

        window.clear() ;
        window.draw(wholeScreen, 4, sf::TrianglesStrip, &base) ;
        window.draw(wholeScreen, 4, sf::TrianglesStrip, overlayStates) ;
        window.display() ;
    }
}

transparency.frag:
uniform float opacity ;
uniform sampler2D texture;

void main()
{
    vec4 color = texture2D(texture, gl_TexCoord[0].xy);
    color.a *= opacity ;
    gl_FragColor = color ;
}
 

Pages: 1 ... 3 4 [5] 6 7 ... 10