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

Pages: [1] 2
1
Graphics / Re: sf::Text appearing with an odd offset
« on: October 31, 2012, 08:54:47 pm »
I had seen that, but thought it was to do with whitespaces not counting properly, and the fact that the bounding box changes size vertically depending on the characters contained in the text.

My problem here is that it appears to be impossible to centre even the reported bounding box. Even without setting the origin of the text to half its size, the topleft of the bounding box will still not be drawn at the centre of the blue rectangle.

Apologies if I've misunderstood.

2
Graphics / sf::Text appearing with an odd offset
« on: October 31, 2012, 08:27:47 pm »
Using latest SFML2 from giit (LaurentGomila-SFML-c02e375)

I seem to be unable to centre sf::Text within a box without manually tuning it. Setting the origin of the text to the centre of its bounds results in the text (and its bounding box) showing with an offset from the expected position.



Minimal code:

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "Text Test");
    window.setFramerateLimit(60);

    sf::RectangleShape shape(sf::Vector2f(50, 50));
    shape.setPosition(100, 100);
    shape.setFillColor(sf::Color::Blue);

    sf::Font font;
    font.loadFromFile("arial.ttf");

    sf::Text text("A", font, 20);
    text.setOrigin(text.getLocalBounds().width/2, text.getLocalBounds().height/2);
    text.setColor(sf::Color::White);
    text.setPosition(125,125);

    sf::RectangleShape textbox(sf::Vector2f(text.getLocalBounds().width, text.getLocalBounds().height));
    textbox.setPosition(text.getGlobalBounds().left, text.getGlobalBounds().top);
    textbox.setFillColor(sf::Color::Transparent);
    textbox.setOutlineColor(sf::Color::White);
    textbox.setOutlineThickness(1);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();

        window.draw(shape);
        window.draw(textbox);
        window.draw(text);

        window.display();
    }

    return EXIT_SUCCESS;
}

Unless I've missed something, i'd expect the above code to result in the letter (or at least its bounding box) being centred in the bigger blue box. Whether or not the origin for text is set, there still seems to be an odd offset from the expected position.

Having searched, this thread - http://en.sfml-dev.org/forums/index.php?topic=9235.0 - appears to be related, though I can't see a resolution for it.

Any thoughts on why it's happening, or if it is indeed a bug?

Thanks!

3
Graphics / Framerate, rendering and optimisations
« on: February 16, 2012, 09:41:29 pm »
Quote
OpenGL renderer string: Software Rasterizer


That certainly doesn't look right. The intel driver should be sitting in that spot showing something along the lines of 'Mesa DRI Intel(R)'. I suspect that whatever you did to allow it to boot through after installing the nvidia driver has blacklisted the intel one.

At this point, i'd advise you to follow the instructions for properly removing the nvidia driver in the link I gave you, and then follow the instructions for installing bumblebee once you've got acceleration back under the intel chip.

This will mean that your laptop will be using the intel integrated chip for all standard acceleration (such as desktop effects), and you will be able to start programs using the optirun prefix to render them with your nvidia chip. It should also allow you to turn off the nvidia card when not in use.

As to reinstalling, as long as you can be bothered, there is no particular reason to avoid it. Especially if you keep your root and home partitions separate. Repairing it is, of course, a preferable solution however.

Ultimately this is probably a better question for the forum of whatever distro you're using, as it's not directly related to sfml!

4
Graphics / Framerate, rendering and optimisations
« on: February 16, 2012, 01:08:20 pm »
I assume you're using a laptop, and so the problem is likely to do with nvidia optimus, and its poor support in linux.

Likely you'll want to give this a careful read

Essentially bumblebee/ironhide is currently your only option to actually use the nvidia card. Do not install the nvidia drivers directly, they will cause you to lose all acceleration, even from the integrated chip.

Aside from that, what tank said.

5
General / SFML Window not showing!!!
« on: December 24, 2011, 04:33:40 am »
The answer has been provided! You're missing the point of what everyone has been saying i'm afraid.

Every frame you blank the screen, draw whatever you want to draw, and then display it. This means that to remove something previously displayed  from the current display, you simply don't draw it anymore.

