SFML community forums

Help => Graphics => Topic started by: qsik on May 15, 2008, 03:49:07 am

Title: Drawing Everything
Post by: qsik on May 15, 2008, 03:49:07 am
is there a way to draw everything w/o having to write window.draw(whatever) every single time you have something new?
Title: Re: Drawing Everything
Post by: quasius on May 15, 2008, 06:17:52 am
Quote from: "qsik"
is there a way to draw everything w/o having to write window.draw(whatever) every single time you have something new?


No.  But just use an STL vector of Sprites.
Code: [Select]

for (unsigned int i = 0; i < vSprites.size(); ++i)
      window.draw(vSprites[i]);


It's not that big of a deal.  How would you expect SFML to know what "everything" is anyway?  SFML does not have a sprite manager.  You can and should make your own.
Title: Drawing Everything
Post by: eleinvisible on May 16, 2008, 10:28:45 pm
But I think he means, he wants the entire screen to redraw, not all the objects. Like in SDL you can call SDL_Flip(Screen).
Title: Drawing Everything
Post by: Kernelpanic on May 16, 2008, 10:58:04 pm
A sprite isn't bound to one window, so it wouldn't be possible to detect all sprites, which must be drawn in one specific window.

@quasius
It would be good to use iterators for the loop:
Code: [Select]

for(vector<Sprite>::iterator i = vSprites.begin(); i != vSprites.end(); i++)

So you can use easily all types of containers.
Title: Drawing Everything
Post by: quasius on May 17, 2008, 01:11:10 am
Quote from: "Kernelpanic"

@quasius
It would be good to use iterators for the loop:


I was trying to keep it simple and intuitive...
Title: Drawing Everything
Post by: Nexus on May 17, 2008, 03:15:12 pm
Sorry, if it's a little bit off-topic...
Quote from: "Kernelpanic"

It would be good to use iterators for the loop:
[...]
So you can use easily all types of containers.

Is this faster with iterators or is it just more general and easy to port? What is a reason against indexes?
Title: Drawing Everything
Post by: eleinvisible on May 17, 2008, 04:45:13 pm
Quote from: "Nexus"
Sorry, if it's a little bit off-topic...
Quote from: "Kernelpanic"

It would be good to use iterators for the loop:
[...]
So you can use easily all types of containers.

Is this faster with iterators or is it just more general and easy to port? What is a reason against indexes?
Seconded, because the reason I use STL vectors is because they're fast, and allow index access with [] and at, otherwise I don't think I'd like STL containers as much.
Title: Drawing Everything
Post by: quasius on May 17, 2008, 05:16:13 pm
Quote from: "eleinvisible"
Quote from: "Nexus"
Sorry, if it's a little bit off-topic...
Quote from: "Kernelpanic"

It would be good to use iterators for the loop:
[...]
So you can use easily all types of containers.

Is this faster with iterators or is it just more general and easy to port? What is a reason against indexes?
Seconded, because the reason I use STL vectors is because they're fast, and allow index access with [] and at, otherwise I don't think I'd like STL containers as much.


