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

Pages: 1 ... 3 4 [5] 6 7 ... 15
61
Graphics / Re: A question about textures and drawing
« on: June 13, 2014, 09:57:56 pm »

62
Graphics / Re: A question about textures and drawing
« on: June 13, 2014, 05:39:29 pm »
EDIT:: I drawn conclusion you meant, there is no switch performed.

The texture is already uploaded to the GPU when you create it. But if you make two draw calls with the same texture, you save one texture switch on the GPU, which is expensive.
I am still unsure of the answer :D.

Code: [Select]
sf::Texture tex;
sf::RenderWindow & win;
sf::VertexArray verArr1;
sf::VertexArray verArr2;
sf::RenderStates renSta;

//Load texture
//... add vertices to both verArr
verArr1.setPrimitiveType(sf::Quads);
renSta.texture = &tex;


win.draw(verArr1, renSta);//Draw 1
win.draw(verArr2, renSta);//Draw 2
In draw 1, the texture switch will occur, its the first draw call i ever made.
My question is: Is the Draw 2, gonna perform a texture switch as well?

63
Graphics / A question about textures and drawing
« on: June 13, 2014, 04:20:37 pm »
Hello.
I am wondering how to setup my sprites sheet for objects, tiles, and units...
Id personally put it in one big texture, but i was wondering If there are two draw calls with same texture, one after another, does it copy the texture again intro the gpu, or does it know not to copy texture again?

And if i wanted to find out something as this, would i read about GPUs, OpenGL or what?

64
SFML projects / Re: Anyone want to build a 2D game with me?
« on: June 13, 2014, 04:16:32 pm »
Hello everyone, I was wondering if someone would like to work on a 2D Zelda like RPG game for fun and for learning purposes. Your level of C++ and SFML isn't necessary, as long as you know basics that's all that counts. We can both learn and build a 2D game!

As for the name of the game, I don't have one yet!
I would like a Zelda like game, but rather than playing with Zelda, you'll be prompted the option of choosing either Warrior, Archer, or Mage!

The game will be a bit long and tedious but like I said, it's just a fun project we can start and have it on github to work on! I'm looking for 2 other members ! Anyone interested be sure to add me on skype AndreeU17

Thanks guys for reading this and hopefully we'll see you guys soon
What is your c++ skills, how experienced are you (What games did you make in past, links please).
I myself would like some help with coding on current 2d, top down fantasy rpg. I have a team, but if you are skilled i am looking for guinea pigs :D some screenShots http://postimg.org/my.php?gallery=7zo1b6rq

