Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Visual C++ Questions  (Read 9402 times)

0 Members and 1 Guest are viewing this topic.

YellowShadow

  • Newbie
  • *
  • Posts: 29
    • AOL Instant Messenger - ehwatsupdoc21
    • View Profile
Visual C++ Questions
« on: January 14, 2009, 04:51:14 am »
Hey guys, I recently switched from CodeBlocks and MinGW to Visual C++ Express 2008. But I've been running into some problems with the current code I have.

1. Where do I put the SFML_DYNAMIC macro? The image in the tutorial doesn't show so I don't know where to put it.

2. Right now I'm linking against the static libs so I can get some work done, till I fix issue #1 but when I try to load an image, it says can't be found. I've manually checked to see if that image is there but the program can't find it.

Here is my code so you can see how I'm doing my image loading.

Code: [Select]

#include <iostream>

#include <SFML/Graphics.hpp>

int main()
{
    //Create the window of the application
    sf::RenderWindow App(sf::VideoMode(1024, 728, 32), "GunKnights");

    //Set the frame rate
    App.SetFramerateLimit(60);

    //Ground Image
    sf::Image groundImage;

    //Load the ground image
    if (!groundImage.LoadFromFile("gfx\\maps.png"))
{
std::cout << "Error loading maps.png" << std::endl;
return EXIT_FAILURE;
}

    //Create a ground sprite
    sf::Sprite ground(groundImage);

    //Set the position of the ground image
    //ground.SetPosition(0, App.GetHeight() - ground.GetSize().y);

    bool IsPlaying = true;
    while (App.IsOpened())
    {
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            //Window closed or escape key pressed : exit
            if ((Event.Type == sf::Event::Closed) ||
                ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape)))
            {
                App.Close();
                break;
            }
        }

        if (IsPlaying)
        {
        }

        //Clear the Window
        App.Clear(sf::Color(100, 149, 237, 100));

        //Draw the ground image
        App.Draw(ground);

        App.Display();
    }

    return EXIT_SUCCESS;
}


If anyone can help me fix the following problems, I would really appreciate it!

Thanks,
YellowShadow

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Visual C++ Questions
« Reply #1 on: January 14, 2009, 08:00:55 am »
1. Please don't duplicate your questions in multiple topics

2. Your working directory is probably not the one containing the executable. This can happen when you launch your program from the Visual Studio. It can be setup in your project's properties, in "Debugging" --> "Working Directory". Just set it to $(TargetDir).
Laurent Gomila - SFML developer

YellowShadow

  • Newbie
  • *
  • Posts: 29
    • AOL Instant Messenger - ehwatsupdoc21
    • View Profile
Visual C++ Questions
« Reply #2 on: January 15, 2009, 03:59:13 am »
Quote from: "Laurent"
1. Please don't duplicate your questions in multiple topics

2. Your working directory is probably not the one containing the executable. This can happen when you launch your program from the Visual Studio. It can be setup in your project's properties, in "Debugging" --> "Working Directory". Just set it to $(TargetDir).


I did set my working directory to that, yet I get the same error. I tried cleaning and rebuilding the project but still I get the same error when I run the game.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Visual C++ Questions
« Reply #3 on: January 15, 2009, 08:10:51 am »
Does it work when you launch your executable directly (i.e. not from Visual Studio)?
Laurent Gomila - SFML developer

YellowShadow

  • Newbie
  • *
  • Posts: 29
    • AOL Instant Messenger - ehwatsupdoc21
    • View Profile
Visual C++ Questions
« Reply #4 on: January 15, 2009, 04:10:11 pm »
Quote from: "Laurent"
Does it work when you launch your executable directly (i.e. not from Visual Studio)?


No it doesn't.

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
Visual C++ Questions
« Reply #5 on: January 15, 2009, 06:23:40 pm »
If you leave the Working Directory field blank and put your image in the same directory as the .sln-file you should be able to use this path:

"./your_image.png"

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Visual C++ Questions
« Reply #6 on: January 15, 2009, 09:43:36 pm »
Is there any message on the standard output?
Laurent Gomila - SFML developer

YellowShadow

  • Newbie
  • *
  • Posts: 29
    • AOL Instant Messenger - ehwatsupdoc21
    • View Profile
Visual C++ Questions
« Reply #7 on: January 16, 2009, 04:27:03 am »
Quote from: "Laurent"
Is there any message on the standard output?


Code: [Select]