It might be faster with iterators.  But since the indexing syntax is so common, I'm sure any good optimizing compiler just uses an iterator anyway in release build.  It's nothing to worry about.
The biggest reason to use iterators (and it's not that big) is if you wanted to switch to another container (list, map), it would be a bit easier.  List and map will obviously be faster and better than vectors in certain situations.  List doesn't use indexing and map indexing works differently from vector indexing (in a map, if you reference an index that doesn't exist, it will create that entry automatically which can cause unexpected behavior if you don't understand what's going on.)
There's probably nothing wrong with using index syntax for vectors if you like.
Title: Drawing Everything
Post by: workmad3 on May 17, 2008, 06:10:33 pm
I don't think any compiler would replace index notation with iterator constructs. It's not really an optimisation (especially if the iterator coding isn't quite as optimal as possible).

The point of using iterator notation rather than index notation is that iterator notation is pointer notation, which can be used with ANY container that is standard in C++, not just STL ones. That means that the same (templated, generic) code will work with raw arrays in the same way as it will work for vectors, or maps or deques or whatever.

However, if you want a good way to do what you are suggesting, I would suggest using boost and doing:
Code: [Select]

BOOST_FOREACH(Sprite s, vSprites)
{
   s.Draw();
}

as then you don't need to worry about messing around with iterators, indices or anything else :) There is an STL version of for_each but it isn't as useful as the boost version, although I think there may be an improved version in C++0x.
Title: Drawing Everything
Post by: Nexus on May 17, 2008, 08:02:33 pm
I just asked because I don't like iterators, either. Sometimes I really hate them ;)

Most of the time, you can avoid using iterators, but unfortunately, the erase() function doesn't work with indexes - sometimes, that's really annoying. I really don't understand why there is no overloaded function with an index integer as parameter.
Title: Drawing Everything
Post by: Kernelpanic on May 17, 2008, 08:37:14 pm
For some containers like list they are really faster.
I think for containers like vector and deque they are a little bit faster, because the program can contact the adress directly.
Somtimes I hate them, too, because I had a situation, where I needed one int-counter and one iterator in a for-loop, for(int i=...) and inside of the loop an iterator. :D
Title: Drawing Everything
Post by: Laurent on May 18, 2008, 06:21:33 am
Quote
Most of the time, you can avoid using iterators, but unfortunately, the erase() function doesn't work with indexes - sometimes, that's really annoying. I really don't understand why there is no overloaded function with an index integer as parameter.

You can always construct a vector iterator from an index :
Code: [Select]
vector<xxx>::iterator it = v.begin() + index;
Title: Drawing Everything
Post by: qsik on May 18, 2008, 07:01:26 am
Code: [Select]
void CategoryArray()
{
for (int sprite = 0; sprite < 6; sprite++)
{
if (sprite == 1)
Categories[sprite] = sf::Sprite(Who);
if (sprite == 2)
Categories[sprite] = sf::Sprite(Dates);
if (sprite == 3)
Categories[sprite] = sf::Sprite(Where);
if (sprite == 4)
Categories[sprite] = sf::Sprite(Numbers);
if (sprite == 5)
Categories[sprite] = sf::Sprite(Random);
}
}


Code: [Select]
for (int number = 1; number < 6; number++)
{
Window.Draw(Categories[number]);
};


this code should assign and display 5 sprites but it only displays 4, what am i doing wrong?
Title: Drawing Everything
Post by: Laurent on May 18, 2008, 08:58:23 am
Wow, I'm always impressed how people can make simple things much more complicated :shock:
What about this code ?
Code: [Select]
void CategoryArray()
{
    Categories[1] = sf::Sprite(Who);
    Categories[2] = sf::Sprite(Dates);
    Categories[3] = sf::Sprite(Where);
    Categories[4] = sf::Sprite(Numbers);
    Categories[5] = sf::Sprite(Random);
}

Or, if you just want to assign a new image and don't want to reset all other attributes :
Code: [Select]
void CategoryArray()
{
    Categories[1].SetImage(Who);
    Categories[2].SetImage(Dates);
    Categories[3].SetImage(Where);
    Categories[4].SetImage(Numbers);
    Categories[5].SetImage(Random);
}


But I agree, your code should display 5 sprites. Maybe the error is in another part of the code.
Title: Drawing Everything
Post by: Nexus on May 18, 2008, 04:27:14 pm
Quote from: "Laurent"
You can always construct a vector iterator from an index :
Code: [Select]
vector<xxx>::iterator it = v.begin() + index;

I know, but that's what I hate... I think
Code: [Select]
MyVector.erase(3); would be much easier instead of
Code: [Select]
MyVector.erase(MyVector.begin() + 3);
At least there should be an overloaded function which would accept both iterators and index integers.

But do you think it's better to use iterators all the time (even as loop-counting variables)? Because at the moment I try to avoid them wherever possible ;)
Might it be significant for the performance if I got big sf::Sprite vectors which are drawn every frame?
Title: Drawing Everything
Post by: Laurent on May 18, 2008, 04:43:04 pm
Quote
At least there should be an overloaded function which would accept both iterators and index integers.

It's much more flexible and maintainable to provide one set of functions that work with an iterator, plus a simple way to convert an index to an iterator, rather than duplicating every function. And iterators are the generic way of working with standard containers, indexes are just a specific access for vectors and strings.

Quote
But do you think it's better to use iterators all the time (even as loop-counting variables)?

Of course it is ! :)
There's really no advantage to use indices where iterators could be used.

Quote
Because at the moment I try to avoid them wherever possible

Why ? That's definitively a bad habit.

Quote
Might it be significant for the performance if I got big sf::Sprite vectors which are drawn every frame?

Using iterators or indexes will hardly make any difference in your program, especially when we talk about real-time graphics... That's nanoseconds (for container access) versus milliseconds (for displaying sprites).
Or, if you prefer, thats an integer multiplication + addition versus setting render states, sending geometry through AGP or PCI express, and going through the whole graphics pipeline (transform, lighting, clipping rasterization, texturing, blending, ...).
Title: Drawing Everything
Post by: Nexus on May 18, 2008, 05:16:04 pm
So the argument for iterators is the flexibility and not the performance?
Therefore I can leave my lovely indexes for the next time ;)  - no I think I will change my code.

Quote from: "Laurent"
Quote
Because at the moment I try to avoid them wherever possible

Why ? That's definitively a bad habit.

I don't have a lot of experience with iterators, and I don't need the containers too intensely. I only use std::vector<> and std::string, and until now, everything worked well with indexes, so I didn't see any reason to use iterators.

But I didn't know about the iterator's advantages (and to tell the truth, still don't know everything), I thought it would be just a formal matter. Thank you for the declarations. I guess I will adapt my code. But what is now the point of using iterators? Wouldn't it be okay to use indexes in future? Are there some long-dated consequences I don't recognize yet?
Title: Drawing Everything
Post by: Redien on May 18, 2008, 05:49:27 pm
What if you want to change one of those vectors to a list in the future? Then your code would break and you would have to spend time rewriting parts of it.
Title: Drawing Everything
Post by: workmad3 on May 18, 2008, 07:04:18 pm
With a vector, I think indicies may be slightly faster, but are less flexible (you can only use them with vectors, deques and pointer-arrays) whereas iterator semantics can keep the same codewith any container, as long as you only use forward-iterator features (this is all you need to step sequentially through every element in a container, so pretty much all you need). The better method is to use structures that remove the need to worry about iterators in any way, shape or form though, such as with boost FOR_EACH, or writing a map-algorithm that can take a function (or functor) that will apply a function to each entry in a container. C++ 0x should contain much easier ways of doing this as well (such as an improved for_each construct and lambda functions :D) but that is still in the future. Performance wise though, indicies will be pretty much the same or worse than iterators when using anything other than a vector (and even then, iterators will be so close to index access that it makes no real difference. After all, a vector iterator is a really easy construct :))
Title: Drawing Everything
Post by: Kernelpanic on May 18, 2008, 08:47:36 pm
Why should they be faster in vectors and deques?
The adress must be evaluated, it is only less difficult than in a list.
Title: Drawing Everything
Post by: qsik on May 18, 2008, 11:30:27 pm
i cant get the last image to appear...what do i do!?

Code: [Select]
int x = 0;
int y = 144;

void SetPositions()
{
for (int repeat = 0; repeat < 26; repeat++)
{
int Position = 1;
Questions[Position].SetPosition(x,y);
Position = Position+1;
x = x=143;
if (x > 600)
y = y+1;

};
}


this also produces strange results
Title: Drawing Everything
Post by: Redien on May 19, 2008, 03:01:45 am
Code: [Select]
int Position = 1;
First of all, you're declaring the integer Position in the for-loop. So the code will only access the question at index 1. I'm guessing you want to loop through all the questions. Why don't you just use repeat instead of creating a new counter variable?

Code: [Select]
x = x=143;
I'm not sure what you want to do with this line, but it will produce the same code as
Code: [Select]
x = 143;
Title: Drawing Everything
Post by: qsik on May 19, 2008, 06:14:33 am
the above code was riddled with typos oops XD

when debugging, im getting lots of access violations?
Title: Drawing Everything
Post by: qsik on May 19, 2008, 06:54:53 am
sorry for double posting but the SVN just broke my code

Code: [Select]
#ifdef _DEBUG
#pragma comment(lib, "sfml-main-d.lib")
#pragma comment(lib, "sfml-system-s-d.lib")
#pragma comment(lib, "sfml-window-s-d.lib")
#pragma comment(lib, "sfml-graphics-s-d.lib")
#pragma comment(lib, "sfml-audio-s-d.lib")
#pragma comment(lib, "sfml-network-s-d.lib")
#endif
#ifdef NDEBUG
#pragma comment(lib, "sfml-main.lib")
#pragma comment(lib, "sfml-window-s.lib")
#pragma comment(lib, "sfml-system-s.lib")
#pragma comment(lib, "sfml-graphics-s.lib")
#pragma comment(lib, "sfml-audio-s.lib")
#pragma comment(lib, "sfml-network-s.lib")
#endif

#include "string"
#include "SFML/System.hpp"
#include "SFML/Window.hpp"
#include "SFML/Audio.hpp"
#include "SFML/Network.hpp"
#include "SFML/Graphics.hpp"


Code: [Select]
#include "SFML/Quickstart.h"

int Question = 0;
int JeopardyPos = 0;

int Jeopardy[25];
sf::Sprite Questions[25];
sf::Sprite HorizontalBars[5];
sf::Sprite VerticalBars[5];
sf::Sprite Categories[5];

sf::Image n100;
sf::Image n200;
sf::Image n300;
sf::Image n400;
sf::Image n500;

sf::Image Who;
sf::Image Dates;
sf::Image Where;
sf::Image Numbers;
sf::Image Random;

sf::Image HorizontalBar;
sf::Image VerticalBar;

int LoadImages()
{
if (!Who.LoadFromFile("G:/Jeopardy/Jeopardy Who.bmp"))
return EXIT_FAILURE;

if (!Dates.LoadFromFile("G:/Jeopardy/Jeopardy Dates.bmp"))
return EXIT_FAILURE;

if (!Where.LoadFromFile("G:/Jeopardy/Jeopardy Locations.bmp"))
return EXIT_FAILURE;

if (!Numbers.LoadFromFile("G:/Jeopardy/Jeopardy Numbers.bmp"))
return EXIT_FAILURE;

if (!Random.LoadFromFile("G:/Jeopardy/Jeopardy Random.bmp"))
return EXIT_FAILURE;

if (!n100.LoadFromFile("G:/Jeopardy/$100.bmp"))
return EXIT_FAILURE;

if (!n200.LoadFromFile("G:/Jeopardy/$200.bmp"))
return EXIT_FAILURE;

if (!n300.LoadFromFile("G:/Jeopardy/$300.bmp"))
return EXIT_FAILURE;

if (!n400.LoadFromFile("G:/Jeopardy/$400.bmp"))
return EXIT_FAILURE;

if (!n500.LoadFromFile("G:/Jeopardy/$500.bmp"))
return EXIT_FAILURE;

if (!VerticalBar.LoadFromFile("G:/Jeopardy/Jeopardy Vertical Bar.bmp"))
return EXIT_FAILURE;

if (!HorizontalBar.LoadFromFile("G:/Jeopardy/Jeopardy Horizontal Bar.bmp"))
return EXIT_FAILURE;

return EXIT_SUCCESS;
}

sf::Music Music;

int LoadMusic()
{
if (!Music.OpenFromFile("G:/Jeopardy/Jeopardy.wav"))
{
return EXIT_FAILURE;
};

return EXIT_SUCCESS;
}

void JeopardyArray()
{
for (int pos = 0; pos < 25; pos++)
{
Jeopardy[pos] = 1;
}
}

void QuestionsArray()
{
for (int sprite = 0; sprite < 25; sprite++)
{
if (sprite < 5)
Questions[sprite] = sf::Sprite(n100);
if (sprite < 10 && sprite > 4)
Questions[sprite] = sf::Sprite(n200);
if (sprite < 15 && sprite > 9)
Questions[sprite] = sf::Sprite(n300);
if (sprite < 20 && sprite > 14)
Questions[sprite] = sf::Sprite(n400);
if (sprite < 25 && sprite > 19)
Questions[sprite] = sf::Sprite(n500);
}
}

void BarArray()
{
for (int sprite = 0; sprite < 5; sprite++)
{
VerticalBars[sprite] = sf::Sprite(VerticalBar);
HorizontalBars[sprite] = sf::Sprite(HorizontalBar);
};
}

void SetPositions()
{
int x = 0;
int y = 148;

for (int repeat = 0; repeat < 25; repeat++)
{

Questions[repeat].SetPosition(x,y);
x = x+204;

if (x == 1020)
{
y = y+124;
x = 0;
};
};
}

int Load()
{
LoadImages();
LoadMusic();
Music.Play();
JeopardyArray();
QuestionsArray();
BarArray();
SetPositions();

return EXIT_SUCCESS;
}


Code: [Select]
#include "Headers.h"

int main()
{
sf::RenderWindow Window(sf::VideoMode(1024, 768, 32), "Jeopardy!", sf::Style::Fullscreen);
sf::Color Background(222, 41, 16);
Window.SetBackgroundColor(Background);
Load();
sf::Sprite C1(Who);
sf::Sprite C2(Dates);
sf::Sprite C3(Where);
sf::Sprite C4(Numbers);
sf::Sprite C5(Random);
C2.SetPosition(204,0);
C3.SetPosition(408,0);
C4.SetPosition(612,0);
C5.SetPosition(816,0);

bool Running = true;
while(Running)
    {
sf::Event Event;
const sf::Input& Input = Window.GetInput();
int MouseX = Input.GetMouseX();
int MouseY = Input.GetMouseY();
       
while (Window.GetEvent(Event))
        {
            if (Event.Type == sf::Event::Closed)
                Running = false;
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
Running = false;
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::F))
Music.Play();

if ((0 < MouseX && MouseX < 162 && 124 < MouseY && MouseY < 260) && (Event.MouseButton.Button == sf::Mouse::Left) && (Jeopardy[1] == 1))
{
Question = 1;
JeopardyPos = 1;

};

if ((Event.MouseButton.Button == sf::Mouse::Right) && (Question > 0))
{
Jeopardy[JeopardyPos] = 0;
Question = 0;
};
        };

for (int x = 0;  x < 25; x++)
{
Window.Draw(Questions[x]);
};
       
Window.Display();
    }
    return 0;
}
Title: Drawing Everything
Post by: Laurent on May 19, 2008, 09:57:26 am
Are we supposed to guess the errors ?
Title: Drawing Everything
Post by: qsik on May 19, 2008, 11:33:33 pm
the executable file doesnt load at all, debugging the application leaves me with lots of access violation errors?
Title: Drawing Everything
Post by: Redien on May 19, 2008, 11:49:54 pm
The reason you get access violations is because your for-statements try to access array elements that are outside the array boundries.