65
Graphics / Re: Can sf::Font font be in a Constructor parameter?
« on: June 07, 2014, 06:23:38 pm »
There are quite some ways of achieving what you want to do.
Why not pass in font by reference?
Code: [Select]
Game(sf::Font & loadFont ,std::string title, int characterSize, sf::Vector2f position, sf::Color color)
You usually never want to load one font multyple times, and in here it seems that is the case.
Have sf::Font already loaded and checked for error, then whenever you need it you can use it.
Code: [Select]
sf::Font fontArial;
fontArial.loadFr...
//...
Game startTitle(Game(loadFont ,"Start", 24, sf::Vector2f(0,0), sf::Color::White));
Game startTitle(Game(loadFont ,"CrashAttempt", 32 sf::Vector2f(screen_size_x / 2, screen_size_y / 2), sf::Color(255,255,255,126));

But be aware, in order for your sf::Text to use sf::Font, you need to keep sf::Font instance alive.

66
Graphics / Re: Can i link VertexArray for drawing in one call?
« on: June 06, 2014, 01:22:51 pm »
2500 come from, non static cause physics, i have now 5 layers for collision, and its all just objects.
To illustrate, Terrain, 32x32 sprites, 800x600 screen = 450 tiles on screen, i will show tavern example.

Walls, carpets, candles on wall, Many (tables, chairs, on tables(candles, drinks, pouches with gold, gold coins)), units and all their cosmetics(armor, weapon), windows on tavern... It pretty much piles up.
I do not want static tables like (Table with glass on in) i have raw table then i place glass on top of the table.

67
Graphics / Re: Can i link VertexArray for drawing in one call?
« on: June 06, 2014, 10:59:32 am »
500 sprites is not a lot. Even 2500. Today's games draw millions of polygons.
I couldn't get too acurate data, but from little program i made i gotten:
Drawing 2500 sprites, 60fps, 13%cpu, is ~ to 95000 size vertexArray. of drawing at 60fps, and 10-20cpu usage.
That may be just my gpu, but that is a huge difference.

68
Graphics / Re: Can i link VertexArray for drawing in one call?
« on: June 05, 2014, 04:30:35 pm »
If I understand correctly, tou group several dynamic entities into vertex arrays. This is usually not a good idea. Can't you just use sprites for dynamic entities, and vertex arrays for the static background?
I am expecting large amounts(there will be no less then 50 at time and can go up to 500 easily,there will be case where it will reach about 2500 but that is the maximum) of objects on screen at any given time.
I was just wondering if it is possible to link vertexArrays together for drawing in one call.

I failed to find such feature in documentation, and if there was such a feature as linking vertexArrays togeder, in one draw call, that would increase performance, thus i searched for it.

69
Graphics / Can i link VertexArray for drawing in one call?
« on: June 04, 2014, 08:23:13 pm »
Hello.
Currently i am trying to design multy level height.

So i have a map that has 4 layers,(Floor,low,middle,high), i am not doing base layer for ground i am making objects, and i want them to be able to stack one up on other.
So if i made one vertex for each 320x320 pixel region, my issue is that whenever i add object, i don't want to reposition the whole vertex array if it is bellow another object.

If i add object to position x=0,y=0, with size w=32,h=32 at layer middle. vertexArray(VA) position will be 0-3
Now when i add another object at same position, but at layer floor VA(4-7), i need to switch those around so i will draw in correct order.
That is not issue on small scale, but i am not in small scale, and repositioning hundred vertices, for only one object is passable, but in case 10 objects tumbles from middle layer to low...

So if i make one vertexArray for each layer, i can just add intro it without any checks because objects cannot overlap, problem is that i do not know how to link the VertexArrays together for faster drawing or is it even possible, they will use same texture and renderStates.

I don't know a way to make this efficient atm.
Any suggestions would be gladly appreciated.
The point is to add and remove objects at runtime, and have them show per layer,(Draw order, floor->low->middle->high)) So if at one position we would have, (Candle-Floor, chair-low, bread-middle)
i would see chair with bread on it, no candle what so ever, and because i don't want to have over hundred of vertexArray draw calls i am asking for help.

70
Graphics / Re: 2D World Questions
« on: June 02, 2014, 06:13:39 pm »
Well if you made tilemap, just increase its X and Y sizes, meaning you add more tiles per row and column and you get bigger map.
The view is pretty complicated for starters to get i agree, i had problems myself, but if you read the tutorial on how to use it and read thru the documentation you will figure it out easily.

What you probably want to make is a static position tilemap meaning it doesn't actually move. You want to move view around, something you probably know as camera.

To sumarize the game loop:
if User holds D, move units x position 10 pixels to right.
if User holds A...
CameraView.setCenter(Unit);

RenderWindow.setView(CameraView);//After this call, everything will be drawn with offsets of the view, you dont really to know those. meaning view left up corner can be x=213,y=512 that means if unit is at x=300,y=700 it will be on screen shown at x=87,y=188 if drawn with this view set on
Draw map;
Draw Units;
RenderWindow.setView(renderWindow.getDefaultView());//If you want to draw interface, set view to default so left up corner is x=0,y=0
Draw Interface;
//If you draw unit now, and its at x=300,y=700, depending on you screen size it will probably be off screen and not visible

71
SFML projects / Re: The Wanderer - Lost in time
« on: June 02, 2014, 01:44:29 pm »
It looks quite good !
So it will be a real time sandbox-RPG or something like that ?
Focus will be done on the player or on the settlement ?
Thanks, the focus will be on player. The player will have various ways to affect town.

72
SFML projects / Re: The Wanderer - Lost in time
« on: June 02, 2014, 12:42:32 am »
Since the last message was long time ago and i got quite rusty updating this page, i redone the first post BUMP.
I will have some game play shots this month, to show what was done, also just to show THIS IS NOT DEAD! ;)

73
So i forgot to post, here you got the light system to get image:


