SFML community forums

Help => Graphics => Topic started by: qsik on August 04, 2008, 05:46:10 am

Title: Draw Missing!?
Post by: qsik on August 04, 2008, 05:46:10 am
i just updated to the latest SVN and for some reason my [window name].Draw function is missing!? what should i do?
Title: Draw Missing!?
Post by: qsik on August 04, 2008, 05:57:48 am
nvmd, i needed a renderwindow instead of a window to draw images...when did that change?
Title: Draw Missing!?
Post by: Laurent on August 04, 2008, 06:03:34 am
That never changed, there's nothing related to 2D graphics in sfml-window.
Title: Draw Missing!?
Post by: qsik on August 04, 2008, 06:57:38 am
using VS 2008 + SVN version...its been awhile since ive used SFML

im getting a debug assertation, but im pretty sure im using the code right

i load the image here in the header file

Code: [Select]
int LoadImages()
{
if (!Opening.LoadFromFile("C:/Jeopardy/Other/Opening.jpg"))
return EXIT_FAILURE;


wrap up the function in the same file
Code: [Select]

int Load()
{
LoadImages();


then assign the image to a sprite in the main .cpp file
Code: [Select]
int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Jeopardy!", sf::Style::Fullscreen);
Load();
OpeningImage.SetImage(Opening);


and display it after the event loop
Code: [Select]

App.Clear();
App.Draw(OpeningImage);
App.Display();


what am i doing wrong?
Title: Draw Missing!?
Post by: Laurent on August 04, 2008, 06:59:54 am
What is the assertion message ? On which line is it happening ?
Title: Draw Missing!?
Post by: qsik on August 05, 2008, 11:17:07 pm
it happens when i get to the
Code: [Select]
App.Draw(OpeningImage);

breaking out of the program leads me to this section of code but points specifically to the line with _DEBUG_ERROR...

Code: [Select]
#if _HAS_ITERATOR_DEBUGGING
if (size() <= _Pos)
{
_DEBUG_ERROR("vector subscript out of range");
_SCL_SECURE_OUT_OF_RANGE;
}


error-debug assertation failed, line 779, vector subscript out of range
Title: Draw Missing!?
Post by: Laurent on August 06, 2008, 02:44:19 am
Line 779 of which file ? Can you run it in debug mode and get the callstack ?

Basically, I'm almost sure there isn't any "out of range" error with vectors in SFML, so the problem might come from your code.
Title: Draw Missing!?
Post by: qsik on August 06, 2008, 03:29:38 am
my code just in case

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

std::string base = "../Jeopardy/Questions/Question";
std::string end = ".png";
std::string final;

sf::Sprite Categories[6];
sf::Sprite OpeningImage;

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

sf::Image Category1;
sf::Image Category2;
sf::Image Category3;
sf::Image Category4;
sf::Image Category5;
sf::Image Category6;

sf::Image Question;
sf::Image Answer;
sf::Image Opening;
sf::Image FinalJeopardy;
sf::Image DailyDouble;

sf::Music OpeningMusic;
sf::Music FinalJeopardyMusic;

/*/int LoadQuestion(int QuesNumber)
{
std::string middle = Convert(QuesNumber);
std::string Q = base + middle + end;
if (!Ques.LoadFromFile(Q))
return EXIT_FAILURE;
}/*/

int LoadImages()
{
if (!Opening.LoadFromFile("C:/Jeopardy/Other/Opening.jpg"))
return EXIT_FAILURE;

if (!Category1.LoadFromFile("C:/Jeopardy/Categories/Slide1.gif"))
return EXIT_FAILURE;

if (!Category2.LoadFromFile("../Jeopardy/Categories/Slide2.gif"))
return EXIT_FAILURE;

if (!Category3.LoadFromFile("../Jeopardy/Categories/Slide3.gif"))
return EXIT_FAILURE;

if (!Category4.LoadFromFile("../Jeopardy/Categories/Slide4.gif"))
return EXIT_FAILURE;

if (!Category5.LoadFromFile("../Jeopardy/Categories/Slide5.gif"))
return EXIT_FAILURE;

if (!Category6.LoadFromFile("../Jeopardy/Categories/Slide6.gif"))
return EXIT_FAILURE;

if (!n100.LoadFromFile("../Jeopardy/Money/Slide1.bmp"))
return EXIT_FAILURE;

if (!n200.LoadFromFile("../Jeopardy/Money/Slide2.bmp"))
return EXIT_FAILURE;

if (!n300.LoadFromFile("../Jeopardy/Money/Slide3.bmp"))
return EXIT_FAILURE;

if (!n400.LoadFromFile("../Jeopardy/Money/Slide4.bmp"))
return EXIT_FAILURE;

if (!n500.LoadFromFile("../Jeopardy/Money/Slide5.bmp"))
return EXIT_FAILURE;

return EXIT_SUCCESS;
}

int LoadOpeningMusic()
{
if (!OpeningMusic.OpenFromFile("../Jeopardy/Music/Opening.wav"))
{
return EXIT_FAILURE;
};

return EXIT_SUCCESS;
}



int LoadFinalJeopardyMusic()
{
if (!FinalJeopardyMusic.OpenFromFile("../Jeopardy/Music/Final Jeopardy.wav"))
{
return EXIT_FAILURE;
};

return EXIT_SUCCESS;
}

void CategoryArray()
{
Categories[0] = sf::Sprite(Category1);
Categories[1] = sf::Sprite(Category2);
Categories[2] = sf::Sprite(Category3);
Categories[3] = sf::Sprite(Category4);
Categories[4] = sf::Sprite(Category5);
Categories[5] = sf::Sprite(Category6);
}

int Load()
{
LoadImages();
LoadOpeningMusic();
LoadFinalJeopardyMusic();
OpeningMusic.Play();
CategoryArray();

return EXIT_SUCCESS;
}



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

int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Jeopardy!", sf::Style::Fullscreen);
Load();
OpeningImage.SetImage(Opening);

while(App.IsOpened())
    {
sf::Event Event;
while (App.GetEvent(Event))
        {
            if (Event.Type == sf::Event::Closed)
                App.Close();
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();
if ((Event.Type == sf::Event::MouseButtonPressed) && (Event.MouseButton.Button == sf::Mouse::Left))
App.Close();
};

App.Clear();
App.Draw(OpeningImage);
App.Display();
    };

return 1;
}


call stack

Code: [Select]
> Jeopardy.exe!std::vector<sf::Color,std::allocator<sf::Color> >::operator[](unsigned int _Pos=0)  Line 780 + 0x2e bytes C++
  Jeopardy.exe!sf::Image::Update()  Line 549 + 0xd bytes C++
  Jeopardy.exe!sf::Image::Bind()  Line 360 C++
  Jeopardy.exe!sf::Sprite::Render(sf::RenderTarget & __formal={...})  Line 192 C++
  Jeopardy.exe!sf::Drawable::Draw(sf::RenderTarget & Target={...})  Line 396 + 0x13 bytes C++
  Jeopardy.exe!sf::RenderTarget::Draw(const sf::Drawable & Object={...})  Line 105 C++
  Jeopardy.exe!main()  Line 24 C++
  Jeopardy.exe!_WinMain@16()  + 0x19 bytes C++
  Jeopardy.exe!__tmainCRTStartup()  Line 574 + 0x35 bytes C
  Jeopardy.exe!WinMainCRTStartup()  Line 399 C


the file that breaking out of the program leads to is vector.h (the vc 2008 sdk file i think)
Title: Draw Missing!?
Post by: Laurent on August 06, 2008, 06:13:18 am
Ok, I've found the bug. There's no protection when creating an OpenGL texture from an empty image, I'll fix this. By the way, this means one of your images failed to load.
Title: Draw Missing!?
Post by: qsik on August 06, 2008, 06:52:17 am
failed to load due to a bug or due to my code?
Title: Draw Missing!?
Post by: Laurent on August 06, 2008, 07:06:54 am
Should be due to your code, but apparently you properly handle loading errors. Unless you try to load a valid empty image ;)