Read up on C++ arrays and try again.
http://www.cplusplus.com/doc/tutorial/arrays.html
Title: Drawing Everything
Post by: qsik on May 20, 2008, 05:32:18 am
i updated the above code and it should work yes? but it still doesn't run
Title: Drawing Everything
Post by: quasius on May 20, 2008, 07:58:42 am
Quote from: "qsik"
i updated the above code and it should work yes? but it still doesn't run


That's not enough information for anyone to help you.  Where and how does it crash?  Did you place breakpoints and step through the code to see where and why it crashes?
You need to do a bit more besides posting your entire project and asking "why doesn't it work?"

Edit:  What compiler are you using?  Do you know how to use breakpoints?  If not, you should google breakpoints for your compiler.  They are a very powerful debugging tool.
Title: Drawing Everything
Post by: qsik on May 21, 2008, 01:40:52 am
VC 2008 express edition
Title: Drawing Everything
Post by: eleinvisible on May 21, 2008, 03:42:41 am
I recommend at least copying and pasting the errors you get, and what lines it refers to, otherwise its like finding a (many) needles in a (very large) haystack.
Title: Drawing Everything
Post by: qsik on May 21, 2008, 08:26:55 am
it works now yay :)

now how would i implement getting if the mouse cursor is over a certain picture and detect the click on/in the picture to change to a different picture without pasting code?