So this system works as such.
There are two parts, DayNight which control is it dark on screen or not. And Light which is for color and data.
At DayNight i have RenderTexture that i use to create night effect, "Black screen" Then for each light i draw gradient circle to simulate light there.
At Light, it is just a normal light, A circle textured rectangle on which i control color, give it "Power" intensity via alpha color.
class Light
{
public:
        Light();
        Light(const int Radius, const sf::Color Color, const int PosX, const int PosY, bool IsBinded = 0, int UnitVecID = 0);
        int radius;
        sf::Color color;
        int posX, posY;

        bool isBindedToUnit;
        int unitVecID;
};
class LightHolder
{
public:
        LightHolder();
        void Loop(UnitList & objUnitList);
        void DrawLight(sf::RenderTexture & renTex, sf::RenderWindow & renWin);


        void AddLight(Light & light);
        void RemoveLight(const int VecID);
        void MoveLight(int VecID);

        std::vector<int> lightListEmptyPos;
        std::vector<Light> lightList;
//Light
public:
        sf::VertexArray verArrLight;
        sf::RenderStates renStatLight;
        sf::Texture texLight;
//Reveal
        sf::RenderStates renStatReveal;
        sf::Texture texReveal;
};
class DayNight
{
public:
        DayNight(daynight::TimeType typeOfTime);//0-100%, 0=Dark, 100=Light used to gain color from texture for day night
        void Loop();
        void Draw(sf::RenderWindow & renWin, sf::Vector2f & pos);

        sf::VertexArray verArr;
        sf::Color color;//Vertex color
//Night
        sf::Image imgColorForNight;
        double clockDuration;
        double increment;
        int value;
        int percent;
        daynight::TimeType timeType;
        sf::Color nightColor;
        sf::Sprite sprNight;
//Drawing
        sf::RenderTexture renTex;
        sf::RenderStates renStat;
};


//CPP FILES
DayNight::DayNight(daynight::TimeType typeOfTime)
{
        color = sf::Color(0, 30, 0, 126);
        verArr.setPrimitiveType(sf::PrimitiveType::Quads);
        verArr.append(sf::Vertex(sf::Vector2f(0,0), color, sf::Vector2f(0, 0)));
        verArr.append(sf::Vertex(sf::Vector2f(glob::WINDOW_WIDTH, 0), color, sf::Vector2f(0, 0)));
        verArr.append(sf::Vertex(sf::Vector2f(glob::WINDOW_WIDTH,glob::WINDOW_HEIGHT), color, sf::Vector2f(0, 0)));
        verArr.append(sf::Vertex(sf::Vector2f(0,glob::WINDOW_HEIGHT), color, sf::Vector2f(0, 0)));
        if(imgColorForNight.loadFromFile("./Files/Textures/NightColor.png") == false)
        {
                glob::PrintError("Unable to load image ./Files/Textures/NightColor.png From DayNight::DayNight");
        }

        renTex.create(glob::WINDOW_WIDTH, glob::WINDOW_HEIGHT);
        renStat.blendMode = sf::BlendMultiply;

        clockDuration = daynight::DAY_DURATION;
        increment = 1000/60;
        value = 0;
        percent = 0;

        timeType = typeOfTime;
        if(typeOfTime == daynight::TTDay)
                value = 100;
        else if(typeOfTime == daynight::TTNight)
                value = 0;
        else if(typeOfTime == daynight::TTDawn)
                value = 25;
        else if(typeOfTime == daynight::TTDusk)
                value = 75;
        nightColor = imgColorForNight.getPixel((value * imgColorForNight.getSize().x) / 100, 0);//24 because its max time of day
}

