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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Dark Byte

Pages: 1 [2]
16
Graphics / need help with image manager.
« on: October 15, 2010, 03:24:30 am »
Alright. Thanks.
This is what I have for RetrieveImage
Code: [Select]

sf::Image ImageManager::RetrieveImage(const string path)
{
if ( this->Data.find(path) != this->Data.end() )
{
return this->Data[path];
}
else
{
try
{
throw "failed to load image "+path;
}
catch (string E)
{
cout << "An exception occured: " << E;
}
}
}


When an image is returned it has the correct width and height, but it is fully white. I am passing a pointer of the a global image manager to a function to draw the graphics. COuld that be what is wrong?

17
Graphics / need help with image manager.
« on: October 14, 2010, 11:15:54 pm »
I need help creating an image manager. I have one, but calling something like
Code: [Select]

sprite.SetImage(Manager.RetrieveImage("gfx/player.tga"))


Will cause the program to crash.

Here is the source:
ImageManager.h
Code: [Select]

#include <map>

class ImageManager
{
 private:
map<string, sf::Image> Data;

 public:
sf::Image RetrieveImage(const string path);
bool LoadImage(string path);
int ImageCount();

} ;



ImageManager.cpp
Code: [Select]

#include "ImageManager.h"

sf::Image ImageManager::RetrieveImage(const string path)
{
if ( this->Data.find(path) != this->Data.end() )
{
return this->Data[path];
}
}

bool ImageManager::LoadImage(string path)
{
if ( this->Data.find(path) !=  this->Data.end() )
return true;
else
{
sf::Image IMGTemp;
if ( IMGTemp.LoadFromFile(path) )
{
this->Data[path] = IMGTemp;
return true;
}
else
return false;
}
}

int ImageManager::ImageCount()
{
return this->Data.size();
}


18
Graphics / SFML PNG Images
« on: October 09, 2010, 10:54:26 pm »
Thanks

19
Graphics / Program crashes when LMB is pressed
« on: October 09, 2010, 08:38:30 pm »
It has been fixed

20
Graphics / SFML PNG Images
« on: October 09, 2010, 08:37:36 pm »
Does it read RGBA from PNG files or just RGB?

21
Graphics / Program crashes when LMB is pressed
« on: October 07, 2010, 12:30:16 am »
This program compiles correctly, but when the left mouse button is pressed it gives this error:
pure virtual method called
terminate called without active exception

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

It only happens when a new instance of the class CBullet is created. It (in this program) is only created when you press the LMB.

When a new CBullet is created it adds a pointer to that class to the vector CBullets. And when it is destroyed it is removed from the vector.

I am compiling with MinGW. My command line is:
g++ main.cpp -obin/output.exe -lsfml-system -lsfml-window -lsfml-graphics -lsfml-audio -static-libgcc -static-libstdc++

Edit:
It happens when the sprite is drawn at line 188

Code: [Select]

#include <cmath>
#include <vector>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>

#define PI 3.14159265358979

using namespace std;

template <class T>
T FindDistance(T x1, T x2, T y1, T y2)
{
return sqrt( (x2 - x1)*(x2-x1) + (y2 - y1)*(y2-y1) );
}

class CBullet;
vector<CBullet*> CBullets;

sf::Image IMGBullet;

class CBullet
{
private:
float MAX_DIST, rot, sx, sy;
bool force_destroy;

public:
sf::Sprite Sprite;

CBullet(float x, float y, float rot_)
{
this->MAX_DIST = 350.f;
this->force_destroy = false;
this->Sprite.SetImage(::IMGBullet);
this->Sprite.SetX(x);
this->sx = x;
this->Sprite.SetY(y);
this->sy = y;
this->rot = rot_;
CBullets.push_back(this);
}

~CBullet()
{
for ( int i; i < CBullets.size(); i++ )
{
if ( CBullets[i] == this )
{
CBullets.erase(CBullets.begin() + i);
break;
}
}
}

void Update (void)
{
if ( !this->force_destroy )
{
float X = this->Sprite.GetPosition().x;
float Y = this->Sprite.GetPosition().y;
if ( FindDistance<float> (X, sx, Y, sy) >= MAX_DIST )
{
this->force_destroy = true;
}

this->Sprite.SetX( X + sin(rot) );
this->Sprite.SetY( Y - cos(rot) );
}
else
delete this;
}

} ;


