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

Pages: [1]
1
Graphics / Unexpected Results when using .setOrigin()
« on: June 12, 2013, 10:57:25 pm »
Hi guys,
I have been working on a few minor projects in SFML 2.0 for about a month or so now and I have this one recurring problem with arranging drawables on the renderwindow. I often find it easier to place objects by setting the origin to the centre of the object with something like:
Code: [Select]
rect.setOrigin(
     rect.getGlobalBounds().width/2,
     rect.getGlobalBounds().height/2
     );

Hovever, when Trying to overlay sf::Text and sf::RectangleShape objects, having set their origins to the centre, i get unexpected results.

For Example:

Code: [Select]
#include "SFML\Graphics.hpp"

int main()
{
int SCREEN_WIDTH = 1024;
int SCREEN_HEIGHT = 768;

sf::RenderWindow rwindow(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32), "test window!");

sf::Font myFont;
myFont.loadFromFile("OCR-A.TTF");

//set the text, change origin and set position
sf::Text label("Some Text", myFont, 50);
label.setOrigin(
label.getGlobalBounds().width/2,
label.getGlobalBounds().height/2
);
label.setPosition(SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
label.setColor(sf::Color::Green);

// set a rectangle shape to the same size and position as the text
sf::RectangleShape rect;
rect.setSize(sf::Vector2f(
label.getGlobalBounds().width,
label.getGlobalBounds().height
));
rect.setOrigin(
rect.getGlobalBounds().width/2,
rect.getGlobalBounds().height/2
);
rect.setPosition(label.getPosition());
rect.setFillColor(sf::Color(255,255,255,100));


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

rwindow.clear();
rwindow.draw(rect);
rwindow.draw(label);
rwindow.display();
}

return 0;
}

produces the following result:



The text and rectangle appear to be the same size but are not on top of one-another as expected.
has anyone come across this problem before?

cheers.

2
Graphics / Images, Textures and Sprites - quick question
« on: May 17, 2013, 11:06:45 pm »
Hi guys, I'm fairly new to c++ and I've been using the SFML 2.0 API for about a week now. The brilliant documentation has got me quite far and yesterday I started trying to build a little Mandelbrot Set explorer. All I have done so far is to get the algorithm to draw the set and send it to a renderwindow (I include a picture of the results). The next step is to start to package it up into a more object oriented framework and add zoom and scroll features, here I'm stumbling at the first hurdle. The code which sends the image to the renderwindow looks something like this at the moment:

Code: [Select]
sf::RenderWindow window( sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32), "MandelBrot Set!");
sf::Texture texture;
sf::Sprite sprite;
sf::image image(SCREEN_WIDTH, SCREEN_HEIGHT, sf::Color::White);

for(unsigned i=0; i<SCREEN_WIDTH; ++i)
{
  for(unsigned j=0; j<SCREEN_HEIGHT; ++i)
  {
    // calculate color for each pixel here using image.SetPixel(i,j,sf::Color)
  }
}

image.SaveToFile("some_directory.png");
texture.LoadFromFile("some_directory.png");
sprite.SetTexture(texture);

window.draw(sprite);
window.display();

//then some display loop

So my question is: Do I have to save the image to disk before i can access it with a texture? I cant see any way around it from just reading the stuff in the documentation. I never used 1.6 but I gather from various tutorials and such that this used to be possible by passing an image directly to a sprite, the image seems to be more abstract in 2.0.

Thanks.

Edit: Forgot the image..
http://postimg.org/image/w3azfoju3/

Pages: [1]
anything