By the way, GIF is not a supported format.
Title: Draw Missing!?
Post by: qsik on August 07, 2008, 12:33:02 am
that would explain it, all my images are gifs...

changing them to pngs should work then thnx
Title: Draw Missing!?
Post by: qsik on August 07, 2008, 02:06:32 am
i changed them all to pngs but they still dont work! i get the same error, oddly my images wont bind to the sf::Image variables for some odd reason
Title: Draw Missing!?
Post by: Laurent on August 07, 2008, 02:34:19 am
You should check the standard error output for any SFML message.

You should also use the value returned by your loading functions to actually do something useful when they report an error ;)
Title: Draw Missing!?
Post by: qsik on August 07, 2008, 03:15:34 am
my images are failing to load...is my code for loading images incorrect because i checked the path and it is correct
Title: Draw Missing!?
Post by: Laurent on August 07, 2008, 03:40:39 am
Your code is correct. Maybe the current working path is not the one you think it is.
Title: Draw Missing!?
Post by: qsik on August 07, 2008, 05:55:01 am
i fixed it! oddly, the jpg file wouldnt load but converting it to a png solved the problem
Title: Draw Missing!?
Post by: qsik on August 09, 2008, 06:15:07 am
*bump for update email
Title: Draw Missing!?
Post by: qsik on August 10, 2008, 12:51:21 am
how would i get the path of where the exe is? that way i can load images and music even if the name of the folders change

also, i switched to using arrays, so i have sf::Image other[5] instead of sf::Image Opening and such, but the image does not load for some reason...it did before
Title: Draw Missing!?
Post by: qsik on August 10, 2008, 01:49:39 am
heres my code, i cant seem to find why it wont work plz check for errors due to misused/wrong syntax

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

int width;
int height;
int IW;
int IH;
int begin;
int finish;

std::string base = "C:/Jeopardy/";
std::string end = ".png";

sf::Sprite Categories[6];
sf::Sprite Money[5];
sf::Sprite Opening;
sf::Sprite Questions[30];
sf::Sprite Answers[30];

sf::Image categories[6];
sf::Image money[5];
sf::Image questions[30];
sf::Image answers[30];
sf::Image opening;
sf::Music OpeningMusic;
sf::Music FinalJeopardyMusic;

void GetDesktopMode()
{
sf::VideoMode DesktopMode = sf::VideoMode::GetDesktopMode();
width = DesktopMode.Width;
height = DesktopMode.Height;
}

int LoadImages()
{
for(begin = 0, finish = 5; begin < finish; begin++)
{
std::string middle = Convert(begin);
std::string image = base + "Categories/Slide" + middle + end;
if (!categories[begin].LoadFromFile(image))
return EXIT_FAILURE;
};

for(begin = 0, finish = 4; begin < finish; begin++)
{
std::string middle = Convert(begin);
std::string image = base + "Categories/Money" + middle + end;
if (!money[begin].LoadFromFile(image))
return EXIT_FAILURE;
};

for(begin = 0, finish = 29; begin < finish; begin++)
{
std::string middle = Convert(begin);
std::string image = base + "Categories/Questions" + middle + end;
if (!questions[begin].LoadFromFile(image))
return EXIT_FAILURE;
};

for(begin = 0, finish = 29; begin < finish; begin++)
{
std::string middle = Convert(begin);
std::string image = base + "Categories/Answers" + middle + end;
if (!answers[begin].LoadFromFile(image))
return EXIT_FAILURE;
};

if (!opening.LoadFromFile("C:/Jeopardy/Other/Opening.png"))
return EXIT_FAILURE;

return EXIT_SUCCESS;
}


void LoadSprites()
{
for (begin = 0, finish = 5; begin < finish; begin++)
Categories[begin] = sf::Sprite(categories[begin]);

for (begin = 0, finish = 4; begin < finish; begin++)
Money[begin] = sf::Sprite(money[begin]);

Opening.SetImage(opening);

for (begin = 0, finish = 29; begin < finish; begin++)
Questions[begin] = sf::Sprite(questions[begin]);

for (begin = 0, finish = 29; begin < finish; begin++)
Answers[begin] = sf::Sprite(answers[begin]);
}

void ScaleSprites()
{
for (begin = 0, finish = 5; begin < finish; begin++)
{
IW = categories[begin].GetWidth();
IH = categories[begin].GetHeight();
IW = ((width/6) * IW);
IH = ((height/6) * IH);
Categories[begin].Scale(IW, IH);
};

for (begin = 0, finish = 4; begin < finish; begin++)
{
IW = money[begin].GetWidth();
IH = money[begin].GetHeight();
IW = ((width/6) * IW);
IH = ((height/6) * IH);
Money[begin].Scale(IW, IH);
};

for (begin = 0, finish = 29; begin < finish; begin++)
{
IW = questions[begin].GetWidth();
IH = questions[begin].GetHeight();
IW = ((width/6) * IW);
IH = ((height/6) * IH);
Questions[begin].Scale(IW, IH);
};

for (begin = 0, finish = 29; begin < finish; begin++)
{
IW = answers[begin].GetWidth();
IH = answers[begin].GetHeight();
IW = ((width/6) * IW);
IH = ((height/6) * IH);
Answers[begin].Scale(IW, IH);
};
}

int LoadMusic()
{
if (!OpeningMusic.OpenFromFile("C:/Jeopardy/Music/Opening.wav"))
return EXIT_FAILURE;

if (!FinalJeopardyMusic.OpenFromFile("C:/Jeopardy/Music/Final Jeopardy.wav"))
return EXIT_FAILURE;

return EXIT_SUCCESS;
}

