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.


Topics - GarrickW

Pages: [1] 2
1
General / Compiling SFML from source, CMake problems
« on: September 30, 2013, 06:20:58 am »
So I am trying to compile SFML 2.1 from the source, and I am having some issues with CMake.

I did my best to follow the tutorial to the letter, but when I hit Configure in the CMake window, I get the following errors I don't understand:

CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER_ENV_VAR
CMake Error: Could not find cmake module file:C:/Users/Guerric/Downloads/SFML Custom/CMakeFiles/2.8.11.2/CMakeCCompiler.cmake
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER_ENV_VAR
CMake Error: Could not find cmake module file:C:/Users/Guerric/Downloads/SFML Custom/CMakeFiles/2.8.11.2/CMakeCXXCompiler.cmake
Configuring incomplete, errors occurred!

I used the
set PATH=%PATH%;your_mingw_folder\bin
command to set the PATH variable (obviously with my own installation directory), and tried running CMake both from the desktop icon and from the command prompt using cmake-gui.

How can I solve these and get to compiling SFML?

2
General / static sf::Font initialization crashes program in MinGW4.7.1
« on: September 29, 2013, 06:45:56 pm »
So I recently upgraded to MinGW 4.7.1 and, lo and behold, it broke my program.

The debugger suggests that the culprit is a static sf::Font object I initialize in my Interface class (from Interface.cpp):

sf::Font Interface::m_Font;

The debugger says:

#0 669815E2     sf::Font::Font() () (C:\Users\Guerric\Desktop\CREATI~1\GAME-D~1\sfml-graphics-2.dll:??)
#1 0040521E     __static_initialization_and_destruction_0(__initialize_p=1, __priority=65535) (C:\Users\Guerric\Desktop\Creative Works\Game - Digitesque Prison\Interface.cpp:11)
#2 00405272     _GLOBAL__sub_I__ZN9Interface5m_AppE() (C:\Users\Guerric\Desktop\Creative Works\Game - Digitesque Prison\Interface.cpp:263)
#3 0042719A     __do_global_ctors () (??:??)
#4 004010DC     __mingw_CRTStartup () (??:??)
#5 00401295     mainCRTStartup () (??:??)

Any ideas on what is going wrong here?

3
So I have a Sprite, which itself has a Texture, and which may be scaled/rotated/translated.  I should probably also note that it is centered, i.e.

Sprite.setOrigin(Sprite.getLocalBounds().width / 2, Sprite.getLocalBounds().height / 2);

I also have a given Point (sf::Vector2f) in global space.

If the point is within the Sprite's local bounds, I want to figure out the color of the exact pixel of the source Texture the point corresponds to.

Obviously I somehow need to convert from global to local space, but I'm not sure how to do this.  My previous attempt was:

//I also tried without subtracting the position,
//since I assume that the sprite's translation is also included in its transform
Point.x -= Sprite.getPosition().x;
Point.y -= Sprite.getPosition().y;

//I also tried getTransform(), which unsurprisingly didn't work either
Point = Sprite.getInverseTransform().transformPoint(Point);

sf::Color PointColor = Sprite.getTexture()->copyToImage().getPixel(Point.x, Point.y);

What is the correct way of doing this?

4
Audio / Modifying length of a sound sample?
« on: June 25, 2013, 03:00:22 am »
I am currently writing a program in which the user can play a simple virtual piano.  I load a sample representing a middle C, and I change the pitch of that sound to get the other notes the user requests.  However, I also want the player to be able to play notes of different lengths - quarter notes, half notes, etc.

Is there a way to dynamically alter the length of the sample?  I've been mucking around in Audacity trying to change the sample length to have multiple samples (I only really want five - staccato, quarter, half, three-quarter and full), but doing so makes the sample sound very scratchy.

If there is no way to do this, does anybody know what other approaches I may try?