int main()
{
sf::Image IMGPlayer;
sf::Image IMGCursor;
sf::Image IMGBack;

sf::SoundBuffer SNBShoot;

sf::RenderWindow App(sf::VideoMode(800,600,32), "rotation test");

App.ShowMouseCursor(false);

sf::Clock CLKShoot;

if ( !IMGPlayer.LoadFromFile("gfx/player.bmp") )
App.Close();
IMGPlayer.CreateMaskFromColor(sf::Color(255,0,255));

if ( !IMGCursor.LoadFromFile("gfx/pointer.bmp") )
App.Close();

if ( !IMGBack.LoadFromFile("gfx/desktop.png") )
App.Close();

if ( !SNBShoot.LoadFromFile("sfx/elite.wav") )
App.Close();

if ( !IMGBullet.LoadFromFile("gfx/bullet.bmp") )
App.Close();

sf::Sound SNDShoot;
SNDShoot.SetBuffer(SNBShoot);

IMGCursor.CreateMaskFromColor(sf::Color(255,0,255));

sf::Sprite SPRPlayer;
sf::Sprite SPRCursor;
sf::Sprite SPRBack;

SPRPlayer.SetImage(IMGPlayer);
SPRCursor.SetImage(IMGCursor);
SPRBack.SetImage(IMGBack);

SPRPlayer.SetSubRect(sf::IntRect(1,1,32,32));
SPRCursor.SetSubRect(sf::IntRect(0,0,25,25));

SPRPlayer.SetX(400);
SPRPlayer.SetY(300);

SPRPlayer.SetCenter(16.f, 16.f);
SPRCursor.SetCenter(11.f, 11.f);

sf::Vector2f Center(400, 300);
    sf::Vector2f HalfSize(400, 300);
sf::View MainView(Center, HalfSize);
CLKShoot.Reset();
while ( App.IsOpened() )
{
sf::Event Event;
while ( App.GetEvent(Event) )
{
if ( Event.Type == sf::Event::Closed )
App.Close();
}

float Offset = 150.f*App.GetFrameTime();
if ( App.GetInput().IsKeyDown(sf::Key::LShift) )
Offset *= 0.35f;
if ( App.GetInput().IsKeyDown(sf::Key::W) )
{
MainView.Move(0, -Offset);
SPRPlayer.Move(0, -Offset);
}
if ( App.GetInput().IsKeyDown(sf::Key::A) )
{
MainView.Move(-Offset, 0);
SPRPlayer.Move(-Offset, 0);
}
if ( App.GetInput().IsKeyDown(sf::Key::S) )
{
MainView.Move(0, Offset);
SPRPlayer.Move(0, Offset);
}
if ( App.GetInput().IsKeyDown(sf::Key::D) )
{
MainView.Move(Offset, 0);
SPRPlayer.Move(Offset, 0);
}
if ( App.GetInput().IsMouseButtonDown(sf::Mouse::Left) && CLKShoot.GetElapsedTime() >= SNBShoot.GetDuration() )
{
SNDShoot.Play();
CBullet bullet(SPRPlayer.GetPosition().x, SPRPlayer.GetPosition().y, SPRPlayer.GetRotation());
CLKShoot.Reset();
}

App.SetView(MainView);
App.Clear();

sf::Vector2f MousePos = App.ConvertCoords(App.GetInput().GetMouseX(), App.GetInput().GetMouseY());

SPRCursor.SetX(MousePos.x);
SPRCursor.SetY(MousePos.y);

SPRPlayer.SetRotation( -(atan2(App.GetInput().GetMouseY()-300, App.GetInput().GetMouseX()-400) * 180 / PI + 90) );

App.Draw(SPRBack);
App.Draw(SPRPlayer);

for ( int i = 0 ; i < CBullets.size(); i++ )
{
CBullets[i]->Update();
App.Draw(CBullets[i]->Sprite);
}

App.Draw(SPRCursor);

//App.SetView(App.GetDefaultView());

App.Display();
}

return 0;
}