int Load()
{
GetDesktopMode();
LoadImages();
LoadSprites();
LoadMusic();
ScaleSprites();
OpeningMusic.Play();

return EXIT_SUCCESS;
}



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

int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Jeopardy!");
Load();


while(App.IsOpened())
    {
sf::Event Event;
while (App.GetEvent(Event))
        {
            if (Event.Type == sf::Event::Closed)
                App.Close();
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();
};

App.Clear();

App.Draw(Opening);

App.Display();
    };

return EXIT_SUCCESS;
}
Title: Draw Missing!?
Post by: quasius on August 10, 2008, 05:26:42 am
Quote from: "qsik"
heres my code, i cant seem to find why it wont work plz check for errors due to misused/wrong syntax


You need to tell us exactly what's not working as expected and post just the relevant code.  You can't post your entire app, ask "why doesn't it work?" and expect meaningful help.  You need to help us help you.
Title: Draw Missing!?
Post by: quasius on August 10, 2008, 05:29:25 am
Quote from: "qsik"
how would i get the path of where the exe is? that way i can load images and music even if the name of the folders change

also, i switched to using arrays, so i have sf::Image other[5] instead of sf::Image Opening and such, but the image does not load for some reason...it did before


Getting the working directory is OS-specific.  You will need to google "get working directory c++ <OS name>."
As for arrays of images, that should work fine.  You probably have a problem somewhere else.  Are you sure you are indexing them correctly?
Title: Draw Missing!?
Post by: zarka on August 10, 2008, 10:18:58 am
Quote from: "qsik"
how would i get the path of where the exe is? that way i can load images and music even if the name of the folders change


if you have a folder structure like this:
Code: [Select]

game_folder
| - exe
| - data_folder
     | - img.png

you could in your code write img.LoadFromFile("data_folder/img.png");

This will work on most operating systems(at least windows, linux and mac OS) and is how most people do it :)
Title: Draw Missing!?
Post by: zac on August 10, 2008, 03:50:58 pm
Getting the working dir in Windows uses the function "GetCurrentDirectory". The description of this function will be at msdn.microsoft.com .
In Linux, you have to usw getcwd() (take google/view die-linux manpages)...
by the way, you could use relative paths...