Code: [Select]

while(running)
{
// events
// logic

App.Clear(); // Blank the screen

   if(collision == false) // If there is no collision
   {
  App.Draw(sprite) // Draw the sprite
   }

   App.Display(); // Finally display what we've drawn this frame
}  


This is very simplistic, and you'll want to do a lot more than that with any actual game object, but it's the idea people have been trying to get across. You only call draw on the sprite during the frame if there is no collision, if there IS a collision, then draw doesn't get called, and the sprite will dissapear from the screen.

You don't actively undraw anything, at any point. Essentially, every frame you want to display a freshly drawn image.

6
Graphics / Applying a shader seem to cause a massive CPU jump
« on: August 26, 2011, 12:01:32 am »
I'm afraid my attempts at reducing this to a complete and minimal code have resulted in nothing useful, as the cpu jump is not evident. This is, I suppose, probably a signifier of where the problem lies, however I currently remain ignorant despite my efforts :(

Essentially i've been following the dynamic lighting tutorial found here: http://www.sfml-dev.org/wiki/fr/sources/lightmanager

I have a working implementation, and while the light is stationary the program uses maybe 1/2% cpu. If I apply the blur.sfx shader from the sfml examples folder, I attain the desired effect, but my cpu usage jumps to almost an entire core.

The lights are drawn to a window sized rendertexture, and the draw function  for the resulting rendertexture looks like this:

Code: [Select]
void LightManager::Draw(sf::RenderWindow &window)
{
    if (moved)
    {
        rSprite.SetTexture(rTex.GetTexture());
        rSprite.SetBlendMode(sf::Blend::Multiply);
    }

    window.Draw(rSprite, BlurEffect);
}


Where rTex is the rendertexture and rSprite is the corresponding sprite used to draw it. The shader is loaded and configured once in an Init() function, and Draw is the only call that it is involved in thereafter. The program is also FrameLimited to 120.

Computer wise i'm using an Intel T6500 cpu with Nvidia g105m in Ubuntu 64 bit using an up to date proprietary Nvidia driver. The problem is also apparent on the same computer in Win 7 64 bit after testing.

As i've not provided a minimal code I don't expect any concrete solutions, but I'm hoping for a few pointers as to why this might be happening. Any suggestions on where to look would be greatly appreciated.

Edit: I just tested the program on a friends laptop, using an ATI hd4300 series card and the cpu usage was exactly what i'd expect. The shader made no noticeable difference to cpu usage whether applied or not. I'm left fairly puzzled, as I'm fairly certain my computer with the nvidia g105m has a hardware implementation of pixel shaders.

7
Audio / Audio crash on exit
« on: August 06, 2011, 09:48:43 pm »
Ah, righto. Are there any workarounds to ensure the program closes, or do I need to put up with it until sfml2.x?

Thanks for the swift reply!

8
Audio / Audio crash on exit
« on: August 05, 2011, 12:28:41 am »
Using the latest sfml2 snapshot (SFML-732b789) I'm getting a pretty consistent audio crash upon exit, sometimes the program hangs, sometimes it just returns odd values and manages to shutdown.

The callstack upon crash is:

