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

Pages: [1] 2
1
Graphics / Settings texture wrapping to repeat using sf::Renderer
« on: June 08, 2011, 08:16:21 pm »
Ah, I didn't know that, but it works perfectly now  :) .

2
Graphics / Settings texture wrapping to repeat using sf::Renderer
« on: June 08, 2011, 07:16:08 pm »
I was just trying out some ways to generate a racing track from a few points, generating the vertices worked out right but I'm having some problems with the texture coordinates. I currently have a distance variable which keeps track of the current track distance and a textureSize variable which determines how much pixels of the track the texture should cover.

The code which calculates the uv coordinates:
Code: [Select]

float textureSize = 64.0f //The texture is 64x64 so this should display it at the real scale.

// The two sides of the point in the track.
leftVertex.texCoords = sf::Vector2f(0.0f, distance / textureSize);
rightVertex.texCoords = sf::Vector2f(1.0f, distance / textureSize);


I render the vertices like this:
Code: [Select]

renderer.SaveGLStates();
   
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_WRAP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_WRAP);
   
renderer.SetTexture(&m_Texture);
renderer.Begin(sf::Renderer::TriangleStrip);
    for (int i = 0; i < m_sideVertices.size(); i++)
    {
        renderer.AddVertex(m_sideVertices[i].position.x,
                           m_sideVertices[i].position.y,
                           m_sideVertices[i].texCoords.x,
                           m_sideVertices[i].texCoords.y,
                           sf::Color::White);
    }
renderer.End();

renderer.RestoreGLStates();


But it looks like this (red lines show where the vertices are):


As you can see the beginning of the track (the left side) is textured correctly because the v coordinates are within the 0-1 range, after that the texture gets stretched out.

So is setting the texture wrapping mode to GL_REPEAT not working or am I using the wrong texture coordinates?

3
General / Get positional data from View in SFML 2.0
« on: May 07, 2011, 10:08:47 am »
I had some problems with the GetCenter() function because the View logic changed in SFML 2.0, I corrected it and everything works fine again.

4
General / Get positional data from View in SFML 2.0
« on: May 06, 2011, 09:20:00 pm »
I just changed to SFML 2.0 and all went well until I couldn't find a way to retrieve data about the position of the current sf::View. I have a tile map and I only want to draw the tiles that are currently visible. The only way I thought of was to retrieve the data from the projection matrix but it seems kind of hacky :?.

5
General / Window only updates when mouse is moved over it.
« on: April 23, 2011, 10:12:16 pm »
Never mind... I made a stupid mistake, I quickly wrote the event loop and never looked at it again, but I accidentally included the updating and rendering inside it. I feel stupid  :x.

6
General / Window only updates when mouse is moved over it.
« on: April 23, 2011, 09:52:40 pm »
I succeeded in disabling compositing and the problem still remains  :(.

7
Graphics / Zoom to mouse (as in Google maps)?
« on: April 16, 2011, 01:00:21 pm »
I worked on a little demo so you can try to understand what is going on, change a few of the values and see what happens.

I hope this is the effect you wanted :P.

Code: [Select]

#include <SFML/Graphics.hpp>
#include <iostream>
#include <math.h>

float lerp(float value, float start, float end)
{
    return start + (end - start) * value;
}

int main()
{
    sf::RenderWindow App(sf::VideoMode(800, 600), "SFML window");

    const sf::Input& input = App.GetInput();

    // Make a few shapes for testing.
    sf::Shape rect1 = sf::Shape::Rectangle(10, 10, 60, 60, sf::Color(255, 0, 0));
    sf::Shape circle1 = sf::Shape::Circle(100, 100, 40, sf::Color(0, 255, 0));
    sf::Shape line1 = sf::Shape::Line(200, 200, 300, 300, 2, sf::Color(0, 0, 255));

    sf::Vector2f currentCenter;
    sf::Vector2f targetCenter;
    float targetZoom = 0.0f;
    float currentZoom = 0.0f;
    float previousZoom = 0.0f;
    bool zooming = false;

    float lerpFactor = 0.01f; // The speed of the zooming.

    while (App.IsOpened())
    {
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            if (Event.Type == sf::Event::Closed)
                App.Close();
            else if(Event.Type == sf::Event::MouseWheelMoved)
            {
                zooming = true;

                // Zooming in or out.
                if (Event.MouseWheel.Delta == 1)
                    targetZoom = 1.3f;
                else
                    targetZoom = 0.7f;

                currentZoom = 1.0f;
                previousZoom = currentZoom;

                // Store the current center of the view and our target (the position of the mouse).
                currentCenter = App.GetDefaultView().GetCenter();
                targetCenter = App.ConvertCoords(input.GetMouseX(), input.GetMouseY(), &App.GetDefaultView());
            }
        }

        if (zooming)
        {
            // Interpolate between the current zoom and the target zoom for a smooth effect.
            currentZoom = lerp(lerpFactor, currentZoom, targetZoom);
            App.GetDefaultView().Zoom(1.0f + (currentZoom - previousZoom));

            // Interpolate the between the current center of the view and the target.
            currentCenter.x = lerp(lerpFactor, currentCenter.x, targetCenter.x);
            currentCenter.y = lerp(lerpFactor, currentCenter.y, targetCenter.y);
            App.GetDefaultView().SetCenter(currentCenter);

            // Store the previous zoom because we will need the difference between the previous and current zoom.
            // This is because sf::View::Zoom zooms relative to the current zoom.
            previousZoom = currentZoom;

            // If the difference between the current and previous zoom is less then 0.01, stop zooming.
            // Linear interpolation will never reach the target value so we stop here.
            if (fabs(targetZoom - currentZoom) < 0.01f)
                zooming = false;
        }

        App.Clear();

        App.Draw(rect1);
        App.Draw(circle1);
        App.Draw(line1);

        App.Display();
    }

    return 0;
}


