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

Pages: [1] 2
1
General / Adding Events to the Event queue
« on: October 15, 2011, 06:52:33 pm »
Ah, I apologise! I started Uni a few weeks ago and completely forgot about this.

So I can't quite seem to get RenderWindow::Close to work.
Any other ideas?

I'm gonna keep playing around with it, and I'll let you know if I find anything, but I doubt it.

Thank you for the replies!

Edit: Okay, I've found a simple work around.

When the button is clicked, it'll 'disable' the window that contains it.
Just before the event loop, it checks if the window is disabled, if it is, it calls Window.Close().

Sorry for wasting your time.

2
General / Adding Events to the Event queue
« on: October 06, 2011, 11:34:33 pm »
It's that time again where I ask a possibly stupid question;

Okay, I'm using GWEN with SFML, and basically I have an inherited GWEN::Window with a button on it. I have a button on it called Exit, which I obviously want to close the application.

How do I even go about doing this? One option is to pass a pointer to the sf::renderwindow into the GWEN window, but I believe that's bad practice.

So can I either somehow add Event::Close to the event queue, or can I some how call App.Close() some how?

Basically, sf::RenderWindow < GWEN::Controls::Window < Gwen::Controls::Button. (< just being a hierarchy) How can I access sf::RenderWindow from Controls::Window?

3
Network / [SFML2] Network Help
« on: September 13, 2011, 02:13:37 pm »
Oh wow, my ignorance is shooting through the roof today.
If you can believe me, I'm not always like this.

Yes, I have an examples folder.
Whenever I tried git pull, I always got an error about local branch, can't quite remember.

Don't worry, my batch file is safe and what not, it just takes a stupidly long way round.

(Delete SFML folder, redownload new sfml, recompile, done.)

Edit:
Example worked, port bound and what not. Thank you very much!

4
Network / [SFML2] Network Help
« on: September 13, 2011, 01:54:10 pm »
OOOOH.

Sorry, I fail badly at github related stuff. You should see my SFML2 update batch file. Cringe worthy.

Anyway, thank you very kindly Laurent. Excellent 'service' as ever!

5
Network / [SFML2] Network Help
« on: September 13, 2011, 01:41:46 pm »
Quote
Sockets example of SFML 2

Er... Hate to be a pain, but where is that...? I've looked for SFML2 examples, but can't find any on networking, or do you mean use the 1.6 example?



