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 - dpixel

Pages: [1]
1
Graphics / Image too large?
« on: September 09, 2013, 04:12:36 pm »
Hi all,

I was getting a "white sprite" problem.  It shows up fine on one computer and as a white box on another. 
And I thought it was the sf::Sprite, sf::Texture scope, after reading around.    I narrowed it down that the image was too big for the vid card.  The width was 2089 and I cut it back to 2048 and everything was fine.

Anyway, I have a lot of graphics in this game and there will be more.  I've read in the tutorials that it's best to have as few textures as possible, but I did not understand why from the reasoning.  Could someone explain in more simple terms.   Thanks.

2
Audio / Audio crashes of exit
« on: August 30, 2013, 07:06:04 am »
I've been reading about some issues with Windows XP and sf::Sound, etc.  I don't really understand what's going on...if it's an issue that I have?  Or if the issue was fixed?

My program crashes on exit with a:

The instruction at "0x100453cc" referenced memory ar "0x030cb490". The memory could not be "read".

All I have to put in is this one line to make it crash on exit...
sf::SoundBuffer buf1;

Other than that, the audio works fine.

3
General / FPS Help
« on: August 29, 2013, 03:43:39 am »
I just started SFML after being an SDL user.   I'm trying to dial in this FPS code.  For some reason the timing is off.

If I set
int FPSQ = 60;
 
I get about 120FPS

To get 60FPS I have to set
int FPSQ = 33;
 

#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <iostream>
#include <string>
#include <sstream>


using namespace sf;
sf::RenderWindow window;

    sf::Texture Tplayer;
    sf::Texture SmallAlpha;
    sf::Texture Back;
    sf::Texture mainchar;

    sf::Sprite Splayer;
    sf::Sprite Splayer1;
    sf::Sprite smallalpha;
    sf::Sprite background;
    sf::Sprite char1;

void Walk_Right(int x, int y, int index);

std::string GetFullScreen(int mode)
{
    int newsizeX = 0;
    int newsizeY = 0;
    switch (mode)
    {
    case 0:
        newsizeX = 1920;
        newsizeY = 1080;
        window.setTitle("1920x1080");
        break;
    case 1:
        newsizeX = 800;
        newsizeY = 450;
        window.setTitle("800x450");
        break;
    case 2:
        newsizeX = 1200;
        newsizeY = 675;
        window.setTitle("1200x675");
        break;
    case 3:
        newsizeX = 1600;
        newsizeY = 900;
        window.setTitle("1600x900");
        break;
    default:
        break;
    }
    sf::Vector2u windowsize(newsizeX, newsizeY);
    window.setSize(windowsize);
    window.setPosition(sf::Vector2i(0, 0));
    //For display text
    std::string Result;
    std::ostringstream convert;
    convert << windowsize.x << " x " << windowsize.y;
    Result = convert.str();
    return Result;
}