#0 76B64CBC   ole32!CoVrfCheckThreadState() (C:\Windows\syswow64\ole32.dll:??)
#1 76B64C26   ole32!CoVrfCheckThreadState() (C:\Windows\syswow64\ole32.dll:??)
#2 76B64D3C   ole32!CoVrfCheckThreadState() (C:\Windows\syswow64\ole32.dll:??)
#3 76B65446   ole32!CoVrfCheckThreadState() (C:\Windows\syswow64\ole32.dll:??)
#4 76B65A5B   ole32!CoFileTimeToDosDateTime() (C:\Windows\syswow64\ole32.dll:??)
#5 76B65916   ole32!CoFileTimeToDosDateTime() (C:\Windows\syswow64\ole32.dll:??)
#6 76B65877   ole32!CoFileTimeToDosDateTime() (C:\Windows\syswow64\ole32.dll:??)
#7 76B65830   ole32!CoFileTimeNow() (C:\Windows\syswow64\ole32.dll:??)
#8 74FBE880   DirectSoundCaptureCreate() (C:\Windows\SysWOW64\dsound.dll:??)
#9 74FBE668   DirectSoundCaptureCreate() (C:\Windows\SysWOW64\dsound.dll:??)
#10 74FBE43A   DirectSoundCaptureCreate() (C:\Windows\SysWOW64\dsound.dll:??)
#11 74FC3EA0   DirectSoundCaptureCreate() (C:\Windows\SysWOW64\dsound.dll:??)
#12 74FBE43A   DirectSoundCaptureCreate() (C:\Windows\SysWOW64\dsound.dll:??)
#13 74FC35E9   DirectSoundCaptureCreate() (C:\Windows\SysWOW64\dsound.dll:??)
#14 74FC3A7C   DirectSoundCaptureCreate() (C:\Windows\SysWOW64\dsound.dll:??)
#15 74FC3646   DirectSoundCaptureCreate() (C:\Windows\SysWOW64\dsound.dll:??)
#16 64055006   alcCloseDevice() (D:\My Documents\Repo\Prog\bin\Debug\openal32.dll:??)
#17 00000000   0x07c80048 in ??() (??:??)
#18 00000000   0x00000001 in ??() (??:??)
#19 00000000   0x0028fdbc in ??() (??:??)
#20 00000000   0x003b2f88 in ??() (??:??)
#21 6278181A   ~AudioDevice(this=0x4) (D:\My Documents\Software\SFML2-732b789\src\SFML\Audio\AudioDevice.cpp:85)
#22 00000000   0x00000003 in ??() (??:??)


This is using codeblocks 10.05 with mingw32 4.4.1 on win 7 64 bit. The same problem does not occur when the program is run in linux. I'm using the extlibs/bin/x86 dlls that were supplied with this snapshot.

Any ideas would be appreciated! Is this likely to be something i'm doing wrong, or a possible bug?

9
Graphics / SFML 2 Tilemap issue
« on: August 03, 2011, 11:12:46 pm »
I assume you've adapted the collision class on the wiki to sfml2 if that's what you're using? The new way rectangles are defined being the major change that will silently mess it up unless you've adjusted.

The other thing is what are you testing against what? Are you optimising the amount of collision checks you make, or are you testing everything against everything every frame?

10
General / Colision with SFML2
« on: February 27, 2011, 05:27:07 pm »
Try this:

Code: [Select]
/*
 * File:   collision.cpp
 * Author: Nick
 *
 * Created on 30 January 2009, 11:02
 */
#include <SFML/Graphics.hpp>
#include "collision.h"

Collision::Collision() {
}

Collision::~Collision() {
}

sf::IntRect Collision::GetAABB(const sf::Sprite& Object) {

    //Get the top left corner of the sprite regardless of the sprite's center
    //This is in Global Coordinates so we can put the rectangle back into the right place
    sf::Vector2f pos = Object.TransformToGlobal(sf::Vector2f(0, 0));

    //Store the size so we can calculate the other corners
    sf::Vector2f size = Object.GetSize();

    float Angle = Object.GetRotation();

    //Bail out early if the sprite isn't rotated
    if (Angle == 0.0f) {
        return sf::IntRect(static_cast<int> (pos.x),
                static_cast<int> (pos.y),
                static_cast<int> (pos.x + size.x),
                static_cast<int> (pos.y + size.y));
    }

    //Calculate the other points as vectors from (0,0)
    //Imagine sf::Vector2f A(0,0); but its not necessary
    //as rotation is around this point.
    sf::Vector2f B(size.x, 0);
    sf::Vector2f C(size.x, size.y);
    sf::Vector2f D(0, size.y);

    //Rotate the points to match the sprite rotation
    B = RotatePoint(B, Angle);
    C = RotatePoint(C, Angle);
    D = RotatePoint(D, Angle);

    //Round off to int and set the four corners of our Rect
    int Left = static_cast<int> (MinValue(0.0f, B.x, C.x, D.x));
    int Top = static_cast<int> (MinValue(0.0f, B.y, C.y, D.y));
    int Right = static_cast<int> (MaxValue(0.0f, B.x, C.x, D.x));
    int Bottom = static_cast<int> (MaxValue(0.0f, B.y, C.y, D.y));

    Left += pos.x;
    Top  += pos.y;

    //Create a Rect from out points and move it back to the correct position on the screen
    sf::IntRect AABB = sf::IntRect(Left, Top, size.x, size.y);
    //AABB.Offset(static_cast<int> (pos.x), static_cast<int> (pos.y));
    return AABB;
}

