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

Pages: [1]
1
Graphics / Framerate, rendering and optimisations
« on: February 15, 2012, 10:57:04 pm »
Hi! :)

So I'm coding this little game, just for fun, and when I add say more than twenty objects, it starts to go downhill. I have a recent computer with a graphics card (nvidia geforce GT 540m, it says) and a intel core i5 CPU. So it's not slow or anything.

Could it possibly be because I'm using linux, and I couldn't work out the drivers and I think I'm using the software renderer? AssaultCube runs really slowly on it. Is that the cause?

I commented out the line that initiates the rendering, and got an FPS of about 64-70. Which is good, because I set the renderWindow to have a max framerate of 64. But when the line is uncommented (that is, I allow it to render my objects, of which I only have about 40, 32x32 sprites) the FPS drops. A lot. I got it down to 18 once.

I was going to post a whole lot more info, but it just hit me that it's probably the software renderer, isn't it?

*groans* I'm going to have to reinstall linux :(

2
SFML website / How about sending an email when a new topic is posted?
« on: January 01, 2011, 01:33:38 am »
On these forums, it would be nice if there was a "Watch forum" button, or something, so I could "watch" the Graphics forum, and every time a new topic is posted, it sends me an email with the topic (not for every post though, only topics). You could even do a "daily digest" of posts (posts, not topics) each day.

Forgive me if it's already implemented ;)
I can't find it anywhere, is all.

Justification: I don't have enough time to browse these forums (and even if I did I would forget), but I do like helping people, so when I see a topic I can help with, I'd be able to jump right in.

Anyway, there's my twenty cents :)

3
Graphics / [solved] sf::Image* problem ;)
« on: January 01, 2011, 01:22:21 am »
Hi there! I'm trying to make a class that handles animation (and before you ask, I checked out the wiki, what was there didn't fit my needs), and am having some problems ;)

Basically, my class takes a pointer to a sprite and changes that sprites image based on what frame it should be at (the frames are pointers to images). Here's the code, which'll hopefully speak for itself :)

Animation.hpp
Code: [Select]
#ifndef Animation_hpp
#define Animation_hpp

#include <string>
#include <vector>
#include <SFML/Graphics.hpp>

class Animation {
public:
Animation();
void SetSprite(sf::Sprite*);
void AddFrame(const std::string& path);
void SetSpeed(unsigned int speed);
void AdvanceFrame();
//private:
std::vector< sf::Image* > mFrames;
sf::Sprite* mSpr;
unsigned int mSpeed;
unsigned int mCurrentFrame;
unsigned int mCount;
};

#endif

Animation.cpp
Code: [Select]
#include "Animation.hpp"
#include "Main.hpp"
//imagemanager.hpp is just my images manager, surpisingly
#include "ImageManager.hpp"

#include <iostream>

Animation::Animation() {
mCount = 0;
mSpeed = 10;
mCurrentFrame = 0;
}
void Animation::SetSprite(sf::Sprite* spr) {
mSpr = spr;
}
void Animation::AddFrame(const std::string& path) {
        //ImageManager.LoadImage() just returns a pointer to an image.
sf::Image* timg = ImageManager.LoadImage(path);
mFrames.push_back(timg);
}
void Animation::SetSpeed(unsigned int speed) {
mSpeed = speed;
}
void Animation::AdvanceFrame() {
if (mFrames.size() > 0) {
mCount += mSpeed;
if (mCount >= 100) {
mCount = 0;
mCurrentFrame++;
if (mCurrentFrame == mFrames.size()-1) {
mCurrentFrame = 0;
}
//std::cout << mFrames.size()-1 << " : " << mCurrentFrame << std::endl;
mSpr->SetImage( *( mFrames[mCurrentFrame] ) );
}
}
}

So now you hopefully know what I'm getting at.
Here's the code I'm using to use this class:
Code: [Select]
     mAnim.SetSprite(&mSpr);
mAnim.AddFrame("images/trail-b_u.png");
mAnim.AddFrame("images/trail-b_r.png");
mAnim.AddFrame("images/trail-b_d.png");
mAnim.AddFrame("images/trail-b_l.png");

and in the main loop I call mAnim.AdvanceFrame();

 I did a bit of testing, and replaced
Code: [Select]
void Animation::AddFrame(const std::string& path) {
        //ImageManager.LoadImage() just returns a pointer to an image.
sf::Image* timg = ImageManager.LoadImage(path);
mFrames.push_back(timg);
}

with
Code: [Select]

void Animation::AddFrame(const std::string& path) {
sf::Image* timg = ImageManager.LoadImage(path);
mFrames.push_back(timg);
sf::Image* img;
std::cout << "a" << std::endl;
img = (mFrames[0]);
std::cout << "b" << std::endl;
mSpr->SetImage(*img);
std::cout << "c" << std::endl;
}

and my output is
Code: [Select]
a
b
c
a
b
c
a
b
Segmentation fault

Isn't this fun? So I seem to be getting the error when I do "mSpr->SetImage(*img);". Quite frankly, I have no idea why. It might be my imagemanager's fault, but I doubt it.

Thanks for reading that through and even if you've just got an idea of what's wrong, I'd love to hear it  :)

I just thought I'd put my twenty-cents in and say I reckon SFML would do nicely with an animation class of it's own :)

If I forgot anything don't hesitate to remind me :)
Thanks :)
Stewart

[EDIT] Sorry if this is in the wrong section, or has nothing to do with SFML. I just didn't know where to put it :(

4
Feature requests / Copy a Sprite onto an Image
« on: November 25, 2010, 10:22:18 am »
You know how you can copy a sf::Image onto another sf::Image? This is a handy feature I'm using quite a bit in the game I'm making. However, I feel being able to copy an sf::Sprite onto a sf::Image would be extremely useful. When you copy a sf::Image you don't get the rotation, scale factors or anything. Because of this, instead of just using Rotate(), I'm going to have to use about 5 different images in my game. I think this would be a useful addition.

So basically, I would like to copy a sf::Sprite onto a sf::Image. It's just a suggestion :)

Awesome library, really simple, keep it up!

5
General / Having trouble with DLLs, threads AND RenderWindows
« on: October 12, 2010, 06:35:42 am »
Hi guys, nice to meet you all! Man, that's an awesome range of emoticions over there -<<
 :shock:
hehe.

Anyway, I'm making a program that loads DLLs and for each DLL it creates a thread for it, and the thread executes one function that the DLL contains. Yeah, crappy explanation I know.

Anyway, when I pass a RenderWindow to the DLL and try to draw on it, it fails. Funny thing is I can move the RenderWindow using SetPosition. Well actually it isn't funny, because it makes less sense.

I tried moving the Clear() and Display() code to the DLL but nothing is working.

Anyway, if anyone has any idea as to why this is happening I'd love to hear them. I'll send an icecream to anyone who helps :)

Thanks for taking your time to read this and have a nice day!!!

--Stewart

Pages: [1]