And thank you for the sf::IpAddress::None. I did wonder if it was that, but apparently I used it incorrectly!
((!Var.None()). No wonder it didn't work. Haha.)

6
Network / [SFML2] Network Help
« on: September 13, 2011, 12:53:29 pm »
Okay, so I used the networking tutorial for 1.6, and then realised the changes, now here's a few problems I have;

Instead of (!IPAddress.IsValid()), what can I use to check if the IPAddress is valid? Seeing as IsValid() as been removed.

Also, I constantly see "Failed to bind Port ####". (# being the port number...)

The port is forwarded on my router, so what else is the problem? I've let it through my firewall too.

(The code I'm using is literally the UDP Socket example with a few changes to fit SFML2.)

7
Graphics / Debug version works fine, release desn't (Tic Tac Toe)
« on: September 07, 2011, 02:13:14 pm »
To your question "Why is debug.exe bigger than release.exe" is because debug contains alot of debugging code in the SFML area. All of this debug code is literally for that reason; debugging. It helps narrow down errors and what not.

Release doesn't contain these debug lines, so naturally it's alot less to process.

As to why release isn't working as well, I don't know. Sorry.

8
Graphics / Bug?: Polygon drawing + outline fail
« on: September 07, 2011, 02:09:41 pm »
Sorry, I know "instant" is a bit of a bad term, but I kind of meant "it's so fast, that you barely notice a delay".

And that is interesting to know, thank you.

Also scan fill kinda scared me, and like you said, this works, so I may as well stick to it.

It's not like I'm using this in anything important right now, I'm just literally collecting 'knowledge' as it were.

Thanks for all the help guys :D

9
Graphics / Bug?: Polygon drawing + outline fail
« on: September 06, 2011, 12:25:06 pm »
Okay, sorry for the double post but;

I've tried a flood fill algorithm, but it's just so slow! It takes like 5 minutes to even do it!

So how the hell does paint do it so fast?

Here's my code anyway;
Code: [Select]

void FloodFill(sf::Vector2i Pixel, sf::Color SelectedColour, sf::Color TargetColour)
{
std::queue<sf::Vector2i> FillQueue;

if (Mountain.GetPixel(Pixel.x, Pixel.y) != TargetColour)
return;

FillQueue.push(Pixel);

while (!FillQueue.empty())
{
sf::Vector2i n (FillQueue.front());

if (Mountain.GetPixel(n.x, n.y) == TargetColour)
                {
Mountain.SetPixel(n.x, n.y, SelectedColour);

if (n.x - 1 > 0)
FillQueue.push(sf::Vector2i(n.x-1, n.y));

if (n.x + 1 < 800) //800 being window width.
FillQueue.push(sf::Vector2i(n.x+1, n.y));

if (n.y - 1 > 0)
FillQueue.push(sf::Vector2i(n.x, n.y-1));

if (n.y + 1 < 599) //800 being window height, except 600 caused crashing.
FillQueue.push(sf::Vector2i(n.x, n.y+1));

               }
                FillQueue.pop();

std::cout << FillQueue.size() << std::endl;
//Draw();
}

return;
}


The reason Draw was there, was so I can see what happens when it does it, (Cool effect of it spreading out, but obviously this makes the whole thing slower, so i commented it out). cout is there just so I could see that it was doing something and how many pixels are left to change... This just keeps going up.

If I remove all 4 of these;
Code: [Select]
if (Mountain.GetPixel(n.x, n.y+1) == TargetColour
this speeds it up the cycles tremendously, but then also doubles the amount of pixels it's checking.

How can I speed up this operation so it's as fast as paint? Is it because I'm constantly using an sf::Image (Mountain) to check for pixels? I can't find any other way to check the pixels of the thing even through Sprite or Texture.

This is becoming a real pain in the backside, because I have no idea!

EDIT!
Okay, I managed to speed it up by half, but it still takes a really long time, I've updated the code above with what I have.

EDIT2!
Er... okay... I removed std::cout... and it's instant....
...anyone care to explain why...?
Also, fairly obvious, but debug takes 2-3 seconds to achive what I want to do, but release is fairly instant. It's quite cool how much difference it makes.

10
Graphics / Bug?: Polygon drawing + outline fail
« on: September 05, 2011, 04:56:05 pm »
That's pretty hot, thanks.

I always wondered how 'fill' works, it just seems so quick on paint and stuff, but using an algorithm like that just looks like it'd take forever.

I really need to give processors more credit. xD

Also, I guess this topic can be closed now.

11
Graphics / Bug?: Polygon drawing + outline fail
« on: September 04, 2011, 05:19:41 pm »
Hmm... I guess I need to go look at some image functions then. Thanks.

Me being lazy; is there a 'fill' function or anything? That's the only real thing I'm after. Before I just drew a line, all I wanted to do was fill the bottom half of the screen.

12
Graphics / Re: Detecting when an object is no longer visible to the use
« on: September 04, 2011, 11:26:28 am »
Quote from: "DClipp"

Code: [Select]
  if (ball.GetPosition().y > 460) {
      ballIsVisible == false;
   }



Wait, can you use the '==' operator to assign stuff too when it's not in an "if" statement?

I thought it was purely for if statements...

13
Graphics / Bug?: Polygon drawing + outline fail
« on: September 04, 2011, 11:23:04 am »
I get the whole outline going to points thing, but shouldn't it follow the whole convex thing instead?

There's no way in hell I could even do something like splitting it up into parts then putting them together, that's way out of my league.

I guess I'll have a look into the thor-lib then.

So many libraries...

14
Graphics / Bug?: Polygon drawing + outline fail
« on: September 04, 2011, 02:27:51 am »
That couldn't have gone over my head even more if you tried.

I'm off to google what you mean.

But still, isn't this worth pointing out? I mean the outline works fine, but the 'filling' doesn't.

Edit:
Oh, I see what you mean about the concave thing... so... what can I do for a work around? I just wanted to add points and fill the space in the middle.

15
Graphics / Bug?: Polygon drawing + outline fail
« on: September 03, 2011, 06:04:09 pm »
I apologise in advance about the title, couldn't think of anything suitable.

Okay, so I'm not sure if this is a bug, or some error on my part, but considering the method, I'm pretty sure it's SFML.

So I have a vector of points, and I add all the points into a sf::Shape, then I set the properties such as colour, outline, etc.

Now, when I draw the polygon, I get some weird results;


Can you see where the outline doesn't match the sudden straight line of colour?

Now, the outline is definitely correct, but that random stretch of gray isn't.

Considering that the outline is draw with the polygon itself, it can't be an error on my part because I'm not manually drawing them seperately.

Unless I'm a total idiot and missing something, I'm not entirely sure what it is.

It is a tiny bit of a problem obviously, because it's plain as day in some generations.

Here's the code; (Please be warned that alot of it is debug code, it was me just messing around with some ideas and fractal generation)

Code: [Select]
#include <SFML\Graphics.hpp>
#include <time.h>
#include <Vector>

sf::VideoMode VMode(800, 600,32);
sf::RenderWindow Window(VMode, "ProcGen");

void Generate();
void Draw();
void Clear();

static const float w = float(Window.GetWidth());
static const float h = float(Window.GetHeight());
float Displacement;
float MidPoint;
int Split;

sf::Shape Polygon;

std::vector<sf::Vector2f> Points;



int  main()
{
srand(time(0));

Clear();
Generate();

while (Window.IsOpened())
{
sf::Event Event;
while (Window.PollEvent(Event))
{
switch (Event.Type)
{
case sf::Event::Closed:
Window.Close();
break;

case sf::Event::KeyPressed:
Clear();
Generate();
break;

default:
break;
}
}

Window.Clear(sf::Color(0, 255, 255));
Draw();
Window.Display();


}

return 0;
}


void Generate()
{
std::vector<sf::Vector2f>::iterator It;
int j;

for (int i = 0; i < 7; i++)
{
Split = Split/2;
for(It = Points.begin(), j = 0; It != (Points.end() - 1); It++, j++)
{
sf::Vector2f Temp((Points[j].x+Points[j+1].x)/2,(Points[j].y+Points[j+1].y)/2);
Temp.y = Temp.y - (rand() % (Split*2) - Split);

Points.insert(It+1, Temp);

It = Points.begin();
for (int k = 0; k <= j; k++)
It++;

j++;
}
}

sf::Shape temp;

for (unsigned int i = 0; i < Points.size(); i++)
temp.AddPoint(Points[i]);

temp.SetColor(sf::Color(128,128,128));
temp.SetOutlineThickness(2.0f);

Polygon = temp;
}

void Draw()
{
//for (unsigned int i = 0; i < Points.size()-1; i++)
// Window.Draw(sf::Shape::Line(Points[i], Points[i+1], 2.0f, sf::Color::Black));

Window.Draw(Polygon);
}

void Clear()
{
Displacement =  rand() % 200 + 300;
    MidPoint = Displacement/2;
Split = MidPoint;
Points.clear();
Points.push_back(sf::Vector2f(0,h));
Points.push_back(sf::Vector2f(rand() % 400 + 200,h-Displacement));
Points.push_back(sf::Vector2f(w,h));
}

Pages: [1] 2