void Blit(int x, int y, int srcX, int srcY, int srcW, int srcH, sf::Sprite sprt)
{
    sprt.setPosition(x, y);
    sprt.setTextureRect(sf::IntRect(srcX, srcY, srcW, srcH));
    window.draw(sprt);
}
void BlitWithAlpha(int x, int y, int srcX, int srcY, int srcW, int srcH, sf::Sprite sprt, int alphachannel)
{
    sprt.setPosition(x, y);
    sprt.setTextureRect(sf::IntRect(srcX, srcY, srcW, srcH));
    sprt.setColor(Color(255, 255, 255, alphachannel));
    window.draw(sprt);
}
void BlitImage8x16(int x, int y, int srcX, int srcY, sf::Sprite sprt)
{
    sprt.setPosition(x, y);
    sprt.setTextureRect(sf::IntRect(srcX, srcY, 8, 16));
    window.draw(sprt);
}
void CustomText(int x, int y, std::string st)
{
    int StringLength, FontXPos, CharacterSpacing = 8;
    std::string character;
    StringLength = st.length();
    for (int n=0; n<=StringLength-1; n++)
    {
            character = st.substr(n,1);
            if (character == "A") FontXPos = 0;
            if (character == "B") FontXPos = 8;
            if (character == "C") FontXPos = 16;
            if (character == "D") FontXPos = 24;
            if (character == "E") FontXPos = 32;
            if (character == "F") FontXPos = 40;
            if (character == "G") FontXPos = 48;
            if (character == "H") FontXPos = 56;
            if (character == "I") FontXPos = 64;
            if (character == "J") FontXPos = 72;
            if (character == "K") FontXPos = 80;
            if (character == "L") FontXPos = 88;
            if (character == "M") FontXPos = 96;
            if (character == "N") FontXPos = 104;
            if (character == "O") FontXPos = 112;
            if (character == "P") FontXPos = 120;
            if (character == "Q") FontXPos = 128;
            if (character == "R") FontXPos = 136;
            if (character == "S") FontXPos = 144;
            if (character == "T") FontXPos = 152;
            if (character == "U") FontXPos = 160;
            if (character == "V") FontXPos = 168;
            if (character == "W") FontXPos = 176;
            if (character == "X") FontXPos = 184;
            if (character == "Y") FontXPos = 192;
            if (character == "Z") FontXPos = 200;
            if (character == "a") FontXPos = 208;
            if (character == "b") FontXPos = 216;
            if (character == "c") FontXPos = 224;
            if (character == "d") FontXPos = 232;
            if (character == "e") FontXPos = 240;
            if (character == "f") FontXPos = 248;
            if (character == "g") FontXPos = 256;
            if (character == "h") FontXPos = 264;
            if (character == "i") FontXPos = 272;
            if (character == "j") FontXPos = 280;
            if (character == "k") FontXPos = 288;
            if (character == "l") FontXPos = 296;
            if (character == "m") FontXPos = 304;
            if (character == "n") FontXPos = 312;
            if (character == "o") FontXPos = 320;
            if (character == "p") FontXPos = 328;
            if (character == "q") FontXPos = 336;
            if (character == "r") FontXPos = 344;
            if (character == "s") FontXPos = 352;
            if (character == "t") FontXPos = 360;
            if (character == "u") FontXPos = 368;
            if (character == "v") FontXPos = 376;
            if (character == "w") FontXPos = 384;
            if (character == "x") FontXPos = 392;
            if (character == "y") FontXPos = 400;
            if (character == "z") FontXPos = 408;
            if (character == "0") FontXPos = 416;
            if (character == "1") FontXPos = 424;
            if (character == "2") FontXPos = 432;
            if (character == "3") FontXPos = 440;
            if (character == "4") FontXPos = 448;
            if (character == "5") FontXPos = 456;
            if (character == "6") FontXPos = 464;
            if (character == "7") FontXPos = 472;
            if (character == "8") FontXPos = 480;
            if (character == "9") FontXPos = 488;
            if (character == "=") FontXPos = 496;
            if (character == "(") FontXPos = 504;
            if (character == ")") FontXPos = 512;
            if (character == "-") FontXPos = 520;
            if (character == "+") FontXPos = 528;
            //if (character == "\") FontXPos = 536;
            if (character == "/") FontXPos = 544;
            if (character == ".") FontXPos = 552;
            if (character == ",") FontXPos = 560;
            if (character == "!") FontXPos = 568;
            if (character == "?") FontXPos = 576;
            if (character == ";") FontXPos = 584;
            if (character == ":") FontXPos = 592;
            if (character == "`") FontXPos = 600;
            if (character == " ") FontXPos = 608;
                BlitImage8x16(x + (CharacterSpacing * n), y, FontXPos, 0, smallalpha);
    }
}
std::string ConvertToString(float num)
{
    std::stringstream ss;
    ss << num;
    std::string StringValue = ss.str();
    return StringValue;
}

int main()
{
      sf::Time SFMLtime;
      sf::Clock SFMLclock;
      SFMLtime = SFMLclock.getElapsedTime();
      float clk = SFMLtime.asMilliseconds();
    //FPS...
    Uint32 currentTick = clk;
    int pastFPS = 0, currentFPS = 0, FPScounter = 0;
    int FPSQ = 33;
    Uint32 waittime = 1000/FPSQ;
    Uint32 framestarttime = 0;
    //Sint32 delaytime = 0;
    unsigned int delaytime = 0;
    //End FPS


    std::string Resolution;
    //Get current video resolution...
    //sf::VideoMode Vid = sf::VideoMode::getDesktopMode();

    window.create(sf::VideoMode(800, 450, 32), "A New Window");
    //window.setFramerateLimit(60);


    Tplayer.loadFromFile("player.png");
    Splayer1.setTexture(Tplayer);
    SmallAlpha.loadFromFile("smallalpha.png");
    smallalpha.setTexture(SmallAlpha);
    Back.loadFromFile("background.png");
    background.setTexture(Back);
    mainchar.loadFromFile("spritesheet2.png");
    char1.setTexture(mainchar);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
            if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
                window.close();
            if (event.type == sf::Event::KeyPressed)
            {
                if (event.key.code == sf::Keyboard::F12) Resolution = GetFullScreen(0);
                if (event.key.code == sf::Keyboard::F11) Resolution = GetFullScreen(1);
                if (event.key.code == sf::Keyboard::F10) Resolution = GetFullScreen(2);
                if (event.key.code == sf::Keyboard::F9) Resolution = GetFullScreen(3);
            }
            if (event.type == sf::Event::KeyReleased)
            {
            }
        }

        window.clear();

        Blit(0, 0, 0, 0, 800, 450, background);

        SFMLtime = SFMLclock.getElapsedTime();
        float clk = SFMLtime.asMilliseconds();

        CustomText(10, 10, "SFML 2.1");
        CustomText(10, 30, ConvertToString(clk));
        CustomText(10, 50, Resolution);

        Blit(200, 200, 0, 0, 32, 32, Splayer1);
        Blit(768, 360, 32, 0, 32, 32, Splayer1);
        //for(int i = 0; i <= 255; i = i + 10)
        //{
        //    BlitWithAlpha(i+(i*2), 400, 0, 0, 32, 32, Splayer1, i);

        //}
        BlitWithAlpha(418, 250, 0, 0, 32, 32, Splayer1, 128);
        Walk_Right(125, 125, 0);