8
Graphics / Zoom to mouse (as in Google maps)?
« on: April 16, 2011, 12:04:09 pm »
Is this all of the code in which you implemented the zooming? Because your missing quite a lot.

9
General / Window only updates when mouse is moved over it.
« on: April 16, 2011, 11:43:00 am »
I think I'm using metacity with compositing enabled, but I'm not too sure as I've just started using Ubuntu.

10
Graphics / Zoom to mouse (as in Google maps)?
« on: April 16, 2011, 11:19:29 am »
You could define a linear interpolation function like this:

Code: [Select]

float lerp(float value, float start, float end)
{
    return start + (end - start) * value;
}


Then set the center of the View with sf::View::SetCenter(mouseX, mouseY) and zoom into that position with the result of the lerp with sf::View::Zoom().

Some pseudo code:
Code: [Select]

targetzoom = 0
currentzoom = 0
previouszoom = 0
zooming = false

void update()
{
    if (move mousewheel)
    {
        zooming = true

        targetzoom = 0.5
        currentzoom = 0
    }

    if (zooming)
    {
        currentzoom = lerp(0.01, currentzoom, targetzoom)

        view.Zoom(currentzoom - previouszoom) // Zoom is relative.

        previouszoom = currentzoom

        if (abs(targetzoom - currentzoom) < 0.1) // Lerp will never reach the target.
            zooming = false
    }
}


11
General / Window only updates when mouse is moved over it.
« on: April 16, 2011, 10:52:28 am »
I just switched to Ubuntu and tried using SFML, however my RenderWindow only updates when I move the mouse cursor over it.

I use the code from the tutorial about Sprites and move the sprite by a tiny amount each frame. If I move the mouse for a few seconds the window keeps updating after I stop moving it, but after a few seconds the window stops updating.

Code: [Select]

#include <SFML/Graphics.hpp>
 
 int main()
 {
     sf::RenderWindow App(sf::VideoMode(800, 600), "SFML window");

     sf::Image Image;
     Image.LoadFromFile("data/circle.png");
     sf::Sprite Sprite(Image);

     while (App.IsOpened())
     {
         sf::Event event;
         while (App.GetEvent(event))
         {
             if (event.Type == sf::Event::Closed)
                 App.Close();
         }

         sprite.Move(20 * App.GetFrameTime(), 0);
 
         // Clear screen
         App.Clear();
 
         App.Draw(sprite);
 
         // Update the window
         App.Display();
     }
 
     return 0;
 }

12
General / Game won't start anymore
« on: December 15, 2010, 06:07:52 pm »
Ok I changed the libs to the static ones and it works now.
But now there are a few graphics artefacts that weren't there before (the areas where images were drawn the frame before are white), could this be the new drivers?

13
General / Game won't start anymore
« on: December 15, 2010, 11:47:06 am »
Yes i also changed my drivers! Can you also downgrade them?

14
General / Game won't start anymore
« on: December 15, 2010, 07:19:27 am »
It doesn't even reach the "int main()" when I put a breakpoint there, in other projects without SFML it does  :x. Any game which uses SFML now stopped working, and it doesn't give any errors :(.

15
General / Game won't start anymore
« on: December 14, 2010, 08:20:26 pm »
Hello, I've a bit of a problem here, I continued working on my game and all of a sudden it won't start any more  :shock:. When I click the .exe it does nothing for about 5 seconds and then a console window pops up which doesn't close directly when you try to. It works on the computer of a friend of mine so it's not in the code.

I know it's not a lot of information but is there anything I might have changed in my computer that can cause this?

Pages: [1] 2
anything