float Collision::MinValue(float a, float b, float c, float d) {
    float min = a;

    min = (b < min ? b : min);
    min = (c < min ? c : min);
    min = (d < min ? d : min);

    return min;
}

float Collision::MaxValue(float a, float b, float c, float d) {
    float max = a;

    max = (b > max ? b : max);
    max = (c > max ? c : max);
    max = (d > max ? d : max);

    return max;
}

sf::Vector2f Collision::RotatePoint(const sf::Vector2f& Point, float Angle) {
    Angle = Angle * RADIANS_PER_DEGREE;
    sf::Vector2f RotatedPoint;
    RotatedPoint.x = Point.x * cos(Angle) + Point.y * sin(Angle);
    RotatedPoint.y = -Point.x * sin(Angle) + Point.y * cos(Angle);
    return RotatedPoint;
}

bool Collision::PixelPerfectTest(const sf::Sprite& Object1, const sf::Sprite& Object2, sf::Uint8 AlphaLimit) {
        //Get AABBs of the two sprites
    sf::IntRect Object1AABB = GetAABB(Object1);
    sf::IntRect Object2AABB = GetAABB(Object2);

    sf::IntRect Intersection;

    if (Object1AABB.Intersects(Object2AABB, Intersection)) {

        //We've got an intersection we need to process the pixels
        //In that Rect.

        //Bail out now if AlphaLimit = 0
        if (AlphaLimit == 0) return true;

        //There are a few hacks here, sometimes the TransformToLocal returns negative points
        //Or Points outside the image.  We need to check for these as they print to the error console
        //which is slow, and then return black which registers as a hit.

        sf::IntRect O1SubRect = Object1.GetSubRect();
        sf::IntRect O2SubRect = Object2.GetSubRect();

        sf::Vector2i O1SubRectSize(O1SubRect.Width, O1SubRect.Height);
        sf::Vector2i O2SubRectSize(O2SubRect.Width, O2SubRect.Height);

        sf::Vector2f o1v;
        sf::Vector2f o2v;
        //Loop through our pixels
        for (int i = Intersection.Left; i < (Intersection.Left+Intersection.Width); i++) {
            for (int j = Intersection.Top; j < (Intersection.Top+Intersection.Height); j++) {

                o1v = Object1.TransformToLocal(sf::Vector2f(i, j)); //Creating Objects each loop :(
                o2v = Object2.TransformToLocal(sf::Vector2f(i, j));

                //Hack to make sure pixels fall withint the Sprite's Image
                if (o1v.x > 0 && o1v.y > 0 && o2v.x > 0 && o2v.y > 0 &&
                        o1v.x < O1SubRectSize.x && o1v.y < O1SubRectSize.y &&
                        o2v.x < O2SubRectSize.x && o2v.y < O2SubRectSize.y) {

                    //If both sprites have opaque pixels at the same point we've got a hit
                    if ((Object1.GetPixel(static_cast<int> (o1v.x), static_cast<int> (o1v.y)).a > AlphaLimit) &&
                            (Object2.GetPixel(static_cast<int> (o2v.x), static_cast<int> (o2v.y)).a > AlphaLimit)) {
                        return true;
                    }
                }
            }
        }
        return false;
    }
    return false;
}