Code: [Select]
if ((0 < MouseX && MouseX < 162 && 124 < MouseY && MouseY < 260) && (Event.MouseButton.Button == sf::Mouse::Left) && (Jeopardy[1] == 1))
{
Question = 1;
JeopardyPos = 1;

};

if ((Event.MouseButton.Button == sf::Mouse::Right) && (Question > 0))
{
Jeopardy[JeopardyPos] = 0;
Question = 0;
};
        };


my implementation so far
Title: Drawing Everything
Post by: quasius on May 21, 2008, 04:27:16 pm
Quote from: "qsik"
it works now yay :)

now how would i implement getting if the mouse cursor is over a certain picture and detect the click on/in the picture to change to a different picture without pasting code?

Code: [Select]
if ((0 < MouseX && MouseX < 162 && 124 < MouseY && MouseY < 260) && (Event.MouseButton.Button == sf::Mouse::Left) && (Jeopardy[1] == 1))
{
Question = 1;
JeopardyPos = 1;

};

if ((Event.MouseButton.Button == sf::Mouse::Right) && (Question > 0))
{
Jeopardy[JeopardyPos] = 0;
Question = 0;
};
        };


my implementation so far


I know I already posted this...  You need to divide the mouse x and y coords by the cell size x and y to get what cell it was over.  If there's an offset from the top/left of the screen, just subtract it out.
Title: Drawing Everything
Post by: qsik on May 21, 2008, 10:54:59 pm
cell size?? i dont get what you're talking about
Title: Drawing Everything
Post by: quasius on May 21, 2008, 11:01:25 pm
Quote from: "qsik"
cell size?? i dont get what you're talking about


