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.


Topics - Dark Byte

Pages: [1]
1
General discussions / Need help with scaling Box2D coords
« on: July 02, 2011, 03:51:40 pm »
Hi, I cannot convert the Box2D coords to pixels. Everything I have tried does the same just on a different scale. Does anyone know how to convert them?

2
General / Need help programming GUI
« on: January 02, 2011, 06:53:36 am »
I am writing a GUI and I need help with scroll bars. I have this it works but sometimes if the member contentSize is a certain value it fails (it just freezes the program). I have tried to find the problem but have failed.
Here is the code

Declaration
Code: [Select]

class VScrollBar : public Object
{
int mousepos[2];
bool mousedown;
public:
int pos;
float windowSize;
float contentSize;
float minGripSize;

VScrollBar();
float CalculateGripRatio();
float CalculateGripSize();
float CalculateScrollSize();
float CalculateScrollRatio();
float CalculateGripPosition();
void ValidatePos();
void Draw(sf::RenderWindow*);
protected:
void MouseScroll(int delta)
{
pos -= delta;
}
void MouseHover(float fx, float fy)
{
mousepos[1] = mousepos[0];
mousepos[0] = fy;
if ( mousedown )
{
float gripSize = CalculateGripSize();
float gripPos = CalculateScrollSize() * CalculateScrollRatio();
if ( fy >= gripPos && fy <= gripPos + gripSize )
pos += mousepos[0]-mousepos[1];
}
}

void MousePressed(int i)
{
if ( i == MOUSE_BUTTON_R )
{
/* float mouseRatio = *mousepos/wY;
pos = mouseRatio*contentSize;*/
mousedown = true;
}
}

void MouseReleased(int i)
{
if ( i == MOUSE_BUTTON_R )
mousedown = false;
}

} ;


Definition
Code: [Select]

GUI::VScrollBar::VScrollBar()
{
     wY = 100;
     windowSize = 100;
     contentSize = 200;
     minGripSize = 5;
     pos = 0;
     *(mousepos) = 0;
     *(mousepos + 1) = 0;
     mousedown = false;
}

float GUI::VScrollBar::CalculateGripRatio()
{
     if ( contentSize == 0.f )
          return 0.f;
     return windowSize/contentSize;
}

float GUI::VScrollBar::CalculateGripSize()
{
     float tmp = wY * CalculateGripRatio();
     tmp = tmp < 3?3:tmp;
     return tmp<minGripSize?minGripSize:tmp;
}

float GUI::VScrollBar::CalculateScrollSize()
{
     return wY - CalculateGripSize();
}

float GUI::VScrollBar::CalculateScrollRatio()
{
     return pos/contentSize;
}

void GUI::VScrollBar::ValidatePos()
{
     if ( pos < 0 ) pos = 0;
     float gripPos = CalculateScrollSize() * CalculateScrollRatio();
     while ( gripPos > CalculateScrollSize() )
     {
          pos--;
          gripPos = CalculateScrollSize() * CalculateScrollRatio();
     }
}

void GUI::VScrollBar::Draw(sf::RenderWindow* RENW)
{
     ValidatePos();
     int gripSize = (int) CalculateGripSize();
     gripSize = gripSize < minGripSize?minGripSize:gripSize;
     float gripPos = CalculateScrollSize() * CalculateScrollRatio();
     sf::Shape grip = sf::Shape::Rectangle(pX+2, pY + gripPos, pX+wX-1,pY+gripPos+gripSize,sf::Color(70,70,70),true,sf::Color(200,200,200));
     sf::Shape track = sf::Shape::Rectangle(pX+1, pY, pX+wX,pY+wY,sf::Color(200,200,200),true,sf::Color(70,70,70));
     RENW->Draw(track);
     RENW->Draw(grip);
}

3
General / Separating Axis Theorem
« on: December 05, 2010, 02:36:30 am »
Where can I learn how to implement the Separating Axis Theorem into one of my projects?

4
Graphics / [Win API] Can I use an image resource as sf::Image?
« on: December 04, 2010, 07:27:41 am »
Is that possible?

5
Network / Entry Point not Found
« on: December 02, 2010, 07:40:22 am »
Every compiled program that uses sfml-network gives me this this runtime error: The procedure entry point _ZN2sf9IPAddressC1Ev could not be located in the DLL sfml-network.dll

6
Graphics / is it possible to get fonts size in pixles?
« on: November 06, 2010, 05:27:09 pm »
Is it possible to get the width and height of an sf::String object dependent on the font and size in pixels?

7
General / 50% of CPU used to power a simple program
« on: October 24, 2010, 02:25:53 am »
I wanted to know why so much CPU is required to run this
Code: [Select]

#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>

int main()
{
sf::RenderWindow App(sf::VideoMode(800,600,32), "Test app");
sf::Image Back;
if ( !Back.LoadFromFile("background.png") )
App.Close();

sf::Sprite BackSPR;
BackSPR.SetImage(Back);
while ( App.IsOpened() )
{
App.Clear();
sf::Event Event;
while ( App.GetEvent(Event) )
{
if ( Event.Type == sf::Event::Closed )
App.Close();
}
App.Draw(BackSPR);

App.Display();
}

return 0;
}


The compiled program uses about 50% of my CPU.
Some computer info:
RAM 8gb
HDD 1tb
processor 2.6ghz

I am using MinGW to compile.

8
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();
}


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

10
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;
}


11
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?

12
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)?

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

14
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;
}

15
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]