5
Audio / Sounds stop playing when other Sounds are deleted?
« on: June 06, 2013, 09:13:58 pm »
So I'm not 100% sure what is going wrong here, but the following code is not working as expected.

void Cycle(float Time, float Pitch)
{
    //Reduce the timer
    m_PlayTimer -= Time;

    //If it's zero, play the sample
    if (m_PlayTimer <= 0.0)
    {
        //Add the sound!
        m_SoundList.push_back(sf::Sound());
        unsigned short NewSound = m_SoundList.size() - 1;
        m_SoundList[NewSound].setBuffer(*SoundManager::GetSoundBuffer(1));
        m_SoundList[NewSound].setVolume(30.0);
        m_SoundList[NewSound].setPitch(Pitch);
        m_SoundList[NewSound].play();

        //Restore a positive value to the timer
        m_PlayTimer = 1.0;
    }

    //Cull finished sounds
    for (unsigned int ii = 0; ii < m_SoundList.size(); ++ii)
    {
        //Test whether the sound is finished or not; if so, remove it
        if (m_SoundList[ii].getStatus() == sf::Sound::Status::Stopped)
        {
            m_SoundList.erase(m_SoundList.begin() + ii);
            std::cout << "Sound deleted!\n";

            //If ii is the same as the size, there are no further sounds
            if (ii == m_SoundList.size())
            {
                break;
            }
            //Otherwise, there are further sounds!  Decrement ii so as not to skip any
            else
            {
                --ii;
            }
        }
    }
}

What happens is that sometimes, when one Sound finishes after another has started (I also modify the pitch of the sound, so the lengths of each sf::Sound are slightly different), both sounds are deleted in the same call, which kills the newer sound before it has had a chance to play out.  It's as though the algorithm thinks that both sf::Sound objects return Stopped upon calling getStatus().

Any idea what might be causing this, and how I can get things to work as expected?

6
Graphics / Text off-center, problems getting size
« on: April 28, 2013, 08:33:21 pm »
I am trying to get images of arbitrary text, and am using this thread as a reference.  However, I am having some issues.  First, my implementation:

       
        sf::Font f;
        f.loadFromFile("courier.ttf");

        sf::Text text;
        text.setString("Test!");
        text.setFont(f);
        text.setCharacterSize(24);
        text.setColor(sf::Color::Black);

        sf::RenderTexture target;
        target.create(text.getLocalBounds().width,
                      text.getLocalBounds().height);
        target.clear(sf::Color::White);
        target.draw(text);
        target.display();

        sf::Image image = target.getTexture().copyToImage();
        image.saveToFile("text_test.png");

The problem is that if I just do this, what I get is an image wherein the top half is just white, and the bottom half of the image contains the top half of the text (with the bottom half of the text clipped out).

Adding
text.setPosition(0, -text.getLocalBounds().height / 2);

seems to mostly correct the issue... at 24 pts.  But if I change the character size to other values further from 24, such as 12 or 64, an upper or lower sliver of the text is again clipped out of view, respectively.

Am I misunderstanding something about how sf::Text objects are sized, positioned or displayed?  How can I neatly get an image that encompasses exactly all of the displayed text, and no more?

7
Graphics / Problems with positioning sf::Text objects
« on: October 14, 2012, 03:17:32 pm »
So this is similar to my previous post, but the problem has become more pervasive.  I am not able to sensibly come up with a solution for properly arranging a series of sf::Text objects along the center of the screen.  The loop looks like this:

short CharSize = 16;
for (int ii = 0; ii < m_WeaponData.size(); ++ii)
{
    m_WeaponData[ii].setOrigin(...);
    m_WeaponData[ii].setCharacterSize(CharSize);
    m_WeaponData[ii].setColor(sf::Color(255, 255, 255));

    //Then, position it, making sure that each element is below the last
    m_WeaponData[ii].setPosition(m_App->getSize().x / 2, 30 + ii * (CharSize + 8));
}