To get the real directory of your executable file in Windows, you use first:
GetCurrentProcess() to a call to GetModuleFileNameEx.
Again, both functions are described at msdn.microsoft.com .
Title: Draw Missing!?
Post by: qsik on August 10, 2008, 05:23:01 pm
using the SVN version of SFML with VC 2008, i cant get my images to load (checking the image variables when debugging shows them to be empty :( )
i posted my code to see if anyone could find anything wrong with the code (as in incorrect syntax)
Title: Draw Missing!?
Post by: Avency on August 10, 2008, 06:06:06 pm
I'd suggest that you should use relative path names, get the working directory or use some sort of system variable instead of using hardcoded pathnames...seriously!!!
Is there any error output (like "can't fopen")?
Maybe your "Convert" function produces a  unwanted result.
Title: Draw Missing!?
Post by: qsik on August 10, 2008, 06:48:09 pm
yes, but the Opening sprite does not appear even though it does it has a hardcoded path, my question is why it wont appear
Title: Draw Missing!?
Post by: qsik on August 11, 2008, 02:35:31 am
u were right, the for loops in my LoadImages(); was causing my sf::Image Opening to not load...odd

for images, are vectors better than arrays?

otherwise, im not sure how to mass load images in succession, ex. my program looks through subfolders for images labled Slide1, Slide2, ... and so forth

how would i go about achieving this effect? i tried converting ints to string as in my current program but it doesnt seem to work
Title: Draw Missing!?
Post by: quasius on August 11, 2008, 03:10:51 am
Quote from: "qsik"
u were right, the for loops in my LoadImages(); was causing my sf::Image Opening to not load...odd

for images, are vectors better than arrays?

otherwise, im not sure how to mass load images in succession, ex. my program looks through subfolders for images labled Slide1, Slide2, ... and so forth

how would i go about achieving this effect? i tried converting ints to string as in my current program but it doesnt seem to work


There should be nothing wrong with using arrays (or vectors) or images.  Step through your code in the debugger, checking the variables along the way to find where it's doing something you don't expect.
Title: Draw Missing!?
Post by: qsik on August 11, 2008, 05:42:17 am
i fixed my image code, but i still cant get GetModuleFileName to work, how do i use it so i can get a string to use? if i use strings, i get errors but i dont know how to turn TCHARS into strings!
Title: Draw Missing!?
Post by: qsik on August 11, 2008, 07:48:40 am
this is odd, for some reason, images dont load for the questions and answers arrays even though they do for the other arrays...is my syntax wrong?

Code: [Select]
int LoadImages()
{
for(int begin = 0, finish = 6, place = 1; begin < finish; begin++, place++)
{
std::string base = "C:/Jeopardy/";
std::string end = ".png";
std::string middle;
std::string image;
middle = Convert(place);
image = base + "Other/Slide" + middle + end;
if (!other[begin].LoadFromFile(image))
return EXIT_FAILURE;
};

for(int begin = 0, finish = 6, place = 1; begin < finish; begin++, place++)
{
std::string base = "C:/Jeopardy/";
std::string end = ".png";
std::string middle;
std::string image;
middle = Convert(place);
image = base + "Categories/Slide" + middle + end;
if (!categories[begin].LoadFromFile(image))
return EXIT_FAILURE;
};

for(int begin = 0, finish = 5, place = 1; begin < finish; begin++, place++)
{
std::string base = "C:/Jeopardy/";
std::string end = ".png";
std::string middle;
std::string image;
middle = Convert(place);
image = base + "Money/Slide" + middle + end;
if (!money[begin].LoadFromFile(image))
return EXIT_FAILURE;
};

for(int begin = 0, finish = 30, place = 1; begin < finish; begin++, place++)
{
std::string base = "C:/Jeopardy/";
std::string end = ".png";
std::string middle;
std::string image;
middle = Convert(place);
image = base + "Questions/Slide" + middle + end;
if (!questions[begin].LoadFromFile(image))
return EXIT_FAILURE;
};

for(int begin = 0, finish = 30, place = 1; begin < finish; begin++, place++)
{
std::string base = "C:/Jeopardy/";
std::string end = ".png";
std::string middle;
std::string image;
middle = Convert(place);
image = base + "Answers/Slide" + middle + end;
if (!answers[begin].LoadFromFile(image))
return EXIT_FAILURE;
};

return EXIT_SUCCESS;
}
Title: Draw Missing!?
Post by: qsik on August 13, 2008, 06:32:59 am
a little help plz?

*posting cause ive had so many edits, i dont know if the message of a new post shows up
Title: Draw Missing!?
Post by: quasius on August 13, 2008, 07:02:21 am
Quote from: "qsik"
a little help plz?

*posting cause ive had so many edits, i dont know if the message of a new post shows up


Since you never answered the first time...  Have you stepped through that part of the code with a debugger, watching all relevant variables to make sure it's doing what you think it is?
Title: Draw Missing!?
Post by: qsik on August 13, 2008, 07:13:19 am
i looked at the sf::Image questions/answers arrays and in the questions, only 3 images load while none load in the answers array

--the VC++ debugger cant seem to check variables unless they're global and also, since i have many functions wrapped up into a single load function, i cant find exactly whats going wrong...only something is wrong with my LoadImages()

--could u also help me with figuring out how to convert TCHARS into a std::string?
Title: Draw Missing!?
Post by: Laurent on August 13, 2008, 09:51:40 am
Quote
--the VC++ debugger cant seem to check variables unless they're global

Make sure you're executing a debug build with debug informations generated.
You can also search for some debugger tutorials, after all this is the most powerful tool you'll ever use as a programer ;)

Quote
could u also help me with figuring out how to convert TCHARS into a std::string?

If you're building in unicode mode, TCHAR* is an array of wide chars, and you'll need functions like std::ctype::narrow or wstombs to convert.
If you're not in unicode mode, TCHAR* is a regular array of char and the conversion is automatic.
But where do you get your TCHARs from ?
Title: Draw Missing!?
Post by: qsik on August 13, 2008, 04:30:49 pm
ok, thnx for the info

im using unicode and trying to use GetModuleFileName(), which only takes TCHARS when using unicode otherwise i get a conversion error

--i read up on wstombs but i didnt really get how to use it

*could u check to see if my for loop syntax is correct? some of the images in the last two for loops are not loading for some reason
Title: Draw Missing!?
Post by: quasius on August 13, 2008, 05:22:49 pm
Quote from: "qsik"

*could u check to see if my for loop syntax is correct? some of the images in the last two for loops are not loading for some reason


Did you get the debugger working?
I'm really not trying to be an ass here, but you absolutely must learn to use a debugger if you have any plans of being a programmer.  I'd much rather point you to tools to help yourself than just debugging your code and posting fixes.  I've been programming for 10+ years first as a hobby and then professionally and I still make "syntax errors" all the time.  But the debugger is the efficient tool for finding and eliminating those errors without anyone else's help.
In fact, if I were to fix your code, I'd c/p it into an IDE and use the debuggger.  But that wouldn't really help you much beyond the immediate problem.

Edit:  Your for loops, while possibly correct, are *extremely* non-standard and needlessly complex.  I'd look there first for problems.
It's rare to need a for loop not of the form:

for (unsigned int i = 0; i < nFinish; i++)
{
     .....
}

Then just index off of i.  If you want to start at a different index, just init i to something other than 0.  It's extremely rare to need multiple init statements as you are doing.  I've probably done than once or twice in the last year.
Also returning stuff like EXIT_SUCCESS and EXIT_FAILURE from functions is non-standard.  That's generally used for the main function only.  You can do it, but it looks strange and you'll probably get asked about it at some point.
In your case, it probably just makes sense to return a bool and return false on an error and true otherwise.
If you want an "error code" system, you should probably define stuff other than EXIT_SUCCESS and EXIT_FAILURE.
Title: Draw Missing!?
Post by: qsik on August 13, 2008, 06:55:53 pm
thnx for the advice, ill take it to heart

i do have it in an IDE, VC 2008 express, but im not very good with the debugger

--im just a C++ newbie coming from calculator BASIC
Title: Draw Missing!?
Post by: quasius on August 13, 2008, 07:09:00 pm
Quote from: "qsik"
thnx for the advice, ill take it to heart

i do have it in an IDE, VC 2008 express, but im not very good with the debugger

--im just a C++ newbie coming from calculator BASIC


That's fine.  Calculator BASIC was some of my first programming too.  Check the stuff that Laurent suggested a couple of posts ago and read something like this: http://www.cs.uvm.edu/~upe/resources/debugging/visualStudioCDebug/

The debugger is not actually that complicated, but it's extremely powerful.
Title: Draw Missing!?
Post by: qsik on August 13, 2008, 09:29:37 pm
very odd, this for loop breaks out after 5 iterations...even though it should run 30 times right?
Code: [Select]

int LoadImages3()
{
for(int i = 0; i < 30; i++)
{
middle = Convert((i + 1));
image = base + "Questions/Slide" + middle + end;
if (!questions[i].LoadFromFile(image))
return -1;
image = base + "Answers/Slide" + middle + end;
if (!answers[i].LoadFromFile(image))
return -1;
};

return 1;
}
Title: Draw Missing!?
Post by: zac on August 13, 2008, 09:47:42 pm
For unicode support, most of the Windows API Functions have a "W" version (W like Wide Character)... Just use "GetModuleFileNameExW"... it should take 16-bit WCHAR strings as arguments...
Title: Draw Missing!?
Post by: quasius on August 13, 2008, 09:57:30 pm
Quote from: "qsik"
very odd, this for loop breaks out after 5 iterations...even though it should run 30 times right?
Code: [Select]

int LoadImages3()
{
for(int i = 0; i < 30; i++)
{
middle = Convert((i + 1));
image = base + "Questions/Slide" + middle + end;
if (!questions[i].LoadFromFile(image))
return -1;
image = base + "Answers/Slide" + middle + end;
if (!answers[i].LoadFromFile(image))
return -1;
};

return 1;
}


It should, unless it errors out of one of your LoadFromFile calls and hits a return -1.  You can step through the loop (keep hitting f10 in the debugger) or place breakpoints at bother of those return -1 lines to see if and where that's happening.
Title: Draw Missing!?
Post by: Avency on August 13, 2008, 09:58:23 pm
If it fails to load an image, the function will return. Check your console output (or whatever you redirected cerr to). Maybe the problem is a broken image file.
Title: Draw Missing!?
Post by: qsik on August 14, 2008, 01:00:47 am
this is strange, the loop goes through 3 times and then on the 4th loop, questions[4] cant seem to load C:/Jeopardy/Questions/Slide5.png (but the image load fine in GIMP and so the loop breaks (does lack of memory also cause images to not load?)

--using GetModuleFileNameExW i get an identifier not found?
Title: Draw Missing!?
Post by: quasius on August 14, 2008, 03:34:24 am
Quote from: "qsik"
this is strange, the loop goes through 3 times and then on the 4th loop, questions[4] cant seem to load C:/Jeopardy/Questions/Slide5.png (but the image load fine in GIMP and so the loop breaks (does lack of memory also cause images to not load?)

--using GetModuleFileNameExW i get an identifier not found?


I've had some issues with random .pngs not loading.  There is some type of .png setting SOIL seems to not like.  Try openeing in GIMP or whatever and resaving as a new file.  (This should clean up whatever weird header irregularities are causing problems.  I've had no trouble loading .pngs exported from GIMP.)

Edit:  Lack of memory could certainly cause a failure depending on how SOIL handles such situations, but I can't image that's the problem.  Do you have any reason to believe you're consuming all your system's memory?
Title: Draw Missing!?
Post by: qsik on August 14, 2008, 06:50:21 am
i switched to bmps cause the pngs werent working...but now the image sizes are much bigger :( (the pngs are exported from powerpoint slides --> a problem?)

--is there a way to get rid of sf::clock? i want to implement a timer so that SFML shows a "loading screen" while loading images in the background, but dont want the sf::clock to continually run and waste resources (im targetting older hardware so i need to save as much space as i can)

**still need help with GetModuleFileNameExW
Title: Draw Missing!?
Post by: quasius on August 14, 2008, 07:00:52 am
Just open the pngs in GIMP and reexport them as pngs.  You don't need to save them as bmps.
I'm not sure what you mean by getting rid of sf::clock and then making your own timer.  sf::clock is very simple and you're not likely to make something faster.
And sf::clock doesn't do anything until you create an instance of the class and even then only when you call functions on it.  It's not really talking up resources at all.
Title: Draw Missing!?
Post by: qsik on August 15, 2008, 10:19:07 pm
im making progress, but a problem has popped up. i was using the debugger and my array for my "money" sprites has all the sprites loaded, their positions set, and the loop has the correct numbers to draw...but only the first row appears? here's my code, i cant seem to find the problem

Code: [Select]
for (int i = 0; i < 5; i++)
{
Money[i].SetImage(money[i]);
Money[(i + 5)].SetImage(money[i]);
Money[(i + 10)].SetImage(money[i]);
Money[(i + 15)].SetImage(money[i]);
Money[(i + 20)].SetImage(money[i]);
Money[(i + 25)].SetImage(money[i]);
};


Code: [Select]
void PositionSprites()
{
float xpos = (ScreenWidth/6);
float ypos = (ScreenHeight/6);
float x = 0;
float y = ypos;

for(int i = 0; i < 6; i++)
{
Categories[i].SetPosition(x, 0.0f);
x = x + xpos;
};

for(int i = 0; i < 5; i++)
{
Money[i].SetPosition(0, y);
Money[(i + 5)].SetPosition(xpos, y);
Money[(i + 10)].SetPosition((xpos * 2), y);
Money[(i + 15)].SetPosition((xpos * 3), y);
Money[(i + 20)].SetPosition((xpos * 4), y);
Money[(i + 25)].SetPosition((xpos * 5), y);
y = y + ypos;
};
}


Code: [Select]
for(int i = 0; i < 30; i++)
{
if(CheckMoney[i] == 1)
App.Draw(Money[i]);
};


(http://img237.imageshack.us/img237/4926/jeopardybn5.th.png) (http://img237.imageshack.us/my.php?image=jeopardybn5.png)
Title: Draw Missing!?
Post by: qsik on August 18, 2008, 05:31:43 am
*bump

a little help?
Title: Draw Missing!?
Post by: dunce on August 18, 2008, 11:57:51 am
Your previous code:
Quote
sf::Sprite Money[5];


and then...
Quote
for(int i = 0; i < 30; i++)
{
   if(CheckMoney == 1)
      App.Draw(Money);
};


How can it work for i > 5 if the array size is 5 and the cycle has up to 30 iterations?
Title: Draw Missing!?
Post by: qsik on August 18, 2008, 07:41:28 pm
sorry, i changed the size of Money[] to 30 to hold the needed 30 images unless there is a way to duplicate sprites w/o having to create more sprite variables
Title: Draw Missing!?
Post by: qsik on August 20, 2008, 04:32:38 pm
*bump

--still cant figure it out
Title: Draw Missing!?
Post by: Wizzard on August 20, 2008, 07:16:35 pm
Post all your code (you probably made changes, right?) and I will try to go through it and fix it later today.
Title: Draw Missing!?
Post by: qsik on August 20, 2008, 07:32:56 pm
!!! WARNING !!! i dont use comments, but instead try to make my code make as much sense as possible through the use of good variable names and sensible function names though some of it may not make sense 'cause im not completely done

String Conversion.h

Code: [Select]
#include <iostream>
#include <sstream>
#include <string>

std::string Convert(int number)
{
std::stringstream converter;
converter << number;
return converter.str();
}


Jeopardy.h

Code: [Select]

#include "SFML/Quickstart.h"
#include "SFML/String Conversion.h"

int ScreenWidth;
int ScreenHeight;

int CheckCategories[6];
int CheckMoney[30];

std::string Path;

sf::Sprite Other[6];
sf::Sprite Categories[6];
sf::Sprite Money[30];
sf::Sprite Question;
sf::Sprite Answer;

sf::Image other[6];
sf::Image categories[6];
sf::Image money[5];
sf::Image question;
sf::Image answer;

sf::Music Music[4];

void GetDesktopMode()
{
sf::VideoMode DesktopMode = sf::VideoMode::GetDesktopMode();
ScreenWidth = DesktopMode.Width;
ScreenHeight = DesktopMode.Height;
}

std::string GetExeD()
{
GetModuleFileName(NULL, L"Path", 100);
return Path;
}

int LoadImages()
{
std::string base = "C:/Jeopardy/";
std::string end = ".bmp";
std::string middle;
std::string image;

for(int i = 0; i < 6; i++)
{
middle = Convert((i + 1));
image = base + "Other/Slide" + middle + end;
if (!other[i].LoadFromFile(image))
return -1;
image = base + "Categories/Slide" + middle + end;
if (!categories[i].LoadFromFile(image))
return -1;
};

for(int i = 0; i < 5; i++)
{
middle = Convert((i + 1));
image = base + "Money/Slide" + middle + end;
if (!money[i].LoadFromFile(image))
return -1;
};

return 1;
}

void LoadSprites()
{
for (int i = 0; i < 6; i++)
{
Other[i].SetImage(other[i]);
Categories[i].SetImage(categories[i]);
};

for (int i = 0; i < 5; i++)
{
Money[i].SetImage(money[i]);
Money[(i + 5)].SetImage(money[i]);
Money[(i + 10)].SetImage(money[i]);
Money[(i + 15)].SetImage(money[i]);
Money[(i + 20)].SetImage(money[i]);
Money[(i + 25)].SetImage(money[i]);
};
}

void ScaleSprites()
{
float ImageWidth;
float ImageHeight;

for (int i = 0; i < 6; i++)
{
ImageWidth = other[i].GetWidth();
ImageHeight = other[i].GetHeight();
ImageWidth = (ScreenWidth / ImageWidth);
ImageHeight = (ScreenHeight / ImageHeight);
Other[i].Scale(ImageWidth, ImageHeight);

ImageWidth = categories[i].GetWidth();
ImageHeight = categories[i].GetHeight();
ImageWidth = ((ScreenWidth/6) / ImageWidth);
ImageHeight = ((ScreenHeight/6) / ImageHeight);
Categories[i].Scale(ImageWidth, ImageHeight);
};

for (int i = 0; i < 30; i++)
{
ImageWidth = money[i].GetWidth();
ImageHeight = money[i].GetHeight();
ImageWidth = ((ScreenWidth/6) / ImageWidth);
ImageHeight = ((ScreenHeight/6) / ImageHeight);
Money[i].Scale(ImageWidth, ImageHeight);
};
}

void PositionSprites()
{
float xpos = (ScreenWidth/6);
float ypos = (ScreenHeight/6);
float x = 0;
float y = ypos;

for(int i = 0; i < 6; i++)
{
Categories[i].SetPosition(x, 0.0f);
x = x + xpos;
};

for(int i = 0; i < 5; i++)
{
Money[i].SetPosition(0, y);
Money[(i + 5)].SetPosition(xpos, y);
Money[(i + 10)].SetPosition((xpos * 2), y);
Money[(i + 15)].SetPosition((xpos * 3), y);
Money[(i + 20)].SetPosition((xpos * 4), y);
Money[(i + 25)].SetPosition((xpos * 5), y);
y = y + ypos;
};
}

int LoadMusic()
{
if (!Music[0].OpenFromFile("C:/Jeopardy/Music/Opening.wav"))
return -1;

if (!Music[1].OpenFromFile("C:/Jeopardy/Music/Question.wav"))
return -1;

if (!Music[2].OpenFromFile("C:/Jeopardy/Music/Daily Double.wav"))
return -1;

if (!Music[3].OpenFromFile("C:/Jeopardy/Music/Final Jeopardy.wav"))
return -1;

return 1;
}

void InitChecks()
{
for(int i = 0; i < 6; i++)
CheckCategories[i] = 1;
for(int i = 0; i < 30; i++)
CheckMoney[i] = 1;
}

int Load()
{
GetExeD();
GetDesktopMode();
LoadImages();
LoadSprites();
ScaleSprites();
PositionSprites();
LoadMusic();
InitChecks();
Music[0].Play();

return 1;
}


Main.cpp

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

int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Jeopardy!");
Load();
int stage = 1;

while(App.IsOpened())
    {
sf::Event Event;

while (App.GetEvent(Event))
        {
            if (Event.Type == sf::Event::Closed)
                App.Close();
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();
if ((Event.Type == sf::Event::MouseButtonPressed) && (Event.MouseButton.Button == sf::Mouse::Left) && (stage < 3))
stage = stage + 1;
};

App.Clear(sf::Color(17, 86, 178));
if (stage == 1)
App.Draw(Other[0]);
if (stage == 2)
App.Draw(Other[1]);
if (stage == 3)
{
for(int i = 0; i < 6; i++)
{
if(CheckCategories[i] == 1)
App.Draw(Categories[i]);
};

for(int i = 0; i < 30; i++)
{
if(CheckMoney[i] == 1)
App.Draw(Money[i]);
};
};

App.Display();
    };

return EXIT_SUCCESS;
}
Title: Draw Missing!?
Post by: Avency on August 20, 2008, 08:40:08 pm
That part sure looks weird:
Code: [Select]
  for (int i = 0; i < 5; i++)
   {
      Money[i].SetImage(money[i]);
      Money[(i + 5)].SetImage(money[i]);
      Money[(i + 10)].SetImage(money[i]);
      Money[(i + 15)].SetImage(money[i]);
      Money[(i + 20)].SetImage(money[i]);
      Money[(i + 25)].SetImage(money[i]);
   };


You have 30 sprites but set only 5 images.
Title: Draw Missing!?
Post by: Wizzard on August 21, 2008, 01:46:04 am
Perhaps you meant to do this...

Code: [Select]
sf::Sprite Money[31];


Code: [Select]
for (unsigned int x = 0; x < 5; ++x)
{
    for (unsigned int y = 0; y < 5; ++y)
    {
        Money[x + y].SetImage(money[x]);
    }
}


I couldn't compile your code to test this though.
Title: Draw Missing!?
Post by: NeWsOfTzzz on August 21, 2008, 02:34:57 am
@Wizzard: wrong, 2 errors :/

Correct version:
Code: [Select]
for (unsigned int x = 0; x < 5; ++x)
{
    for (unsigned int y = 0; y < 6; ++y)
    {
        Money[x + y * 5].SetImage(money[x]);
    }
}


And why?
Code: [Select]
sf::Sprite Money[31];
30 was enough!






@qsik, your problem is simple, you scale the sprites to zero
Code: [Select]
for (int i = 0; i < 30; i++)
   {
      ImageWidth = money[i].GetWidth();
      ImageHeight = money[i].GetHeight();
      ImageWidth = ((ScreenWidth/6) / ImageWidth);
      ImageHeight = ((ScreenHeight/6) / ImageHeight);
      Money[i].Scale(ImageWidth, ImageHeight);
   };


change to
Code: [Select]
  for (int i = 0; i < 30; i++)
   {
      ImageWidth = money[0].GetWidth();
      ImageHeight = money[0].GetHeight();
      ImageWidth = ((ScreenWidth/6) / ImageWidth);
      ImageHeight = ((ScreenHeight/6) / ImageHeight);
      Money[i].Scale(ImageWidth, ImageHeight);
   };


Your loop tries to access image[0] to image[29] but you only have image[0] to image[4].. Got it? ;)
.
.
.
.
.
.
.
.
.
.
.
Title: Draw Missing!?
Post by: qsik on August 21, 2008, 04:59:42 am
thnx man, it fixed the errors!

this is correct

Code: [Select]
for (int i = 0; i < 5; i++)
   {
      Money[i].SetImage(money[i]);
      Money[(i + 5)].SetImage(money[i]);
      Money[(i + 10)].SetImage(money[i]);
      Money[(i + 15)].SetImage(money[i]);
      Money[(i + 20)].SetImage(money[i]);
      Money[(i + 25)].SetImage(money[i]);
   };


making 30 images is too slow and costly, so creating 5 sprites of each money image is more efficient and loads quicker

as my small image in a previous post shows, the text in the images are kind of grainy. im scaling 960 x 720 images into (1024/6) x (768/6) images to fit all 36 images on the screen...why do they look kind of bad?
Title: Draw Missing!?
Post by: quasius on August 21, 2008, 07:10:52 am
You should be using comments anyway.  Any reasonably competent software engineer could look at the code and figure out what it does, but that's not the point.  Commenting paragraphs of code with a simple descriptor makes it much easier to read and maintain the code.
Good variable names and whitespace are important, but they're no substitute for coding.  Also, not commenting your code is a good way to get rapidly fired from a job since many employers don't want hard-to-maintain code in their system.  Better get used to it now.
Title: Draw Missing!?
Post by: qsik on August 21, 2008, 11:57:15 pm
how descrptive should the comments be? could u give an example
Title: Draw Missing!?
Post by: quasius on August 22, 2008, 12:39:11 am
Quote from: "qsik"
how descrptive should the comments be? could u give an example


Don't comment every line to the point of obviousness.  i.e. don't do this:

y = x + z;//add x and z and store result in y

Do separate your code into "paragraphs"  that performs a single task (potentially many of these in a function) i.e.

//loads needed images from HD
for (unsigned int i = 0; i < vImageFileNames.size(); ++i)
{
    if (!LoadImageFromFile(vImageFileNames))
        return false;
}


This is useful to provide "tabs" for code that is easy to understand how it works if you read it, but it makes finding the code you want much easier.

If you have code that is not necessarily easy to understand commenting every line or better may be necessary (as well as good variable names).
For example, if I was writing say a collision detection routine with some complicated maths, I'd probably comment every line to explain the process.  Sometimes I've even done ASCII art in my comments to visually explain some computational geometry.

Also, if there ever a specific reason you did something that would not be readily apparent, comment it.  For example if you call two functions and the second is dependent on the first (but not in an obvious way).  examples:

//the behavior of bar() depends on foo(), so call it first
foo();
bar();


//we skip the first to elements because...
for (unsigned int i = 2; i < m_vMyVector.size(); ++i)
{
    //some code...
}


In general "paragraph tabs" (my personal word for them) should always be used and make finding the relevant code easier and line-by-line comments are for code that's hard to follow.
Title: Draw Missing!?
Post by: qsik on August 23, 2008, 07:13:10 am
how's this for a first comment attempt?

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

int CheckCategories[6];
int CheckMoney[30];

std::string Path;

sf::Sprite Other[6];
sf::Sprite Categories[6];
sf::Sprite Money[30];
sf::Sprite Question;
sf::Sprite Answer;

sf::Image other[6];
sf::Image categories[6];
sf::Image money[5];
sf::Image question;
sf::Image answer;

sf::Music Music[4];

//Function returning the current screen resolution's width
int GetDesktopWidth()
{
sf::VideoMode DesktopMode = sf::VideoMode::GetDesktopMode();
return DesktopMode.Width;
}

//Function returning the current screen resolution's height
int GetDesktopHeight()
{
sf::VideoMode DesktopMode = sf::VideoMode::GetDesktopMode();
return DesktopMode.Height;
}

std::string GetExeD()
{
GetModuleFileName(NULL, L"Path", 100);
return Path;
}

//Load images from subfolders of /Jeopardy
int LoadImages()
{
std::string base = "C:/Jeopardy/";
std::string end = ".bmp";
std::string middle;
std::string image;

for(int i = 0; i < 6; i++)
{
middle = Convert((i + 1));
image = base + "Other/Slide" + middle + end;
if (!other[i].LoadFromFile(image))
return -1;
image = base + "Categories/Slide" + middle + end;
if (!categories[i].LoadFromFile(image))
return -1;
};

for(int i = 0; i < 5; i++)
{
middle = Convert((i + 1));
image = base + "Money/Slide" + middle + end;
if (!money[i].LoadFromFile(image))
return -1;
};

return 1;
}

//Assign all loaded images to sprites
void LoadSprites()
{
for (int i = 0; i < 6; i++)
{
Other[i].SetImage(other[i]);
Categories[i].SetImage(categories[i]);
};

for (int i = 0; i < 5; i++)
{
Money[i].SetImage(money[i]);
Money[(i + 5)].SetImage(money[i]);
Money[(i + 10)].SetImage(money[i]);
Money[(i + 15)].SetImage(money[i]);
Money[(i + 20)].SetImage(money[i]);
Money[(i + 25)].SetImage(money[i]);
};
}

//Scale sprites to have each fit 1/6 of the screen resolution
void ScaleSprites()
{
int ScreenWidth = GetDesktopWidth();
int ScreenHeight = GetDesktopHeight();
float ImageWidth;
float ImageHeight;

for (int i = 0; i < 6; i++)
{
ImageWidth = other[i].GetWidth();
ImageHeight = other[i].GetHeight();
ImageWidth = (ScreenWidth / ImageWidth);
ImageHeight = (ScreenHeight / ImageHeight);
Other[i].Scale(ImageWidth, ImageHeight);

ImageWidth = categories[i].GetWidth();
ImageHeight = categories[i].GetHeight();
ImageWidth = ((ScreenWidth/6) / ImageWidth);
ImageHeight = ((ScreenHeight/6) / ImageHeight);
Categories[i].Scale(ImageWidth, ImageHeight);
};

for (int i = 0; i < 30; i++)
{
ImageWidth = money[0].GetWidth();
ImageHeight = money[0].GetHeight();
ImageWidth = ((ScreenWidth/6) / ImageWidth);
ImageHeight = ((ScreenHeight/6) / ImageHeight);
Money[i].Scale(ImageWidth, ImageHeight);
};
}

//Position sprites evenly across the screen in a 6 x 6 grid
void PositionSprites()
{
int ScreenWidth = GetDesktopWidth();
int ScreenHeight = GetDesktopHeight();
float xpos = (ScreenWidth/6);
float ypos = (ScreenHeight/6);
float x = 0;
float y = ypos;

for(int i = 0; i < 6; i++)
{
Categories[i].SetPosition(x, 0.0f);
x = x + xpos;
};

for(int i = 0; i < 5; i++)
{
Money[i].SetPosition(0, y);
Money[(i + 5)].SetPosition(xpos, y);
Money[(i + 10)].SetPosition((xpos * 2), y);
Money[(i + 15)].SetPosition((xpos * 3), y);
Money[(i + 20)].SetPosition((xpos * 4), y);
Money[(i + 25)].SetPosition((xpos * 5), y);
y = y + ypos;
};
}

//Load music
int LoadMusic()
{
if (!Music[0].OpenFromFile("C:/Jeopardy/Music/Opening.wav"))
return -1;

if (!Music[1].OpenFromFile("C:/Jeopardy/Music/Question.wav"))
return -1;

if (!Music[2].OpenFromFile("C:/Jeopardy/Music/Daily Double.wav"))
return -1;

if (!Music[3].OpenFromFile("C:/Jeopardy/Music/Final Jeopardy.wav"))
return -1;

return 1;
}

//Check to see if sprite has been clicked or not
void InitChecks()
{
for(int i = 0; i < 6; i++)
CheckCategories[i] = 1;
for(int i = 0; i < 30; i++)
CheckMoney[i] = 1;
}

//Execute all the functions above and play the Opening Music
int Load()
{
GetExeD();
LoadImages();
LoadSprites();
ScaleSprites();
PositionSprites();
LoadMusic();
InitChecks();
Music[0].Play();

return 1;
}
Title: Draw Missing!?
Post by: quasius on August 25, 2008, 04:56:26 pm
Quote from: "qsik"
how's this for a first comment attempt?


The function header comments are a good idea.   You might consider more intra-function comments.  Over each for-loop, for example (unless it's simple and obvious).
Any time you hard code a value, it's probably a good idea to explain.  What's the meaning of (i + 5), (i + 10), etc. in your LoadSprites function.  Everyone's commenting is different, but here's a sample from my code:

Code: [Select]

//draws a grid for the terrain tiles in the specified color.
void Renderer_Editor::DrawTerrainGrid(sf::Color gridColor)
{
//needed whether we are initing lines or not
int nTileSizeY = TerrainManager::Instance()->GetTileSizeY();
int nTileSizeX = TerrainManager::Instance()->GetTileSizeX();

//Init lines on first draw request.  (We can't do in init since it depends on TerrainManager, which is inited later.)
if (m_bInitGridLines)
{
sf::Vector2i v2iWinSize = this->GetOriginalWindowSize();

//some other data we need
int nHalfWinSizeX = v2iWinSize.x / 2;
int nHalfTileSizeY = TerrainManager::Instance()->GetHalfTileSizeY();

//we need to draw another half-screen further since the later lines are partially off-screen
//TODO: readjust this when resizing window
m_nMaxYOffset = v2iWinSize.y + nHalfWinSizeX + 1 + TerrainManager::Instance()->GetTileSizeY();

//init the grid-line members
//the southwest to northeast grid lines
m_SWtoNEgridLine = sf::Shape::Line(0.0f, (float)nHalfTileSizeY, (float)(v2iWinSize.x + (nTileSizeX * 2)), (float)(nHalfTileSizeY - nHalfWinSizeX - (nTileSizeY * 2)), 1, gridColor);
//the northwest to southeast grid lines
m_NWtoSEgridLine = sf::Shape::Line(0.0f, (float)(nHalfTileSizeY - nHalfWinSizeX), (float)(v2iWinSize.x + (nTileSizeX * 2)), (float)(nHalfTileSizeY + (nTileSizeY * 2)), 1, gridColor);

m_bInitGridLines = false;
}

//actually draw the grid lines
//each frame we offset by the scroll offset up to 1 tile, when we go back to 0 (So the same grid stays alligned and on-screen)
sf::Vector2f v2fTileOffset(fmod(m_v2fScrollOffset.x, (float)nTileSizeX), fmod(m_v2fScrollOffset.y, (float)nTileSizeY));
int nYOffset = -nTileSizeY;

//draw a gridline on both diagonals at every tile boundry across the screen height
while (nYOffset < m_nMaxYOffset)
{
m_SWtoNEgridLine.SetPosition(m_v2fScrollOffset.x - v2fTileOffset.x - nTileSizeX, (float)nYOffset + m_v2fScrollOffset.y - v2fTileOffset.y);
m_NWtoSEgridLine.SetPosition(m_v2fScrollOffset.x - v2fTileOffset.x - nTileSizeX, (float)nYOffset + m_v2fScrollOffset.y - v2fTileOffset.y);
m_pRenderWindow->Draw(m_SWtoNEgridLine);
m_pRenderWindow->Draw(m_NWtoSEgridLine);

nYOffset += nTileSizeY;
}
}
Title: Draw Missing!?
Post by: qsik on August 29, 2008, 06:00:09 am
i still cant figure out how to be able to use std::strings in GetModuleFileName() or convert TCHARS to std::strings

also, can someone explain the poor quality of the text in the images of my program (they are really pixelated on my 1024 x 768 screen)

**why does everything on the site seem so much smaller?
Title: Draw Missing!?
Post by: qsik on September 01, 2008, 04:28:54 am
a little help?
Title: Draw Missing!?
Post by: zarka on September 01, 2008, 10:56:25 am
Quote from: "qsik"
i still cant figure out how to be able to use std::strings in GetModuleFileName() or convert TCHARS to std::strings


These are WIN32 API function i guess? .. you should look them up on MSDN or something :) and i believe there might be another win32 function which can convert TCHAR to a char*
Title: Draw Missing!?
Post by: Wizzard on September 01, 2008, 07:35:08 pm
Have you tried using a std::wstring?
Title: Draw Missing!?
Post by: qsik on September 04, 2008, 01:18:29 am
can i use a wstring in sf::LoadImageFromFile()?
Title: Draw Missing!?
Post by: Wizzard on September 04, 2008, 06:49:24 pm
There is many ways I can think of on how to do that...


Have you even tried it?
Code: [Select]
sf::Image    Image;                // The image to load
std::wstring Filename(L"foo.png"); // The filename of the image

// Load the image using a std::wstring of the filename
Image.LoadFromFile(Filename);


You might be able to simply use std::wstring::c_str():
Code: [Select]
sf::Image    Image;                // The image to load
std::wstring Filename(L"foo.png"); // The filename of the image

// Load the image using a c-style string of the filename
Image.LoadFromFile(Filename.c_str());


If that still doesn't work, it will work by doing this:
Code: [Select]
sf::Image    Image;                 // The image to load
std::wstring WFilename(L"foo.png"); // The filename of the image

// Convert WFilename from std::wstring to a std::string called Filename
std::string Filename;
Filename.assign(WFilename.begin(), WFilename.end());

// Load the image using a std::string of the filename
Image.LoadFromFile(Filename);
Title: Draw Missing!?
Post by: Laurent on September 04, 2008, 10:52:26 pm
SFML takes simple strings (std::string, const char*), not wide ones (std::wstring, const wchar_t). So your 2 first solutions won't work. And the third one doesn't make much sense, in the contexts where this simple conversion works you can directly use simple strings.
Title: Draw Missing!?
Post by: Wizzard on September 05, 2008, 07:39:44 pm
The problem is that he is getting TCHARs from the Windows API that are wchar_t*.
So, he must convert the wchar_t*s to char*s somehow in order to use them with sf::Image::LoadFromFile.
Perhaps he should just turn Unicode support off, but I think he may need it for some reason.
Title: Draw Missing!?
Post by: Laurent on September 05, 2008, 07:47:48 pm
Unicode is enabled by default on some versions of VC++, so in general people can just turn it off.

However, SFML provides functions to properly convert from wide strings to simple strings. Try that :
Code: [Select]
const wchar_t* w = L"some text";
std::string s = sf::Unicode::Text(w);

In fact, Text is a classe which can be constructed from and converted to any type / encoding of strings (including UTF standards). It's mainly used internally, but it can be used to easily perform this kind of conversions as well.
Title: Draw Missing!?
Post by: qsik on September 07, 2008, 12:10:36 am
i know unicode allows for international characters but does turning it off do anything that would majorly affect my program?

otherwise...i could have fixed this a long time ago