bool Collision::CircleTest(const sf::Sprite& Object1, const sf::Sprite& Object2) {
    //Simplest circle test possible
    //Distance between points <= sum of radius

    float Radius1 = (Object1.GetSize().x + Object1.GetSize().y) / 4;
    float Radius2 = (Object2.GetSize().x + Object2.GetSize().y) / 4;
    float xd = Object1.GetPosition().x - Object2.GetPosition().x;
    float yd = Object1.GetPosition().y - Object2.GetPosition().y;

    return sqrt(xd * xd + yd * yd) <= Radius1 + Radius2;
}

//From Rotated Rectangles Collision Detection, Oren Becker, 2001

bool Collision::BoundingBoxTest(const sf::Sprite& Object1, const sf::Sprite& Object2) {

    sf::Vector2f A, B, C, BL, TR;
    sf::Vector2f HalfSize1 = Object1.GetSize();
    sf::Vector2f HalfSize2 = Object2.GetSize();

    //For somereason the Vector2d divide by operator
    //was misbehaving
    //Doing it manually
    HalfSize1.x /= 2;
    HalfSize1.y /= 2;
    HalfSize2.x /= 2;
    HalfSize2.y /= 2;
    //Get the Angle we're working on
    float Angle = Object1.GetRotation() - Object2.GetRotation();
    float CosA = cos(Angle * RADIANS_PER_DEGREE);
    float SinA = sin(Angle * RADIANS_PER_DEGREE);

    float t, x, a, dx, ext1, ext2;

    //Normalise the Center of Object2 so its axis aligned an represented in
    //relation to Object 1
    C = Object2.GetPosition();

    C -= Object1.GetPosition();

    C = RotatePoint(C, Object2.GetRotation());

    //Get the Corners
    BL = TR = C;
    BL -= HalfSize2;
    TR += HalfSize2;

    //Calculate the vertices of the rotate Rect
    A.x = -HalfSize1.y*SinA;
    B.x = A.x;
    t = HalfSize1.x*CosA;
    A.x += t;
    B.x -= t;

    A.y = HalfSize1.y*CosA;
    B.y = A.y;
    t = HalfSize1.x*SinA;
    A.y += t;
    B.y -= t;

    t = SinA * CosA;

    // verify that A is vertical min/max, B is horizontal min/max
    if (t < 0) {
        t = A.x;
        A.x = B.x;
        B.x = t;
        t = A.y;
        A.y = B.y;
        B.y = t;
    }

    // verify that B is horizontal minimum (leftest-vertex)
    if (SinA < 0) {
        B.x = -B.x;
        B.y = -B.y;
    }

    // if rr2(ma) isn't in the horizontal range of
    // colliding with rr1(r), collision is impossible
    if (B.x > TR.x || B.x > -BL.x) return false;

    // if rr1(r) is axis-aligned, vertical min/max are easy to get
    if (t == 0) {
        ext1 = A.y;
        ext2 = -ext1;
    }// else, find vertical min/max in the range [BL.x, TR.x]
    else {
        x = BL.x - A.x;
        a = TR.x - A.x;
        ext1 = A.y;
        // if the first vertical min/max isn't in (BL.x, TR.x), then
        // find the vertical min/max on BL.x or on TR.x
        if (a * x > 0) {
            dx = A.x;
            if (x < 0) {
                dx -= B.x;
                ext1 -= B.y;
                x = a;
            } else {
                dx += B.x;
                ext1 += B.y;
            }
            ext1 *= x;
            ext1 /= dx;
            ext1 += A.y;
        }

        x = BL.x + A.x;
        a = TR.x + A.x;
        ext2 = -A.y;
        // if the second vertical min/max isn't in (BL.x, TR.x), then
        // find the local vertical min/max on BL.x or on TR.x
        if (a * x > 0) {
            dx = -A.x;
            if (x < 0) {
                dx -= B.x;
                ext2 -= B.y;
                x = a;
            } else {
                dx += B.x;
                ext2 += B.y;
            }
            ext2 *= x;
            ext2 /= dx;
            ext2 -= A.y;
        }
    }

    // check whether rr2(ma) is in the vertical range of colliding with rr1(r)
    // (for the horizontal range of rr2)
    return !((ext1 < BL.y && ext2 < BL.y) ||
            (ext1 > TR.y && ext2 > TR.y));

}


