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

Pages: [1]
1
Graphics / Incredibly slow colored tile rendering. optimization help?
« on: March 06, 2011, 01:05:20 am »
I tried making similar opengl-calls, although not the correct ones, they were approximately as stressfull as they will be if i implement my own opengl drawing methods.
I noticed there's the sf::shape class, is this faster than an sf::sprite with no image?
I could also write my own subclass of sf::Drawable so that i have full control of what is drawn. What's the best approach?

EDIT: Forgot to mention: The opengl calls did almost nothing to the fps.
EDIT2: With nothing I mean that it's still ~70fps

EDIT3:
Okay, i tried subclassing sf::Drawable, but i'm having a bit of trouble. Can anyone tell me what's wrong with the following code?

Code: [Select]
#ifndef PIXEL_H
#define PIXEL_H

#include <SFML/Graphics.hpp>
#include <SFML/Graphics/RenderTarget.hpp>
#include <SFML/Graphics/Drawable.hpp>

class Pixel: public sf::Drawable {
    virtual void Render(sf::RenderTarget& Target) const{
        sf::Color color = GetColor();
        glColor4i(color.r, color.g, color.b, color.a); //using this line gives no tile at all
//        glColor3i(0xff, 0xff, 0xff); //when i use this line, i get a black tile
        glRecti(0,0,1,1);
    }
};

#endif

2
Graphics / Incredibly slow colored tile rendering. optimization help?
« on: March 05, 2011, 05:51:53 pm »
I've written a simple sokoban game and I'm trying to draw colored tiles for graphic using sfml.
I think i did everything right, but I'm getting an incredibly slow framerate.

Here's the most importan sfml part of my program:

Code: [Select]
#ifndef SOKOBANSTATE_H
#define SOKOBANSTATE_H

#include "gamstate.h"
#include "board.h"

class SokobanState: public GameState {
    private:
        static const int TILESIZE=16;
        static const int VIEWWIDTH=Game::WINDOWWIDTH/TILESIZE;
        static const int VIEWHEIGHT=Game::WINDOWHEIGHT/TILESIZE;

        sf::Sprite mShadow[VIEWWIDTH][VIEWHEIGHT];
        sf::View mWorldView;
        sf::RenderWindow& window;
        sf::View& defaultView;
        sf::Image mGroundImage, mBoxImage, mPlayerImage, mWallImage;
        sf::Sprite mGroundSprite, mBoxSprite, mTargetSprite, mPlayerSprite, mWallSprite;
        Board mBoard;


    public:
        SokobanState(Game* game):
            GameState(game),
            mWorldView(sf::FloatRect(0, 0, VIEWWIDTH, VIEWHEIGHT)),
            window(pGame->mWindow),
            defaultView(window.GetDefaultView())
        {

            mGroundSprite.Resize(1,1);
            mGroundSprite.SetColor(sf::Color(200, 100, 0));
            mBoxSprite.Resize(1,1);
            mBoxSprite.SetColor(sf::Color(255, 255, 50));
            mPlayerSprite.Resize(1,1);
            mPlayerSprite.SetColor(sf::Color(255, 0, 0));
            mWallSprite.Resize(1,1);
            mWallSprite.SetColor(sf::Color(150, 150, 150));
            mTargetSprite.Resize(1,1);
            mTargetSprite.SetColor(sf::Color(30, 200, 30));

            for(int i=0; i<VIEWWIDTH; ++i){
                for(int j=0; j<VIEWHEIGHT; ++j){
                    sf::Sprite* sprite=&mShadow[i][j];
                    sprite->SetPosition(i, j);
                    sprite->Resize(1,1);
                    sprite->SetColor(sf::Color(0, 0, 0, 70+rand()%105));
                }
            }
        }
//        virtual void init(){}
//        virtual void pause(){}
//        virtual void resume(){}
        virtual void handleEvent(sf::Event event){
            // Escape key pressed
            if (event.Type == sf::Event::KeyPressed){
                if      (event.Key.Code == sf::Key::Escape)
                    pGame->mStateManager.popState();
                else if (event.Key.Code == sf::Key::Up)mBoard.move(Board::UP);
                else if (event.Key.Code == sf::Key::Down)mBoard.move(Board::DOWN);
                else if (event.Key.Code == sf::Key::Left)mBoard.move(Board::LEFT);
                else if (event.Key.Code == sf::Key::Right)mBoard.move(Board::RIGHT);
            }

        }
//        virtual void update(){}
        virtual void draw(){
            window.SetView(mWorldView);
            window.Clear(sf::Color::White);


            for(int i=0; i<Board::WORLDWIDTH; ++i){
                for(int j=0; j<Board::WORLDHEIGHT; ++j){
                    sf::Sprite* sprite=&mWallSprite;
                    char tile=mBoard.getTile(i, j);
                    if(tile&Board::WALL)            1;
                    else if(tile&Board::INVALIDTILE)1;
                    else if(tile&Board::PLAYER)     sprite=&mPlayerSprite;
                    else if(tile&Board::BOX)        sprite=&mBoxSprite;
                    else if(tile&Board::SPACE)      sprite=&mGroundSprite;
                    else if(tile&Board::TARGET)     sprite=&mTargetSprite;
                    else 1;

                    sprite->SetPosition(i, j);
                    window.Draw(*sprite);
                }
            }
        }
};

#endif


This draws a 40x25 world on my netbook at ~2-3 fps.
I'm not even using images for rendering so why is this so incredibly slow?
At the menu screen i'm rendering a whole 1024x600 image at 100fps
any ideas?

3
General / [Solved] Problems statically linking to sfml2 using CB
« on: May 30, 2010, 12:30:55 pm »
I really feel like an idiot posting here.
I usually don't have problems with linking.
However, now i have.

I built sfml using the bat-script.
Everything went fine with no errors.
I copied everything (including *-s.a files) to my codeblocks lib directory.
I played around with sfml for a while, dynamic linking works fine.
To reduce the dl-size of my project, i tried to statically link.

However, i get a lot of linking errors.
Here's the first error:
Code: [Select]
D:\Programmering\GiantSilverGiraffe\Framework\src\Game.cpp|24|undefined reference to `_imp___ZN2sf12RenderWindowC1Ev'|

currently i am linking to:
-lsfml-graphics-s-d
-lsfml-window-s-d
-lsfml-system-s-d

What am i doing wrong?

EDIT: I removed SFML_DYNAMIC from my defines and static debug linking worked!

However, I still get linking problems when i try to build the release version.
.\obj\Release\MainMenu.o:MainMenu.cpp:(.text$_ZN11AltExitGameD1Ev[AltExitGame::~AltExitGame()]+0x39)||undefined reference to `_imp___ZTVN2sf4TextE'|

EDIT2: Okay, I've narrowed it down to being codeblocks fault.
In my codeblocks project, i have two targets, debug and release.
The two setups are nearly identical, yet linking fails with the release build.

I tried linking to the -s (not -s-d) on the debug target, and it built.
This seems like a really weird codeblocks related issue.

EDIT3: After duplicating the debug release, and modifying it, i finally have a realease build that works.
It's a mystery why it failed initially, though.

Pages: [1]