Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Trying to create a graphics engine  (Read 2625 times)

0 Members and 1 Guest are viewing this topic.

DylanMorgan

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
Trying to create a graphics engine
« on: November 20, 2017, 09:49:23 pm »
Okay, so for my new development idea I want to get a solid base before I start working on the game itself. This means I want to set up a graphics engine, sound handler, event handler and logic engine. As I have had a really long break from coding, I am extremely rusty. I was wondering whether using sf::Drawable is going to benefit me in my engine. I can't seem to get it to work right now, these errors are repeated for different lines of code:

Quote
1>d:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.10.25017\include\xmemory0(774): error C2528: 'pointer': pointer to reference is illegal
1>d:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.10.25017\include\xmemory0(984): note: see reference to class template instantiation 'std::allocator<_Ty>' being compiled
1>        with
1>        [
1>            _Ty=sf::Drawable &
1>        ]

This is my code:

Code: [Select]
#ifndef GRAPHICS_ENGINE
#define GRAPHICS_ENGINE

class GraphicsEngine
{
public:
GraphicsEngine();
~GraphicsEngine();

int addToVector(sf::Drawable& drawableObject);
void deleteFromVector(int objectNumber);

void callObjectsDraw(sf::RenderWindow& window);

private:
std::vector<sf::Drawable&> vectorOfDrawableObjects;
};

#endif

Code: [Select]
#include "stdafx.h"
#include "graphicsEngine.h"

GraphicsEngine::GraphicsEngine()
{
}

GraphicsEngine::~GraphicsEngine()
{
}

int GraphicsEngine::addToVector(sf::Drawable& drawableObject)
{
vectorOfDrawableObjects.push_back(drawableObject);
int objectNumber = vectorOfDrawableObjects.size();

return objectNumber;
}

void GraphicsEngine::deleteFromVector(int objectNumber)
{
vectorOfDrawableObjects.erase(vectorOfDrawableObjects.begin() + objectNumber);
}

void GraphicsEngine::callObjectsDraw(sf::RenderWindow& window)
{
for (int i = 0; i < vectorOfDrawableObjects.size(); i++)
{
window.draw(vectorOfDrawableObjects[i]);
}
}

If you can see I have made some basic error and don't want to explain it, I would appreciate a point in the right direction to where I can read up on the theroy behind it :)

achpile

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • Achpile's homepage
    • Email
Re: Trying to create a graphics engine
« Reply #1 on: November 20, 2017, 11:41:42 pm »
Drawables have different sizes, also you making duplicates. try to use pointers.

std::vector<sf::Drawable*> vectorOfDrawableObjects;


int GraphicsEngine::addToVector(sf::Drawable* drawableObject)
{
        vectorOfDrawableObjects.push_back(drawableObject);
        int objectNumber = vectorOfDrawableObjects.size();

        return objectNumber;
}


void GraphicsEngine::callObjectsDraw(sf::RenderWindow& window)
{
        for (int i = 0; i < vectorOfDrawableObjects.size(); i++)
        {
                window.draw(*vectorOfDrawableObjects[i]);
        }
}


 

DylanMorgan

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
Re: Trying to create a graphics engine
« Reply #2 on: November 21, 2017, 06:28:52 pm »
Wow thank you, didn't notice I was doing that :)

DarkRoku12

  • Full Member
  • ***
  • Posts: 203
  • Lua coder.
    • View Profile
    • Email
Re: Trying to create a graphics engine
« Reply #3 on: November 21, 2017, 08:26:48 pm »
Only to advice:

I, as creator of a 2D Game Engine (i will public release the engine when i have time) i recommend:

If you want to make a game, you have a lot of Game Engines out there, you don't need to create one.

If you want to make your own becuase others game engines does not convince you, or, you want to learn.
Before launching you to this world, it will be not only good to lear how to use SFML and basic C++.

A really good engine need to be done by:
- People that knows about graphics processing.
- People that knows about good C/C++.
- People willing to read and investigate a lot.
- People that have time that can invest on the development of the game engine.
- More than 1 people.

Why more than 1 people?
You don't need only to create the engine, you also need to:
- Test it (a lot).
- Try to make the API programmer friendly.
- Make a proper documentation.
- If it will be multi-platform no one people can deep learn Windows/OSX/Linux/Android/IOS so you'll need people involved particularly in each individual area.

But in your time develping the engine, you may never finish it, but you'll end up learning a lot of things.

Have luck and fun in adventure.  ;D
I would like a spanish/latin community...
Problems building for Android? Look here

 

anything