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

Pages: [1]
1
Graphics / Re: Can this be done with an OpenGL shader?
« on: August 30, 2014, 02:45:07 pm »
Take a look at this example on ShaderToy which seems to be similar to the effect you're after: https://www.shadertoy.com/view/MdB3zK

Be aware that the method used is probably not the fastest as it need to compute the distance to each line for each pixel which will be pretty slow with a large number of lines but depending on exactly what you're using it for it may be work well.

Another similar although far more complex example can be found here: https://www.shadertoy.com/view/4slGz4
 

2
Graphics / Re: Trying to implement a shockwave shader using sf::Shader
« on: January 18, 2014, 11:00:49 am »
You've made a small mistake in your vertex shader.

The line:
var_TexCoord = gl_MultiTexCoord0.xy;
should be:
var_TexCoord = gl_TextureMatrix[0] * gl_MultiTexCoord0;

3
Graphics / Re: Circular movement
« on: January 14, 2014, 08:05:41 am »
This page http://www.mathopenref.com/coordparamcircle.html should explain what you need to know in sufficient detail.

I'd highly recommend following the suggestions of the other posters and study trigonometry. The importance of understanding maths in game development can't be overstated.

4
Graphics / Re: sf::RenderTexture::clear not working. (bug?)
« on: January 11, 2014, 04:01:10 am »
There's also an older thread on this issue here: http://en.sfml-dev.org/forums/index.php?topic=9350.0

It does seem to be only affecting AMD cards and their drivers. I have the issue on my desktop but there's nothing on my laptop which has an Nvidia card.

It's interesting that there seems to be three ways to fix this problem.

1. window.resetGLStates()
2. draw a fully transparent sprite over the entire screen
3. apply a post-effect shader

It's obviously got something to do with the OpenGl state but it's interesting that two and three also fix the state issue. I've tried calling all of the OpenGl functions that SFML calls in resetGLStates() but none of them had any effect. I then tried the internal SFML functions but the only one that had any effect on the output was sf::Texture::bind(nullptr, sf::Texture::Pixels) which resulted in a blank white screen.

I'm not sure if this information will help anyone but I don't know anywhere near enough about OpenGl to have any idea where to go from here.

5
Graphics / Re: Build a Realistic Sphere
« on: January 06, 2014, 01:07:19 pm »
There are many ways to approach this problem and each has it's own advantages.

Probably the easiest way to do it if you any artistic skill is to combine several individuals textures with noise and colour variations in order to create the appearance of many different planets when in fact they are based off a small number of building blocks.

If I was taking this approach then I would generate the base like you have with a random colour and then I would apply spherical distortion to some random chosen, positioned, and possibly coloured decals and then overlay or blend them on top of the base. To handle lighting of the planet you can make a mask texture(s) that adds a corona on one side and darkens the other.

Other approaches include: using OpenGL directly to draw the scene in 3D with procedural textures or do the whole lot in a shader.

A good general approach to figuring out how achieve effects like this is to look at digital painting tutorials to understand the steps they take to create the final image. You can then take the concepts from the tutorials and apply it to what your application. Something like this: http://www.solarvoyager.com/images/tutorials/planet_tutorial_large.jpg should give you a decent idea about where to go from here. Once you have a general idea of how you can achieve your planets you can break this rather large problem into smaller sub-problems and research how to achieve them separately.

You may also want to look into general procedural generation techniques to get specific styles from random noise.

6
Graphics / Re: Creating Large Number Of Stars Efficiently
« on: January 06, 2014, 12:07:00 pm »
I believe that your problem here is that gl_TexCoord[0] is not initialised by OpenGL; you have to set the value of this variable yourself. It's is set in the vertex shader for the example you're copying from. The relevant line of code is:

gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;

This code is done in the vertex shader as it only needs to be computed for each vertex and then the fragment shader uses a linearly interpolated value of this to get the texel coordinates. You need to set this in the vertex shader as the fragment shader does not have access to gl_MultiTexCoord0.

Also I'm not sure what your end use case is but there are shaders that can draw a background of stars without having to deal with the vertices which given the large number required for a convincing space-y background may be a better option for you.

You can find one such example here: https://www.shadertoy.com/view/4dfGDM

7
Audio / Re: getStatus function give's error
« on: December 27, 2013, 12:59:52 pm »
if(snd.getStatus()==snd.Status.Paused)
Should be:
if(snd.getStatus() == Sound::Status::Paused)

You might also want to take a look at SFML's included Sound example.

8
Graphics / Re: RenderTexture won't clear properly
« on: December 27, 2013, 11:01:29 am »
I've recently run in to this bug while trying to implement post-effect shaders without copying the contents of the window and I believe that I may have come across some additional information which may help quash this bug.

When running with a shader on, renderTexture.clear() appears to be working as intended but when the shader is switched off the problem appears again. While the previous work-around of drawing a transparent shape over the entire renderTexture works I've found another work-around which may help narrow down where the problem lies. If you call window.resetGLStates() at any point in the rendering loop the problem disappears. Looking at the source for RenderTarget::resetGLStates I've tried using all of the OpenGL calls there in my code after calling window.setActive() and it doesn't seem to have any effect. So it must be one of the other parts of resetGLStates() that is correcting the problem. It also seems weird that the call is to the window and not the renderTexture to fix the problem. I tried calling it on the renderTexture but it had no effect.