My initial attempt was to put the origin of the sf::Text objects at their visual center, as such:

m_WeaponData[ii].setOrigin(m_WeaponData[ii].getLocalBounds().width / 2, 0);

But I discovered that this doesn't actually position the origin to the proper place; instead, the end of each string, more or less, is centered at the middle of the screen (though there is some slight variation).  Instead, I had to do this:

m_WeaponData[ii].setOrigin(m_WeaponData[ii].getLocalBounds().width / 4, 0);

To get the texts aligned according to their visual centers, which makes no sense since width/4 should not be the horizontal center.

Now, however, I've decided that it would be more convenient for the user if the strings were all arranged such that they are centered around the colon ':' character that appears in each of them, which would neatly put labels on one side of the screen and data on the other side.  So to do that, I tried this:

m_WeaponData[ii].setOrigin(m_WeaponData[ii].findCharacterPos(m_WeaponData[ii].getString().find(sf::String(":"))));

What I get instead is a bunch of texts that are shoved off to the left at seemingly random distances, rather than centered on the only ':' character in each string.  However, when I read the values provided by .findCharacterPos(), they seem to be more or less correct (i.e. the farther the ':' into the string, the higher the value of x).

Note that I know that findCharacterPos() returns global coordinates; the sf::Text objects all start positioned at (0,0), however, so that shouldn't matter.

I find that the only way to almost properly position the objects is to ignore setOrigin() altogether and do this instead:

m_WeaponData[ii].setPosition(m_App->getSize().x / 2 - Origin.x / 2, 30 + ii * (CharSize + 8));

But the result is only approximately lined up, not perfectly lined up, and I don't even understand why that solution is better than finding the position of the ':' character.

So something is going wrong here, and I don't know what it is.  Could somebody please offer some advice on this?

8
So I have an std::vector of sf::Text items I'd like to distribute evenly along a vertical axis in the center of the screen.  Here is what I do:

    short CharSize = 16;
    for (int ii = 0; ii < m_WeaponData.size(); ++ii)
    {
        //First, set the text object's origin
        //Use zero as the origin's Y, because if you use half the height, hanging characters such as (g,j,p,q,y) will make things uneven
        //Use 4 instead of 2 because... I have no idea.
        m_WeaponData[ii].setOrigin(m_WeaponData[ii].getLocalBounds().width / 4, 0);
        //Then, position it, making sure that each element is below the last
        m_WeaponData[ii].setPosition(m_App->getSize().x / 2,
                                     30 + ii * (CharSize + 2));
    }

Where m_App is of type sf::RenderWindow*.