The size of each question tile/cell/area/sprite/whatever-you-want-to-call-it
Title: Drawing Everything
Post by: workmad3 on May 21, 2008, 11:05:28 pm
It only works if you have arranged your images into a regular 'grid' with a specific width and height for each. Then you can use integer division on the mouse position to get a 'cell' in the grid and find which image you are over.

If you have an irregular grid or no grid at all, what you probably want instead is (using boost FOREACH as it's easy):
Code: [Select]

BOOST_FOREACH(Sprite s, vSprites)
{
   if ((MouseX > s.GetLeft() && MouseX < s.(GetLeft()+s.GetWidth())) && (MouseY < s.GetTop() && MouseY > (s.GetTop()-s.GetHeight()))
   {
      //Mouse position is over this sprite, do something about it here
   }
}

As usual, this is written straight into the browser so please forgive me for any syntax errors or minor issues :)
Title: Drawing Everything
Post by: qsik on May 22, 2008, 05:19:49 am
i still don't get how to do it...

so lets say i have an 6x5 grid of images which are all 204 x 153, how would i do it then?

Code: [Select]
for (int image = 0; image < 25; image ++)
{
    if (image * category[image].GetWidth() < mousex < category[image].GetWidth()+204) && (image * category[image].GetHeight() < mousey < category[image].GetHeight()+153)
    {
        //Do Things Here
    }
}
Title: Drawing Everything
Post by: Kernelpanic on May 22, 2008, 12:01:17 pm
Code: [Select]

image * category[image].GetWidth() < mousex < category[image].GetWidth()+204

THis means true/false < category[image].GetWidth()+204
Title: Drawing Everything
Post by: BloodGod on May 22, 2008, 03:02:41 pm
Hi =)