void DayNight::Loop()
{
//DAY
        if(timeType == daynight::TTDay)
        {
                clockDuration -= increment;
                if(clockDuration < 0)
                {//Set dusk
                        clockDuration = daynight::DUSK_DURATION;
                        timeType = daynight::TTDusk;
                        value = 0;
                }
                //nightColor = sf::Color::White;
        }
//DUSK SUN DOWN
        else if(timeType == daynight::TTDusk)
        {
                clockDuration -= increment;

                int percent = static_cast<double>(clockDuration) / daynight::DUSK_DURATION * 100;
                value = (imgColorForNight.getSize().x / 100) * percent;
                if(value < 0)
                        value = 0;
                else if(value > imgColorForNight.getSize().x-1)
                        value = imgColorForNight.getSize().x-1;
                nightColor = imgColorForNight.getPixel(value, 0);

                if(clockDuration < 0)
                {//Set night
                        clockDuration = daynight::NIGHT_DURATION;
                        timeType = daynight::TTNight;
                        value = 0;
                        nightColor = imgColorForNight.getPixel(0, 0);
                }
        }
//NIGHT
        else if(timeType == daynight::TTNight)
        {
                clockDuration -= increment;
                if(clockDuration < 0)
                {//Set dusk
                        clockDuration = daynight::DAWN_DURATION;
                        timeType = daynight::TTDawn;
                        value = 0;
                }
                //nightColor = sf::Color(0, 0, 30, 255);
        }
//DAWN SUN RISE
        else if(timeType == daynight::TTDawn)
        {
                clockDuration -= increment;

                int percent = static_cast<double>(clockDuration) / daynight::DUSK_DURATION * 100;
                value = imgColorForNight.getSize().x - ((imgColorForNight.getSize().x / 100) * percent);
                if(value < 0)
                        value = 0;
                else if(value > imgColorForNight.getSize().x-1)
                        value = imgColorForNight.getSize().x-1;
                nightColor = imgColorForNight.getPixel(value, 0);

                if(clockDuration < 0)
                {//Set night
                        clockDuration = daynight::DAY_DURATION;
                        timeType = daynight::TTDay;
                        value = 0;
                        nightColor = imgColorForNight.getPixel(imgColorForNight.getSize().x - 1, 0);
                }
        }
        renTex.clear(nightColor);


        /*
        //Calculate dayNightClock value from time of day
        dayNightClock += increment;
        if(dayNightClock >= imgColorForNight.getSize().x)
        {
                increment = -1;
                dayNightClock = imgColorForNight.getSize().x-1;
        }
        else if(dayNightClock <= 0)
        {
                increment = 1;
                dayNightClock = 0;
        }
        nightColor = imgColorForNight.getPixel(dayNightClock, 0);
//Set colors appropriate to day
        renTex.clear(nightColor);
        */

}

void DayNight::Draw(sf::RenderWindow & renWin, sf::Vector2f & pos)
{
        renTex.display();
        sprNight.setTexture(renTex.getTexture());
        sprNight.setPosition(pos);
        renWin.draw(sprNight, renStat);
}
Light::Light()
{
        radius = 0;
        color = sf::Color(255, 255, 255, 255);
        posX = 0;
        posY = 0;

        isBindedToUnit = false;
        unitVecID = 0;
}

Light::Light(const int Radius, const sf::Color Color, const int PosX, const int PosY, bool IsBinded, int UnitVecID) :
        radius(Radius), color(Color), posX(PosX), posY(PosY), isBindedToUnit(IsBinded), unitVecID(UnitVecID)
{

}

//////////////////////////////////////////////////////////////////////////

LightHolder::LightHolder()
{
        verArrLight.setPrimitiveType(sf::PrimitiveType::Quads);
        if(texLight.loadFromFile(light::LIGHT_TEXTURE_DIR + "Light.png") == false)
        {
                glob::PrintError("Failed loading texture '"+ light::LIGHT_TEXTURE_DIR + "Light.png" + " at LightHolder::LightHolder");
        }
        renStatLight.texture = &texLight;
        renStatLight.blendMode = sf::BlendAdd;

        if(texReveal.loadFromFile(light::LIGHT_TEXTURE_DIR + "Reveal.png") == false)
        {
                glob::PrintError("Failed loading texture '"+ light::LIGHT_TEXTURE_DIR + "Reveal.png" + " at LightHolder::LightHolder");
        }
        //renStatReveal.texture = &texReveal;
        renStatReveal.texture = &texReveal;
        renStatReveal.blendMode = sf::BlendAdd;
}