My question is this: why am I dividing the local bounds by 4?  If I use 2, as would seem to make sense (that should put the origin at the halfway point of the sf::Text's X side, since the width divided by 2 is half the width...), the end of the text lines up with the center of the screen, rather than the center.  Using 4, though, does line up the X center of the sf::Text with the X center of m_App (which I assume I am obtaining correctly, right?).

I can only assume I am doing something wrong, but what?  Why does getLocalBounds().width / 2 not give me the proper results?

9
Graphics / OpenGL - Screenshots always magenta
« on: May 27, 2012, 08:31:31 am »
So I've got a rather annoying problem.  I'm working on a project in OpenGL, and for the moment, my model and background are various shades of grey.  This works fine while I'm running the program, but when I take a screenshot of the scene using these methods:

sf::Image Screen = App->Capture();
Screen.SaveToFile("screenshot.bmp");

the resulting image is in shades of magenta-to-white, rather than grey.  This has the added problem of making much of the image disappear, because most of the areas that aren't brightly shaded (or under-shaded) are all absorbed into the same color.  I've tried to attach a screenshot - the object in the screenshot is supposed to be a full beveled triangle, but you can only barely see it.

What's up with this, and how can I produce accurate screenshots?

[attachment deleted by admin]

10
Graphics / Vector Graphics?
« on: February 21, 2012, 02:05:06 pm »
So I'm working on an app that involves a great deal of zooming in order to refocus on smaller and larger objects.  The larger objects, though, need to look smooth even when focusing on the smaller objects, which can be many thousand times smaller.  So far, I simply use a stand-in sf::Shape::Circle for the larger objects, which is fine since it smooths with zoom, but I will want to add more visual detail in the future.  

If the smallest objects on-screen are 32x32 pixels, though, the largest ones need to be over 3000 pixels in diameter (in order to look good at close range), and I fear that loading that many huge images will be a problem (if it is even allowed by the hardware).

So I am currently using SFML 1.6.  Does it, or SFML 2.0, have support for vector graphics?  That would solve my problems pretty handily, I think.  I know I could split the images up into distinct parts, and I might do that, but I want to know what my options are.

11
Graphics / Sprite not centering properly - conflicts with Rotate...?
« on: February 05, 2012, 06:35:40 pm »
Note: This is for SFML 1.6.

So I have a sprite, which I want to be centered on the real position of the object it represents.  I center it by calling the following:

Code: [Select]
       m_Sprite.SetSubRect(sf::IntRect(0, 65, 65, 86));
        m_Sprite.SetPosition(m_RealPosition.x - (m_Sprite.GetSize().x / 2), m_RealPosition.y - (m_Sprite.GetSize().y / 2));
        m_Sprite.SetCenter(m_Sprite.GetSize().x / 2, m_Sprite.GetSize().y / 2);


This apparently doesn't work.  I discovered this by creating an sf::Shape::Circle at the place represented by m_RealPosition, as such:

Code: [Select]
       m_Marker = sf::Shape::Circle(m_RealPosition.x,
                                     m_RealPosition.y,
                                     5,
                                     sf::Color(255, 0, 0));


The Sprite does its thing left of, and slightly above, the red circle it is supposed to be centered on.  I rotate the Sprite very frequently using sf::Sprite::SetRotation, so I'm wondering if that is causing the problem.

I should note that the object in question inherets from an abstract class that has this in its constructor (the above code is being called every frame after construction, despite any inefficiency; m_Sprite from above is inherited from this abstract class):

Code: [Select]
   m_Sprite.SetPosition(m_RealPosition.x - (m_Sprite.GetSize().x / 2),
                         m_RealPosition.y - (m_Sprite.GetSize().y / 2));

    m_Sprite.SetCenter(m_Sprite.GetSize().x / 2,
                       m_Sprite.GetSize().y / 2);


So my question is basically this: are there any conflicts between SetCenter, SetRotation, SetPosition and SetSubRect that I should be aware of?  Or can anyone else see what I can't?  Why would my Sprite not be centering on m_RealPosition?

Thanks for any help anyone can offer!

12
Window / Cursor for camera rotation in OpenGL
« on: September 01, 2011, 01:26:08 pm »
So I'm working on a small OpenGL project, and my goal is to get a camera to translate through a scene and rotate around itself in a way similar to the first-person camera in Minecraft.

So far, I've got almost everything working the way I want, except for one problem: when moving the mouse left or right to rotate the camera, the cursor eventually hits the edge of the window and stops rotating the camera.  I don't want this; I am aiming for a camera that can continuously rotate in one direction, so long as the mouse is being moved in that direction.

I tried continuously setting the cursor to half the window dimensions (i.e. the center), but that wasn't workable - which should have been obvious to me in hindsight, but meh.

My current code looks like this.  The "wrap around" code doesn't work, though, because when I move the mouse too quickly over the edge of the window, it stops registering a mouse position before the mouse oversteps its bounds - and if I go do slow, it gets thrown around constantly.

Code: [Select]
       //Current Mouse Coords.
        NewMouseX = App.GetInput().GetMouseX();
        NewMouseY = App.GetInput().GetMouseY();

        //If the mouse has left the bounds of the screen, wrap around.
        if (NewMouseX >= WindowWidth - 1 || NewMouseY >= WindowHeight - 1 || NewMouseX < 1 || NewMouseY < 1)
        {
            std::cout << "Wrapping!\n";
            int WrappedX = NewMouseX;
            int WrappedY = NewMouseY;
            if (WrappedX >= WindowWidth - 1)
            {
                WrappedX = 2;
            }
            else if (WrappedX < 1)
            {
                WrappedX = WindowWidth - 2;
            }
            if (WrappedY >= WindowHeight - 1)
            {
                WrappedY = 2;
            }
            else if (WrappedY < 1)
            {
                WrappedY = WindowHeight - 2;
            }
            App.SetCursorPosition(WrappedX, WrappedY);
        }

        //Modify the angle based on mouse movement.
        PlayerRot[0] += (NewMouseX - OldMouseX) * 0.3;
        PlayerRot[1] += (NewMouseY - OldMouseY) * 0.3;
        //Set it back within the bounds of the 0-359 circle.
        if (PlayerRot[0] > 359)
        {
            PlayerRot[0] -= 360;
        }
        else if (PlayerRot[0] < 0)
        {
            PlayerRot[0] += 360;
        }
        if (PlayerRot[1] > 359)
        {
            PlayerRot[1] -= 360;
        }
        else if (PlayerRot[1] < 0)
        {
            PlayerRot[1] += 360;
        }

        //Adjust mouse values, for the next frame.
        OldMouseX = NewMouseX;
        OldMouseY = NewMouseY;


Does anyone here know how to handle this kind of continuously rotating camera?  Are there any special features in SFML that might be helpful here?

13
Graphics / Sprite images are all white squares
« on: August 02, 2011, 10:28:48 am »
So for some reason, all the images I am loading for my sprites are being turned into white squares.  They are at the appropriate position in space, and they even change color if I want them to, so I know they are there, but they remain nothing more than blank squares of whatever color I set them at.

The way I've done it is I have two containers, one for tile images and one for object images.  Each container contains each image only once, and all instances of objects or tiles take their image from these containers.  Within the constructor for the Baby class (one of the object classes), I've included this code:
Code: [Select]

m_Sprite.SetImage(pLevel->GetMobImage(1));
m_Sprite.SetPosition(m_X, m_Y);
cout << m_X << ", " << m_Y << endl;
m_Sprite.SetColor(sf::Color(255, 0, 0));


Note that Baby inherits from Mob.  Mob contains only the sf::Sprite m_Sprite; declaration, however, as well as the following draw function:

Code: [Select]
void Mob::Draw(sf::RenderWindow* App)
{
    App->Draw(m_Sprite);
}


Level::GetMobImage() is defined as follows:

Code: [Select]
sf::Image Level::GetMobImage(int image)
{
    if (image >= m_MobImages.size())
    {
        cout << "ERROR!  No image this far into the vector!\n";
    }
    return m_MobImages[image];
}


Where m_MobImages is the aforementioned container of sf::Images.

---

So, blank squares.

I first thought my code was too convoluted.  Yet I am able to change the color of my sprites, and they definitely have the same size as the images they are supposed to be displaying (some are 9x9, others 15x15, others 32x32).

But then I tested out the other sf::Image using class, Tile, and realized that the tiles that form the background of the scene are also being drawn as blank white squares, even if I give them squiggly black lines as art (I hadn't noticed until then because the tiles had always been blank, and since they did color in using sf::Sprite::SetColor, I thought all was well).

I tried an inefficient hack, just to see if I could get it to work, by having instances of Baby have their own sf::Image data member and load its contents directly from a file themselves, without the whole container system.  I did so by including the following in the constructor for Baby:

Code: [Select]
sf::Image Image;
Image.LoadFromFile("Baby.png");
m_Sprite.SetImage(Image);
m_Sprite.SetPosition(m_X, m_Y);
m_Sprite.SetColor(sf::Color(255, 0, 0));


Again, all I get are red squares.

Can anyone point me in the right direction?

---

This was a similar post about something that seemed similar a few months ago, but reading it didn't really help me solve this, as s/he seemed to be trying to do something different than I am.

http://www.sfml-dev.org/forum/viewtopic.php?t=4493&sid=f9feaa1f0a8d93be858aed89b385873a

14
Graphics / Unwanted, dark grey grid appearing.
« on: July 27, 2011, 09:19:48 am »
This might be an error in my code somewhere, but I can't actually figure out where.  Then again, I might not understand SFML properly yet.

I'm working on a tile-based RTS prototype, and I just made the move from sf::Shape::Rectangles to sf::Sprites for representing my tiles, in order to make them look more interesting.  However, there is now a grey grid that appears in the space between the tiles (see image below).

http://imageshack.us/photo/my-images/33/screenshotgf.jpg/

This shouldn't be happening.  I've got all the tiles spaced at 32 units, which is also the size of the square tiles.  I've tried making the tiles wider in the hopes of "covering" the grid as a temporary solution, but that doesn't work.  The grid appears to exist between the tiles, yet does not go away, even if I inflate the tile size.

I've also placed markers in each of the four corners of the blank tiles, to see if any of the sides or corners are being "covered" by this grid - they're not, unless I inflate the tiles, in which case even the parts that are covered by tiles further to the bottom or right sport this annoying grid.

I thought it might have something to do with the Sprite's Blend, so I set that to None, and nothing changed.

Here is a close-up of the grid, zoomed in using a View.

http://imageshack.us/photo/my-images/32/screenshot2iv.jpg/

As you can see, it cuts off very sharply when two different sorts of tile meet.  I get the impression that SFML is trying to "soften" the contours of my tiles, but I don't want this.  What's up with that?

I should also mention that when I scroll around (again, using a View), the grid tends to flicker, sometimes only appearing vertically, sometimes only horizontally, and sometimes not at all (though only rarely).

15
Graphics / MouseMove.X always returning 0...
« on: June 14, 2011, 07:10:23 am »
So I've managed to get my window detecting mouse input, and MouseMove.Y always properly returns coordinates, but MouseMove.X consistently returns 0, no matter where on the screen I click.

I am trying to click on a circle to reset it's color.  Here are the relevant parts of code:

Code: [Select]
           //This checks for mouse input.
            else if(Event.Type == sf::Event::MouseButtonPressed)
            {
                for(int i = 0; i < (*GameBoard).theBoard.size(); ++i)
                {
                    bool colliding = (*GameBoard).theBoard[i].CollidePoint(Event.MouseMove.X, Event.MouseMove.Y);
                    if(colliding)
                    {
                        (*GameBoard).theBoard[i].m_Circle.SetColor(sf::Color(20, 20, 200));
                        break;
                    }
                }
            }


And this:

Code: [Select]
bool Space::CollidePoint(int x, int y)
{
    float xDist = abs(x - (m_X + m_radius));
    float yDist = abs(y - (m_Y + m_radius));
    float distance = sqrt(pow(xDist, 2) + pow(yDist, 2));

    cout << "\nClick detected at: " << x << ", " << y << endl;
    cout << "Center is at " << (m_X + m_radius) << ", " << (m_Y + m_radius) << endl;
    cout << "Distance is: " << distance << "\n";

    if(distance <= m_radius)
    {
        return true;
    }
    else
    {
        return false;
    }
}


Now, it's possible that MouseMove.X is returning the proper value and I'm just not sending it properly to cout, but I doubt this is the issue, since none of the circles I click on want to respond to me.  Anyone know what I'm doing wrong?  I'm quite new to C++, coming from a background in Python; I fully expect to have made some simple mistake somewhere.

Pages: [1] 2