'Client.exe': Loaded 'C:\Documents and Settings\Dro\Desktop\GunKnights\code\trunk\Client\Debug\Client.exe', Symbols loaded.
'Client.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll'
'Client.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll'
'Client.exe': Loaded 'C:\WINDOWS\system32\opengl32.dll'
'Client.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll'
'Client.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll'
'Client.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll'
'Client.exe': Loaded 'C:\WINDOWS\system32\secur32.dll'
'Client.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll'
'Client.exe': Loaded 'C:\WINDOWS\system32\user32.dll'
'Client.exe': Loaded 'C:\WINDOWS\system32\glu32.dll'
'Client.exe': Loaded 'C:\WINDOWS\system32\ddraw.dll'
'Client.exe': Loaded 'C:\WINDOWS\system32\dciman32.dll'
'Client.exe': Loaded 'C:\WINDOWS\system32\winmm.dll'
'Client.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.30729.1_x-ww_f863c71f\msvcp90d.dll'
'Client.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.30729.1_x-ww_f863c71f\msvcr90d.dll'
'Client.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.1_x-ww_6f74963e\msvcr90.dll'
'Client.exe': Loaded 'C:\WINDOWS\system32\imm32.dll'
'Client.exe': Loaded 'C:\WINDOWS\system32\dinput.dll'
'Client.exe': Loaded 'C:\WINDOWS\system32\hid.dll'
'Client.exe': Loaded 'C:\WINDOWS\system32\setupapi.dll'
'Client.exe': Loaded 'C:\WINDOWS\system32\wintrust.dll'
'Client.exe': Loaded 'C:\WINDOWS\system32\crypt32.dll'
'Client.exe': Loaded 'C:\WINDOWS\system32\msasn1.dll'
'Client.exe': Loaded 'C:\WINDOWS\system32\imagehlp.dll'
'Client.exe': Loaded 'C:\WINDOWS\system32\uxtheme.dll'
'Client.exe': Loaded 'C:\WINDOWS\system32\msctf.dll'
'Client.exe': Loaded 'C:\WINDOWS\system32\version.dll'
'Client.exe': Unloaded 'C:\WINDOWS\system32\version.dll'
'Client.exe': Loaded 'C:\WINDOWS\system32\MSCTFIME.IME'
'Client.exe': Loaded 'C:\WINDOWS\system32\ole32.dll'
'Client.exe': Loaded 'C:\WINDOWS\system32\atioglxx.dll'
'Client.exe': Loaded 'C:\WINDOWS\system32\version.dll'
'Client.exe': Loaded 'C:\WINDOWS\system32\ws2_32.dll'
'Client.exe': Loaded 'C:\WINDOWS\system32\ws2help.dll'
'Client.exe': Loaded 'C:\WINDOWS\system32\mcd32.dll'
'Client.exe': Unloaded 'C:\WINDOWS\system32\mcd32.dll'
First-chance exception at 0x00431819 in Client.exe: 0xC0000005: Access violation reading location 0xcccccccc.
A buffer overrun has occurred in Client.exe which has corrupted the program's internal state. Press Break to debug the program or Continue to terminate the program.

For more details please see Help topic 'How to debug Buffer Overrun Issues'.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Visual C++ Questions
« Reply #8 on: January 16, 2009, 07:54:17 am »
Well, this is not the standard output. The standard output is the console ; if you created a Win32 project (and thus don't have a console) you can either activate it in the project's settings, or redirect std::cerr to a file.

The Visual Studio output shows a crash, is it related to your problem or is it happening after the image loading failure?
Laurent Gomila - SFML developer

YellowShadow

  • Newbie
  • *
  • Posts: 29
    • AOL Instant Messenger - ehwatsupdoc21
    • View Profile
Visual C++ Questions
« Reply #9 on: January 16, 2009, 04:12:22 pm »
Quote from: "Laurent"
Well, this is not the standard output. The standard output is the console ; if you created a Win32 project (and thus don't have a console) you can either activate it in the project's settings, or redirect std::cerr to a file.

The Visual Studio output shows a crash, is it related to your problem or is it happening after the image loading failure?


The console says failed to load image and it's says something about fopen.

The crash happens after the image loading.

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Visual C++ Questions
« Reply #10 on: January 17, 2009, 04:47:35 pm »
I think SFML only supports 8-bit .png files

YellowShadow

  • Newbie
  • *
  • Posts: 29
    • AOL Instant Messenger - ehwatsupdoc21
    • View Profile
Visual C++ Questions
« Reply #11 on: January 17, 2009, 06:01:37 pm »
It worked before with CodeBlocks.

YellowShadow

  • Newbie
  • *
  • Posts: 29
    • AOL Instant Messenger - ehwatsupdoc21
    • View Profile
Visual C++ Questions
« Reply #12 on: January 25, 2009, 11:57:03 pm »
Bump. I still need help with this.

Can anyone help?

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
Visual C++ Questions
« Reply #13 on: January 26, 2009, 12:27:57 pm »
Quote from: "YellowShadow"
Bump. I still need help with this.

Can anyone help?


if you tried what I wrote earlier with no success I'm afraid I can't help.

bullno1

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Visual C++ Questions
« Reply #14 on: January 26, 2009, 04:24:13 pm »
Try to add this to your code:
system("echo %cd%");
It'll print out the working directory. You need to put your resources there.

Quote
The console says failed to load image and it's says something about fopen.

Can you post that "something" here?
I still think this is a path problem.