(http://img291.imageshack.us/img291/4826/coordjs0.jpg)

At the bottom are the conditions that have to be true!

And here is an example function which determines whether the mouse is over a sprite or not:

Code: [Select]

inline bool Overlap(sf::Sprite s,const sf::Input& input)
{
if((input.GetMouseX() >= s.GetLeft() && input.GetMouseY() >= s.GetTop()) &&
(input.GetMouseX() <= s.GetLeft()+s.GetWidth() && input.GetMouseY() <= s.GetTop()+s.GetHeight()))
return true;
else
return false;
}


usage:
Code: [Select]

if(Overlap(Sprite, App.GetInput()) == true)
     std::cout << "yeah" << std::endl;


Sincerely,
BloodGod
Title: Drawing Everything
Post by: qsik on May 25, 2008, 05:48:55 pm
lets say i have something on a flash drive, how do i make it so the program can access the media on the flash drive even though its letter changes? (ex. the flash drive is G:/flash drive on one computer and F:/flash drive on another and putting G:/flash drive in the code will cause an error on the computer that is F:/flash drive)
Title: Drawing Everything
Post by: quasius on May 25, 2008, 06:28:25 pm
Quote from: "qsik"
lets say i have something on a flash drive, how do i make it so the program can access the media on the flash drive even though its letter changes? (ex. the flash drive is G:/flash drive on one computer and F:/flash drive on another and putting G:/flash drive in the code will cause an error on the computer that is F:/flash drive)


Honestly, based on what you've posted so far, you're probably getting in way over your head with something like that.  Do you really need to do that?  If you must do something like that, google "boost filesystem"

Edit:  Thinking more about this, you are probably asking this question because you are (incorrectly) using absolute file paths.  You should only be using relative paths based on your working directory.  Then it doesn't matter where the app is stored (USB, HDD, network drive, whatever)
Title: Drawing Everything
Post by: qsik on May 25, 2008, 11:26:20 pm
it doesnt work because im using images from my flash drive but the working directory is C:

>>what do i do now?

>>EDIT>>also, it seems that GetLeft(), GetTop(), etc. have been removed, how do i substitue functions to return the same effect?
Title: Drawing Everything
Post by: quasius on May 26, 2008, 01:43:16 am
Quote from: "qsik"
it doesnt work because im using images from my flash drive but the working directory is C:

>>what do i do now?

>>EDIT>>also, it seems that GetLeft(), GetTop(), etc. have been removed, how do i substitue functions to return the same effect?


If the working directory is actually C: (which seems strange), just don't include the drive letter.  It doesn't matter what the working dir is.  Just reference all your files from that dir, not the root.
The answer to your second question is GetPosition().
Title: Drawing Everything
Post by: qsik on May 26, 2008, 01:54:54 am
sorry if i didnt make the post very clear

im making the program on my hard drive, directory C:

i have a flash drive attached where i copy the exe and it contains the images/music/etc. i need for the program

when using LoadFromFile("../../Jeopardy.bmp"), i get an access violation error during runtime

also, how does one use GetPosition()? i keep getting something about the position being a Vector2f?
Title: Drawing Everything
Post by: quasius on May 26, 2008, 02:03:28 am
Quote from: "qsik"
sorry if i didnt make the post very clear

im making the program on my hard drive, directory C:

i have a flash drive attached where i copy the exe and it contains the images/music/etc. i need for the program

when using LoadFromFile("../../Jeopardy.bmp"), i get an access violation error during runtime

also, how does one use GetPosition()? i keep getting something about the position being a Vector2f?


Well, if you are actually using C: as your directory, "../../Jeopardy.bmp" will cause an access violation since that references 2 directories up, which is impossible if you're starting at the root of C.

Edit:  I don't believe C: is actually your directory...
Title: Drawing Everything
Post by: qsik on May 26, 2008, 02:05:08 am
i keep forgetting to add

im building my program on C: (hard drive) but the flash drive reads as G: on my computer

also, the files are in Flash Drive Root:/Jeopardy
Title: Drawing Everything
Post by: quasius on May 26, 2008, 02:07:34 am
Quote from: "qsik"
i keep forgetting to add

im building my program on C: (hard drive) but the flash drive reads as G: on my computer

also, the files are in Flash Drive Root:/Jeopardy


Tell me what the difference between a relative and an absolute path is.  Also, tell me what a working directory is.

Edit:  To be clear, I'm trying to get you to figure out some of this by yourself.  I'll help you, but I won't do your homework for you.  And to anyone else considering just posting some code, that's not really helping him.
Title: Drawing Everything
Post by: qsik on May 26, 2008, 05:21:52 am
i got it to work, just changed the working directory in the project settings :)

