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

Pages: 1 2 [3] 4
31
Graphics / Re: OpenGL - Screenshots always magenta
« on: May 27, 2012, 11:26:03 am »
Quote
The installation tutorials are online.

I saw that afterwards - I initially just read the download page and didn't check the Tutorial page to confirm.  I guess I wasn't really paying attention! 

I think I've got SFML 2 properly integrated into my program, just scouring the code for old code to switch over.  I'll let you know if the problem persists.

32
Graphics / Re: OpenGL - Screenshots always magenta
« on: May 27, 2012, 09:48:18 am »
Quote
I am still using SFML 1.6.
Ah... Could you test with SFML 2? SFML 1.6 is not maintained anymore.

Okay - having just downloaded SFML 2, I see the OpenGL example is just an executable with some assets, is that right?  Or am I looking in the wrong place?

Also, just to make sure since the tutorials aren't up, installing SFML 2 works just like it did with SFML 1.6, right?  Or anything special to pay attention to?

If so, I guess I'll first go through my code and replace SFML 1.6 with SFML 2 code, and see if the problem persists.  Thankfully there isn't too much in there to replace, most of it is custom or regular OpenGL.

33
Graphics / Re: OpenGL - Screenshots always magenta
« on: May 27, 2012, 09:37:48 am »
It happens when I use the OpenGL example provided in the SFML folder and add
Code: [Select]
if ((Event.Type == sf::Event::KeyPressed) &&
    (Event.Key.Code == sf::Key::F1))
{
     sf::Image Screen = App.Capture();
     Screen.SaveToFile("screenshot.bmp");
}

I've attached the modified example file.  I didn't touch anything besides adding the above code into the while (App.IsOpened()) loop.

I am still using SFML 1.6.  Is this perhaps a known bug...?  Or perhaps something on my end beyond the code, most likely.  I don't know what settings or configurations might cause this.

[attachment deleted by admin]

34
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]

35
Graphics / Vector Graphics?
« on: February 21, 2012, 02:18:14 pm »
Ah, all right then.  Thanks for the quick reply!

36
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.

37
Graphics / Sprite not centering properly - conflicts with Rotate...?
« on: February 05, 2012, 07:21:05 pm »
Perfect!  That works marvelously.

Out of curiosity, why does the parameter to SetPosition() become the Sprite's center, and not its upper left corner?  I thought the upper-left was always what was being set by SetPosition().  Is it something to do with the inheritance?

Edit: ... It's because SetPosition() sets the position of the sprite's center, as determined by SetCenter() and which is normally (0,0).  Right?

38
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!

39
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?

40
Graphics / Sprite images are all white squares
« on: August 02, 2011, 06:05:48 pm »
Ah, that's pretty much the same as what I used in PyGame back when I was learning programming.  Thanks for the help!

41
Graphics / Sprite images are all white squares
« on: August 02, 2011, 11:18:34 am »
Hm... I've mostly solved the problem, now!  GetMobImage was returning an sf::Image, but I changed it such that it returned a pointer to an sf::Image and then used that instead to set the image (dereferencing it, of course).  That worked - the graphics now display properly.  

The only problem now is that the entire rectangle that contains the sprite's data is being turned red, rather than just the sprite's art.  I exported the image from InkScape as a .png - perhaps I should try something else to get the alpha to carry across?

42
Graphics / Sprite images are all white squares
« on: August 02, 2011, 10:40:42 am »
Afterwards; the images are all loaded during the constructor for the Level class, which is called before the main loop, which is the only place the the Baby instances can be created (and thus the only place GetMobImage gets called).

43
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

44
Graphics / Unwanted, dark grey grid appearing.
« on: July 27, 2011, 11:15:15 am »
Ah, yes, that was exactly it!  Thank you!

45
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).

Pages: 1 2 [3] 4