So far this seems to only be affecting ATI cards. I'm running Win 7 x64 with a Radeon 7970. My graphics card drivers are Catalyst 13.12 and I'm using the pre-compiled SFML 2.1 libs statically linked. My compiler is VS2012 x64 and the problem appears in both debug and release builds. There are no error messages sent to the console window and I've broken the shader program before and the error messages were sent to the console so the error output is working.

I've attached a piece of sample code below which demonstrates the problem on my machine. The shader, the original work-around, and my work around are all toggleable from within the program by using the F1, F2, and F3 keys respectively.

// Includes
#include <SFML/Graphics.hpp>
#include <vector>
#include <cmath>
#include <iostream>


int main()
{
        // Constants
        const int windowWidth = 800, windowHeight = 600;
        const float ballWidth = 50.0f, ballHeight = 50.0f;
        sf::Vector2f ballVelocity(-300.0f,-300.0f);

        // Toggles
        bool ShaderEnabled = false;
        bool hackOneEnabled = false;
        bool hackTwoEnabled = false;
       
        // Fragment Shader Code
        const std::string fragmentShader = \
    "uniform sampler2D texture;" \
        "void main()" \
    "{" \
    "    gl_FragColor = texture2D(texture, gl_TexCoord[0].xy) * vec4(1.0, 0.0, 0.0, 1.0);" \
    "}";

        // Create Main Window
    sf::RenderWindow window(sf::VideoMode(windowWidth, windowHeight), "RenderTexture Issue Demo");
        window.setVerticalSyncEnabled(true);

        // Load Shader
        sf::Shader Shader;
        if (!Shader.loadFromMemory(fragmentShader, sf::Shader::Fragment))
        {
                std::cout << "ERROR: Unable to load shader" << std::endl;
                std::cout << "Press any key to continue..." << std::endl;
                std::cin.get();
        return EXIT_FAILURE;
        }

        // Create RenderTexture
        sf::RenderTexture renderTexture;
        renderTexture.create(windowWidth,windowHeight);

        // Create Sprite for the RenderTexture
        sf::Sprite renderSprite;
        renderSprite.setTexture(renderTexture.getTexture());

        // Create Ball
        sf::RectangleShape ball(sf::Vector2f(ballWidth,ballHeight));
        ball.setOrigin(sf::Vector2f(ballWidth * 0.5f, ballHeight * 0.5f));
        ball.setPosition(sf::Vector2f(0.5f * windowWidth, 0.5f * windowHeight));
        ball.setFillColor(sf::Color::White);

        // Create Transparent Shape with the same size as the window
        sf::RectangleShape screenClearer;
    screenClearer.setSize(sf::Vector2f(windowWidth, windowHeight));
    screenClearer.setFillColor(sf::Color::Transparent);
   
        // Time and Timers Initialisation
        sf::Clock frameTimer;
        sf::Time lastFrameTime;
        const sf::Time physicsTimeStep = sf::microseconds(10);

        // Main Loop
        while (window.isOpen())
    {
                // Simulation Timing
                lastFrameTime += frameTimer.restart();

                // Clamp the maximum frame time to prevent self-perpetuating slowdowns
                if (lastFrameTime.asMilliseconds() > 250)
                        lastFrameTime = sf::milliseconds(250);

                while (lastFrameTime >= physicsTimeStep)
                {
                        // Move Ball
                        ball.move(ballVelocity * physicsTimeStep.asSeconds());
                               
                        // Check Wall Colisions
                        if ((ball.getPosition().x - 0.5f * ballWidth) < 0)
                        {
                                ballVelocity.x = std::abs(ballVelocity.x);
                        }
                        if ((ball.getPosition().x + 0.5f * ballWidth) > windowWidth)
                        {
                                ballVelocity.x = -std::abs(ballVelocity.x);
                        }
                        if (((ball.getPosition().y - 0.5f * ballHeight) < 0) || ((ball.getPosition().y + 0.5f * ballHeight) > windowHeight))
                                ballVelocity.y = -ballVelocity.y;

                        // Advance Simulation Step
                        lastFrameTime -= physicsTimeStep;
                }

                // Render
                renderTexture.clear();
                renderTexture.draw(ball);
               
                // Hack to fix bug where the renderTexture doesn't clear
                if (hackOneEnabled)
                        renderTexture.draw(screenClearer);             
               
                renderTexture.display();
               
                // Alternative hack to fix aforementioned bug.
                // It doesn't seem to matter when this happens as long as it happens at least once per loop.
                if (hackTwoEnabled)
                        window.resetGLStates();                                

                window.clear();

                if (ShaderEnabled)
                        window.draw(renderSprite, &Shader);
                else
                        window.draw(renderSprite);
       
                window.display();
               
                // Event Handler
        sf::Event event;
        while (window.pollEvent(event))
        {
                        switch(event.type)
                        {
                                case sf::Event::Closed:
                                        window.close();
                                        break;
                                case sf::Event::KeyPressed:
                                {
                                        // Toggle Shader
                                        if (event.key.code == sf::Keyboard::F1)
                                                ShaderEnabled = !ShaderEnabled;
                                        // Toggle first RenderTexture clearing hack (Transparent texture over screen)
                                        if (event.key.code ==sf::Keyboard::F2)
                                                hackOneEnabled = !hackOneEnabled;
                                        // Toggle second RenderTexture clearing hack (window.resetGLStates())
                                        if (event.key.code ==sf::Keyboard::F3)
                                                hackTwoEnabled = !hackTwoEnabled;
                                        break;
                                }
                        }
        }
    }
    return EXIT_SUCCESS;
}

Pages: [1]
anything