void LightHolder::Loop(UnitList & objUnitList)
{
        for(unsigned int i = 0; i < lightList.size(); i++)
        {
                if(lightList[i].isBindedToUnit)
                {
                        lightList[i].posX = objUnitList.unitList[lightList[i].unitVecID].ubp.posX;
                        lightList[i].posY = objUnitList.unitList[lightList[i].unitVecID].ubp.posY;
                        MoveLight(i);                  
                }
        }
        //lightList[0].posX = objUnitList.unitList[0].unitProperties.posX;
        //lightList[0].posY = objUnitList.unitList[0].unitProperties.posY;
        //MoveLight(0);

        //lightList[1].posX = objUnitList.unitList[1].unitProperties.posX;
        //lightList[1].posY = objUnitList.unitList[1].unitProperties.posY;
        //MoveLight(1);
}

void LightHolder::DrawLight(sf::RenderTexture & renTex, sf::RenderWindow & renWin)
{
        sf::Uint8 alphaColor;
        if(verArrLight.getVertexCount() > 0)
                alphaColor = verArrLight[0].color.a;
//Draw to texture
        for(unsigned int i = 0; i < verArrLight.getVertexCount(); i++)
        {
                verArrLight[i].color.a = 255;
        }
        renTex.draw(verArrLight, renStatReveal);
//Draw to window
        for(unsigned int i = 0; i < verArrLight.getVertexCount(); i++)
        {
                verArrLight[i].color.a = alphaColor;
        }
        renWin.draw(verArrLight, renStatLight);
}

void LightHolder::AddLight(Light & light)
{
        //Check if empy list has a position
                //If has pick from it
                //else make a new position
        int vecID;
        if(lightListEmptyPos.size() > 0)
        {
                vecID = lightListEmptyPos[lightListEmptyPos.size() -1];
                lightListEmptyPos.pop_back();
                //Modify light
                lightList[vecID] = light;

                MoveLight(vecID);
        }
        else
        {//Create new positions
                vecID = lightList.size();
                //Add and modify light
                lightList.push_back(light);

                verArrLight.append(sf::Vertex(sf::Vector2f(light.posX, light.posY), light.color, sf::Vector2f(0, 0)));
                verArrLight.append(sf::Vertex(sf::Vector2f(light.posX, light.posY), light.color, sf::Vector2f(texLight.getSize().x, 0)));
                verArrLight.append(sf::Vertex(sf::Vector2f(light.posX, light.posY), light.color, sf::Vector2f(texLight.getSize().x, texLight.getSize().y)));
                verArrLight.append(sf::Vertex(sf::Vector2f(light.posX, light.posY), light.color, sf::Vector2f(0, texLight.getSize().y)));
                MoveLight(vecID);
        }
}

void LightHolder::RemoveLight(const int VecID)
{
        //Remove from Light
        //Remove from VA
        lightListEmptyPos.push_back(VecID);
        verArrLight[VecID*4].texCoords = sf::Vector2f(0, 0);
        verArrLight[VecID*4+1].texCoords = sf::Vector2f(0, 0);
        verArrLight[VecID*4+2].texCoords = sf::Vector2f(0, 0);
        verArrLight[VecID*4+3].texCoords = sf::Vector2f(0, 0);

        verArrLight[VecID*4].position = sf::Vector2f(0, 0);
        verArrLight[VecID*4+1].position = sf::Vector2f(0, 0);
        verArrLight[VecID*4+2].position = sf::Vector2f(0, 0);
        verArrLight[VecID*4+3].position = sf::Vector2f(0, 0);
}

void LightHolder::MoveLight(int VecID)
{
        Light & light = lightList[VecID];
        int VerID = VecID*4;
        verArrLight[VerID].position = sf::Vector2f(light.posX-light.radius, light.posY-light.radius);
        verArrLight[VerID+1].position = sf::Vector2f(light.posX+light.radius, light.posY-light.radius);
        verArrLight[VerID+2].position = sf::Vector2f(light.posX+light.radius, light.posY+light.radius);
        verArrLight[VerID+3].position = sf::Vector2f(light.posX-light.radius, light.posY+light.radius);
}

74
SFML projects / Re: Eleutheromania - 2D RPG - Work in progress
« on: May 27, 2014, 07:24:50 pm »
what algorithm you use for path finding? EG: AStar

75
Graphics / Re: SFML Tile Map Tearing
« on: May 26, 2014, 05:01:26 am »
From my personal experience that occurred when position was not rounded value.
Seeing you fixed it but you can still use std::floor(value) to get rounded down decimal value.

Pages: 1 ... 3 4 [5] 6 7 ... 15