22
Graphics / How can I get a sprite's X/Y cords?
« on: October 03, 2010, 08:58:57 pm »
How can I get a sprite's X/Y cords?

23
Graphics / How can I 'mask' an image
« on: September 29, 2010, 03:40:41 am »
Thank you exactly what I needed.

24
Graphics / How can I 'mask' an image
« on: September 29, 2010, 02:46:51 am »
Is it possible to mask an image (if a pixel in the image is a specific color it is invisible)?

25
Graphics / Is it possible to hide the mouse cursor?
« on: September 29, 2010, 01:45:25 am »
thanks

26
Graphics / Is it possible to hide the mouse cursor?
« on: September 29, 2010, 12:28:36 am »
Title says all.

27
Window / SFML Debug/Release with VC+ 2010 errors
« on: September 28, 2010, 11:19:22 pm »
Alright. I have just installed VC++ 2008 (it works w00t). But I will do that as I like 2010 more. And thanks for your help ;)

28
Window / SFML Debug/Release with VC+ 2010 errors
« on: September 28, 2010, 03:31:28 am »
Oh no I have not. Also will it work with the express editions of MSVC? And how could I compile it myself?

29
Window / SFML Debug/Release with VC+ 2010 errors
« on: September 27, 2010, 12:43:10 am »
I am using VC++ 2010 on Win7 64-bit and SFML 1.6

When I use debug mode with the proper libraries (-d suffix) it always crashes and gives me this error:
"The application was unable to start correctly (0xc0150002). Click OK to close the application."
It will not run with the debug libraries.

But when I use the non-debug libraries it runs, but when it closes it gives this error:
"Run-Time Check Failure #2 - Stack around the variable 'App' was corrupted."

In Release mode it is even worse it gives this 20 times
"A buffer overrun has occurred in TEST_.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'."

Here is the source:
Code: [Select]

#include <SFML/Window.hpp>
#include <iostream>

#pragma comment(lib, "sfml-system.lib")
#pragma comment(lib, "sfml-window.lib")

int main()
{
sf::Clock Clock;
sf::Window App(sf::VideoMode(800,600,32), "test");
while ( Clock.GetElapsedTime() < 10.0001f )
{
std::cout<<Clock.GetElapsedTime()<<"\n";
App.Display();
}
return 0;
}

30
Window / **** Buffer overrun? ****
« on: September 25, 2010, 09:51:24 pm »
I am new to SFML and I am having trouble with the Window package. I am using VC++ 2010 with SFML 1.6. I can not make the program run in Release mode because it returns this error
A buffer overrun has occurred in SFMLTest02.exe which has corrupted the program's internal state. Press Break to debug the program or Continue to terminate the program.

It will not run in debug either I get this error
1>------ Build started: Project: SFMLTest02, Configuration: Debug Win32 ------
1>  
1>mt.exe : general error c101008a: Failed to save the updated manifest to the file "Debug\SFMLTest02.exe.embed.manifest". The parameter is incorrect.
1>  
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

SFML is installled to C:\SFML-1.6

And my VC++ properties are
Include Dirs = C:\SFML-1.6\include;$(IncludePath)
Library dirs = C:\SFML-1.6\lib;$(LibraryPath)

Preprocesser =SFML_DYNAMIC;WIN32;_DEBUG;_CONSOLE

Extern Dependencies = sfml-window-d.lib;$(AdditionalDependecies)

The source
Code: [Select]

#include <SFML/Window.hpp>
#include <iostream>

int main()
{
sf::Window App(sf::VideoMode(800,600,32), "Test App");
while ( App.IsOpened() )
{
sf::Event Event;
while ( App.GetEvent(Event) )
{
if ( Event.Type == sf::Event::Closed )
{
App.Close();
}
}

App.Display();
}
return 0;
}
[/code]

Edit:
Also when I use the debug libraries (-d) I get this error when the app starts
http://img215.imageshack.us/img215/2116/capturezk.png

Pages: 1 [2]
anything