The problem is that the latter two arguments rect takes was changed in sfml2 (takes left,top,width,height now), as a result GetAABB needs a tweak. Top and Left also need manually offsetting to return the co-ords to global as well, as Offset() no longer exists.

11
Network / Ftp connection will login, but then does nothing
« on: February 24, 2011, 12:02:35 pm »
That would explain it! Cheers for the quick reply.

12
Network / Ftp connection will login, but then does nothing
« on: February 23, 2011, 11:31:24 pm »
I'm attempting to set up a simple program to grab a few files from an ftp server, and so i've been following the documentation online. At the moment the program is very short, and looks like this:

Code: [Select]
#include <SFML/Network.hpp>
#include <fstream>
#include <iostream>

using namespace std;

int main()
{
    // Create a new FTP client
    sf::Ftp ftp;

    // Connect to the server
    sf::Ftp::Response response = ftp.Connect("thesiteaddress");
    if (response.IsOk())
        cout << "Connected" << std::endl;

    // Log in
    response = ftp.Login("username", "password");
    if (response.IsOk())
        cout << "Logged in" << std::endl;

    // Print the working directory
    sf::Ftp::DirectoryResponse directory = ftp.GetWorkingDirectory();
    if (directory.IsOk())
    std::cout << "Working directory: " << directory.GetDirectory() << std::endl;


     // Download a file to this new directory
    response = ftp.Download("blah.txt", "file", sf::Ftp::Ascii);
    if (response.IsOk())
    {
        cout << "File Downloaded" << endl;
    }
    else
    {
        cout << response.GetStatus() << endl;
    }


    ftp.Disconnect();

    return EXIT_SUCCESS;
}


Where the site address/username/password are replaced with actual values.

This code results in the following output when compiled and run:

Quote
Connected
Logged in
Working directory: /
1001


There is a long wait between working directory, and GetStatus() returning 1001. I've noticed that using something like filezilla i'm unable to get this ftp server to work unless I set it to "active" under Transfer mode.

Any suggestions on what to do, or indeed, pointing out any glaring errors in the code would be greatly appreciated!

13
General / Return sprite to collision function from inside Vector
« on: January 11, 2011, 07:50:12 am »
Once I declared sf::Sprite sprite inside Entity rather than Player everything started working. So this is solved!

14
General / Return sprite to collision function from inside Vector
« on: January 11, 2011, 06:05:06 am »
I have an Entity baseclass which the classes Player and Enemy Inherit.
Code: [Select]

class Entity
{
  public:

    virtual void Update(sf::RenderWindow &window) {};
    virtual void Draw(sf::RenderWindow &window) {};

};


Both player and enemy contain a sprite object that looks like this:
Code: [Select]

class Player : Entity
{
   public:

   sf::Sprite sprite

    void Update(sf::RenderWindow &window);
    void Draw(sf::RenderWindow &window)
}

Player and Enemy are created inside a vector which is set up like this:

Code: [Select]
class EntityManager
{
   public:
   void CollisionCheck();
   private:
   std::vector<Entity*> entityVector;
}


I'm looking to use the collision detection function from the wiki which is of this form:

Code: [Select]
bool Collision::CircleTest(const sf::Sprite& Object1, const sf::Sprite& Object2)

So I'm trying to do something like this:

Code: [Select]
void EntityManager::ColCheck()
{
   if (Collision::CircleTest(entityVector[0]->sprite, entityVector[1]->sprite))
      {
         cout << "COLLISION\n";
      }
}


This results in the following compile error: ‘class Entity’ has no member named ‘sprite’

I'm unsure how to create a dummy sprite in Entity so that I can access the player and enemy sprites using the above method. Is this possible?

I'm stumped and would greatly appreciate any help anyone can offer!

15
Window / Problem trying setup and draw window using multiple files
« on: October 04, 2010, 08:10:24 pm »
Sorry, I should have supplied more information. The program would compile and run, but would spawn a window that promptly disappeared.

What you've suggested has fixed it perfectly, cheers!

Pages: [1] 2
anything