i still dont get the vector2f variable used for the position
Title: Drawing Everything
Post by: dunce on May 26, 2008, 05:32:37 am
Returning to this topic title...
IMO, using one-dimention container for representing a kind of render queue is suitable for very simple scenes. In my engine based on sfml I'm mplementing a scene manager with a tree-based scene graph. It is much more complicated, but it gives possibilites for real scene management (transformation, rotation, visibility control, rendering etc.). Scene graphs are mostly considered to be parts of 3d scene managers, but I decided to try them in a 2d engine. In my implementation each nood has a container for child noods based on std::vector. For now I can say nothing about how fast this implementation will be.
Title: Drawing Everything
Post by: qsik on May 26, 2008, 05:05:20 pm
i get it now, ive figured out how to use GetPosition();

quasius and the others, thnx for your help
Title: Drawing Everything
Post by: qsik on May 26, 2008, 07:59:51 pm
strange runtime error! my code checks to see if all images in the column have been clicked and when they are, the top image disappears but clicking on just the last image in the column causes the top image to disappear!

checking code
Code: [Select]

int CheckCategory(int category)
{
int check;
category = category - 1;
int end = category + 30;

for (; category < end;)
{
check = 0 + Jeopardy[category];
category = category + 6;
};

return check;
}


Code: [Select]
bool Clicked(int position, const sf::Input& Input)
{
int MouseX = Input.GetMouseX();
int MouseY = Input.GetMouseY();
bool MouseClicked = Input.IsMouseButtonDown(sf::Mouse::Left);
sf::Vector2f Position = Money[position].GetPosition();

if ((MouseX >= Position.x) && (MouseX <= (Position.x + 170))
&& (MouseY >= Position.y) && (MouseY <= (Position.y + 128))
&& (Jeopardy[position] == 1) && (MouseClicked == true))
return true;
else
return false;
}


         
Code: [Select]
if (Clicked(0, Window.GetInput()) == true)
Jeopardy[0] = 0;
if (Clicked(6, Window.GetInput()) == true)
Jeopardy[6] = 0;
if (Clicked(12, Window.GetInput()) == true)
Jeopardy[12] = 0;
if (Clicked(18, Window.GetInput()) == true)
Jeopardy[18] = 0;
if (Clicked(24, Window.GetInput()) == true)
Jeopardy[24] = 0;