CustomText(50, 100, ConvertToString(currentTick));
CustomText(50, 120, ConvertToString(delaytime));
CustomText(50, 140, ConvertToString(pastFPS));
CustomText(50, 160, ConvertToString(framestarttime));
CustomText(50, 180, ConvertToString(FPScounter));

CustomText(200, 100, "currentTick");
CustomText(200, 120, "delaytime");
CustomText(200, 140, "pastFPS");
CustomText(200, 160, "framestarttime");
CustomText(200, 180, "FPScounter");

        //Display FPS in upper corner
        CustomText(770, 5, ConvertToString(currentFPS));
        SFMLtime = SFMLclock.getElapsedTime();
        clk = SFMLtime.asMilliseconds();
        currentTick = clk;
        window.display();
        FPScounter++;

        delaytime = waittime - (currentTick - framestarttime);
        if(delaytime > 0)
        {
            sf::sleep(sf::milliseconds(delaytime));
            framestarttime = clk;
        }

        if ( currentTick - pastFPS >= 1000 )
        {
            currentFPS = FPScounter;
            FPScounter = 0;
            pastFPS = currentTick;
        }
//        window.display();
    }

    return 0;
}

int frametime[100] = {0};
void Walk_Right(int x, int y, int index)
{
    frametime[index]++;
    if (frametime[index] > 21) frametime[index] = 0;
    if ((frametime[index] >= 0) && (frametime[index] <= 3)) Blit(x, y, 0, 0, 72, 72, char1);
    if ((frametime[index] >= 4) && (frametime[index] <= 6)) Blit(x, y, 72, 0, 72, 72, char1);
    if ((frametime[index] >= 7) && (frametime[index] <= 9)) Blit(x, y, 144, 0, 72, 72, char1);
    if ((frametime[index] >= 10) && (frametime[index] <= 12)) Blit(x, y, 216, 0, 72, 72, char1);
    if ((frametime[index] >= 13) && (frametime[index] <= 15)) Blit(x, y, 288, 0, 72, 72, char1);
    if ((frametime[index] >= 16) && (frametime[index] <= 18)) Blit(x, y, 360, 0, 72, 72, char1);
    if ((frametime[index] >= 19) && (frametime[index] <= 21)) Blit(x, y, 432, 0, 72, 72, char1);
}
 

4
Graphics / Not a member of sf::Style?
« on: August 27, 2013, 04:57:31 am »
I was messing around with this sample code and got this error...

H:\SFML_Projects\Sample1\main.cpp||In function 'int main()':|
H:\SFML_Projects\Sample1\main.cpp|6|error: 'FullScreen' is not a member of 'sf::Style'|
||=== Build finished: 1 errors, 0 warnings (0 minutes, 0 seconds) ===|


#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window;
    window.create(sf::VideoMode(800, 600, 32), "A New Window", sf::Style::FullScreen);

    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}
 

If I take out the...    sf::Style::FullScreen  it works fine.

When I type sf::Style::  ...  I get   ...  __Unnamed  as my only option

I'm using codeblocks 12.11 and sfml 2.1

Thanks for any help on this.

5
General / CodeBlocks libstdc++-6.dll??
« on: August 26, 2013, 09:35:23 pm »
Ok.  I'm getting this error like others on here.
The procedure entry point __gxx_personality_v0 could not be located in the dynamic link library libstdc++-6.dll.

So I've downloaded the  GCC 4.7 TDM (SJLJ) - 32 bits  2.0 version, recompiled and still getting this error.
I tried the 2.1 version as well.

I have Code Blocks 12.11 and using the pre-packaged compiler.
I also noticed in the bin directory of Mingw, I have both of these files:
libgcc_s_sjlj-1.dll
libgcc_s_dw2-1.dll
I don't know if it makes any difference.

Thanks for any possible help.

UPDATE:


Got it fixed.  I forgot to change out the dll files in my project folder when I changed versions.   :-[


Pages: [1]
anything