Code: [Select]
if (CheckCategory(1) > 0)
Window.Draw(Categories[0]);


all of Jeopardy's values are set to 1 initially
Title: Drawing Everything
Post by: quasius on May 27, 2008, 07:58:42 am
Obviously hard for me to just guess, but did you set a breakpoint for when you click on the last image and step through the code?  Maybe something is wrong with your function that determines what was clicked.  Maybe you're accidentally using the same index for both images.
You should really take a bit of time to familiarize yourself with breakpoints and the debugger.  They are very powerful and essential in modern code debugging.  You should be able to answer questions like this very quickly with proper breakpoint usage.

Edit:  No problem on the help.  I don't mind helping new programmers.  I just stop short of writing code for them, since I don't think it's really helpful.
Title: Drawing Everything
Post by: eleinvisible on May 29, 2008, 11:53:09 pm
I don't mean to sound like a jerk, but sometimes the best way to debug your programs is to test them yourself. Most of these problems could have been fixed with thinking or creativity, however I can see why you would ask questions about certain techniques... And quasius has a point, if you write code for someone new, you're doing them a disfavor.
Title: Drawing Everything
Post by: quasius on May 30, 2008, 07:52:04 pm
Quote from: "eleinvisible"
I don't mean to sound like a jerk, but sometimes the best way to debug your programs is to test them yourself. Most of these problems could have been fixed with thinking or creativity, however I can see why you would ask questions about certain techniques... And quasius has a point, if you write code for someone new, you're doing them a disfavor.


Careful...  it's easy to forget what you didn't know when you started programming.  Opening up an IDE like visual studio 2005 for the first time is very intimidating.  It's hard to use breakpoints when you've never heard of breakpoints.
You can point someone in the right direction without giving them the answer, which is helpful.  Yes, you learn by figuring things out yourself.  But a bit more guidance than throwing someone into the deep end and yelling "don't drown!" is useful.
Title: Drawing Everything
Post by: qsik on June 02, 2008, 04:41:08 am
after debugging, i think the check to see if all images in the row are clicked and gone code is incorrect-here it is and its usage

code
Code: [Select]
int CheckCategory(int category)
{
int check;
category = category - 1;
int end = category + 30;

for (; category < end; category = category + 6)
{
check = 0 + Jeopardy[category];
};

return check;
}


usage
Code: [Select]
if (CheckCategory(1) > 0)
Window.Draw(Categories[0]);
Title: Drawing Everything
Post by: quasius on June 04, 2008, 09:23:17 pm
I'm not sure if you're asking a question or telling us you solved it...
Title: Drawing Everything
Post by: qsik on June 04, 2008, 11:33:15 pm
i just wanted ppl to check to see if my code is correct, because im totally lost as why my application is acting this way.
Title: Drawing Everything
Post by: quasius on June 05, 2008, 12:26:29 am
I'm not sure what you think your check function is doing since it's not commented and has no context, but I'm pretty sure the whole thing is equivalent to
Code: [Select]

return Jeopardy[category + 25];


Did you step through the code with breakpoint /watchlist debugging?
Title: Drawing Everything
Post by: qsik on June 09, 2008, 05:40:35 pm
i didnt step through debugging cause im a total beginner at that sort of thing...where could i find tutorials?

the clickcheck function checks to see if you clicked on an image then sets the appropriate number in the Jeopardy array as 0. The CheckCategory function adds up all the respective numbers of the specified column of images on the Jeopardy array and if that number is greater than 0, it will draw the category image but if the number is 0, it will not draw the image. clicking on the last image for some reason causes the function to somehow believe the number is 0, even though the other numbers in the array are still 1.
Title: Drawing Everything
Post by: quasius on June 09, 2008, 09:28:41 pm
Quote from: "qsik"
i didnt step through debugging cause im a total beginner at that sort of thing...where could i find tutorials?


um... google.  I found this in less than a minute: http://www.odetocode.com/Articles/425.aspx

How much time did you spend looking?