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

Pages: 1 [2] 3
16
General / scale animation problem
« on: April 05, 2016, 01:37:19 am »
hello

i'm having trouble time with scale animation which i thought it will be most easiest part in my game that i'm working on. but it turned i was wrong about it.

my goal is to achieve smooth and constant scaling animation. i have implemented the "easing" technique to calculate ratio of scale amount that need to step each frame to sprite object. it seems run but i didn't get what i was looking for.  the scaling effect is varying from time to time which is not suppose to happen. some time it goes faster while other goes slower.

also, i have faced problem with float point comparison that i can't compare two float values for equality with if statement, i had to implement "close enough" approach.

i have created minimal example to demonstrate the issue:
(click to show/hide)

my questions
how can i fix this tripping in animation?, is my implementation is correct? and are there other ways to achieve smooth and constant scale animation?

Edit: i fixed it, my bad, it was a bug in both source code. i corrected example here and code in my game both work fine at last but it seems i overly complicated it for just scaling , i'm sure there is an easy way to do it, but i don't know it.

is there a better way to do scale animation?


17
General / tilemap glitching[Solved]
« on: March 26, 2016, 12:11:05 pm »
hello,
i have been working on simple exercise on tilemap for 2d platformer but i have experienced some frame glitching. i have no idea what cause this issue.

could someone please help me in this issue. or atleast point me to what is really cause it.

source code:
(click to show/hide)


resources is available in git
https://github.com/MORTAL2000/sfml-examples


18
General / problem with attach and detach child in SceneNode [SOLVED]
« on: February 16, 2016, 01:22:43 am »
i have problem with command pattern in SFML book that works aside with scene-graph data structure when i detached child node and attached it once again. the VS14 doesn't help me much when i debug the problem. it is point me to the vector iterator is not incrementable in onCommend(), this function seems okay, it doesn't invalidate the iterator, it just a loop.

could someone please help me in this issue, thanks you.

i have made minimal example as i could to show the problem as shown below:
#include <stdexcept>
#include <iostream>
#include <utility>
#include <vector>
#include <memory>
#include <cassert>
#include <functional>
#include <queue>
#include <algorithm>

class SceneNode;

namespace Category
{
        enum Type
        {
                None = 0,
                Player1 = 1 << 0,
                Player2 = 1 << 1,
        };
}

struct Command
{
        using Action = std::function<void(SceneNode&)>;

        Command()
                : action()
                , category(Category::None)
        {
        }

        Action          action;
        unsigned int    category;
};

template
<
        typename GameObject,
        typename Function,
        typename = std::enable_if_t<std::is_base_of<SceneNode, GameObject>::value>
>
auto derivedAction(Function fn)
{
        return [=](SceneNode& node)
        {
                fn(static_cast<GameObject&>(node));
        };
}

class CommandQueue
{
public:
        void push(const Command& command)
        {
                mQueue.push(command);
        }

        Command pop()
        {
                auto command(mQueue.front());
                mQueue.pop();
                return command;
        }

        bool isEmpty() const
        {
                return mQueue.empty();
        }


private:
        std::queue<Command>     mQueue;
};

class SceneNode
{
public:
        using Ptr = std::unique_ptr<SceneNode>;


public:
        SceneNode(Category::Type category = Category::None)
                : mChildren()
                , mParent(nullptr)
                , mDefaultCategory(category)
        {
        }

        void attachChild(Ptr child)
        {
                child->mParent = this;
                mChildren.push_back(std::move(child));
        }

        Ptr detachChild(const SceneNode& node)
        {
                auto found = std::find_if(mChildren.begin(), mChildren.end(),
                        [&](Ptr& p)
                {
                        return p.get() == &node;
                });

                assert(found != mChildren.end());

                Ptr result = std::move(*found);
                result->mParent = nullptr;
                mChildren.erase(found);

                return result;
        }

        void onCommand(const Command& command)
        {
                // Command current node, if category matches
                if (command.category & getCategory())
                        command.action(*this);

                // Command children
                for (const auto& child : mChildren) // here VS14 complains
                        child->onCommand(command);
        }

        virtual unsigned int getCategory() const
        {
                return mDefaultCategory;
        }

        SceneNode* getParent() const
        {
                return mParent;
        }

        virtual void setNumber(int i) {};


private:
        virtual void draw(std::ostream& stream) const
        {
                drawCurrent(stream);
                drawChildren(stream);
        }

        friend std::ostream& operator<<(std::ostream& stream, const SceneNode& self)
        {
                self.draw(stream);
                return stream;
        }

        virtual void drawCurrent(std::ostream& stream) const
        {
                // do nothing
        }

        void drawChildren(std::ostream& stream) const
        {
                for (const auto& child : mChildren)
                        child->draw(stream);
        }

private:
        std::vector<Ptr>        mChildren;
        SceneNode*              mParent;
        Category::Type          mDefaultCategory;
};

class Player final : public SceneNode
{
public:
        enum Type
        {
                None,
                Player1,
                Player2,
        };

public:
        Player(Type type, int n, Player* player = nullptr)
                : mType(type)
                , mNumber(n)
                , mPlayer(player)

        {
        }

        void setNumber(int i) override
        {
                mNumber = i;
        }

        void follow()
        {
                if (getCategory() & Category::Player2)
                {
                        if (mPlayer)
                        {
                                auto found = getParent()->detachChild(*this);
                                found->setNumber(20);
                                mPlayer->attachChild(std::move(found));
                        }
                }
        }

        unsigned int getCategory() const override
        {
                if (mType == Type::Player1)
                        return Category::Player1;
                else
                        return Category::Player2;
        }

private:
        void drawCurrent(std::ostream& stream) const override
        {
                stream << "Parent: "<< getParent()->getCategory() << " has child: " << mNumber << '\n';
        }


private:
        Type mType;
        int mNumber;
        Player* mPlayer;
};

int main()
{
        SceneNode sceneGraph;
        CommandQueue commandQueue;

        Player* player1;
        Player* player2;


        auto first(std::make_unique<Player>(Player::Player1, 1));
        player1 = first.get();
        sceneGraph.attachChild(std::move(first));

        // Works
        //auto second(std::make_unique<Player>(Player::Player2, 2, player1));
        //player2 = second.get();
        //player2->setNumber(20);
        //player1->attachChild(std::move(second));

        // Works
        //auto second(std::make_unique<Player>(Player::Player2, 2, player1));
        //player2 = second.get();
        //sceneGraph.attachChild(std::move(second));
        //auto found = player1->getParent()->detachChild(*player2);
        //found->setNumber(20);
        //player1->attachChild(std::move(found));

        // Works
        //auto second(std::make_unique<Player>(Player::Player2, 2, player1));
        //player2 = second.get();
        //sceneGraph.attachChild(std::move(second));
        //player2->follow();

        // Failed ????????
        auto second(std::make_unique<Player>(Player::Player2, 2, player1));
        player2 = second.get();
        sceneGraph.attachChild(std::move(second));

        Command c;
        c.action = derivedAction<Player>(std::bind(&Player::follow, std::placeholders::_1));
        c.category = Category::Player2;
        commandQueue.push(c);

        while (!commandQueue.isEmpty())
                sceneGraph.onCommand(commandQueue.pop());

        std::cout << sceneGraph;
}

19
General / text doesn't draw
« on: February 03, 2016, 02:23:04 am »
i tried to display some text on screen with simple triangle shape by using opengl but for some reasons that doesn't work with my code. how to fixed this

here my code:

#include <gl/glew.h>
#include <SFML/Graphics.hpp>

int main()
{
        sf::RenderWindow window(sf::VideoMode(640, 480), "OpenGL");

        window.setActive();

        glewExperimental = GL_TRUE;
        if (glewInit() != GLEW_OK)
                return 1;

        sf::Font font;
        if (!font.loadFromFile("Media/Sansation.ttf"))
                return 1;

        sf::Text text("test", font);
        text.setPosition(5.f, 5.f);

        GLuint vboID;
        glGenBuffers(1, &vboID);
        GLfloat Vertices[] =
        {
                -1, -1, 0,
                 0,  1, 0,
                 1, -1, 0,
        };

        glBindBuffer(GL_ARRAY_BUFFER, vboID);
        glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);

        glClearColor(0.f, 0.f, 0.f, 1.f);

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

                // opengl drawing
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

                glEnableVertexAttribArray(0);
                glBindBuffer(GL_ARRAY_BUFFER, vboID);
                glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);

                glDrawArrays(GL_TRIANGLES, 0, 3);

                glDisableVertexAttribArray(0);

                // sfml drawing : failed ???????????
                window.pushGLStates();
                window.draw(text);
                window.popGLStates();

                window.display();
        }
}

20
General / How to swap the transform of two objects[Solved]
« on: January 19, 2016, 01:10:58 am »
i'm facing problem with swapping transform(position, scale, rotate) of two object of same type that has transformable member data. i can do it by swapping each of them manually but i think this is noneffective. if i understood it correctly, i think this can be done by std::swap or by "=operator" which is used copy constructor of each given objects and their transform to the new object.

 here example that supposed to work but it didn't.

#include <SFML/Graphics.hpp>

class Tile : public sf::Drawable
{
public:
        Tile(const sf::Texture& texture)
                : mSprite(texture)
                , mTransform()
        {
        }
        ~Tile() = default;

        Tile(const Tile& othher)
                : mSprite(othher.mSprite)
                , mTransform(othher.mTransform)
        {
        }

        Tile& operator=(Tile other) noexcept
        {
                other.swap(*this);
                return *this;
        }

        //Tile(Tile&& other)
        //{
        //      swap(*this, other);
        //}
        //Tile& operator=(Tile&&) = default;

        void swap(Tile& other) noexcept
        {
                using std::swap;

                swap(mTransform, other.mTransform);
                swap(mSprite, other.mSprite);

        }

        friend void swap(Tile& lhs, Tile& rhs) noexcept
        {
                using std::swap;
                swap(lhs.mTransform, rhs.mTransform);
                swap(lhs.mSprite, rhs.mSprite);
        }

        void setPosition(float x, float y)
        {
                mTransform.setPosition(x, y);
        }

        void setPosition(sf::Vector2f pos)
        {
                mTransform.setPosition(pos);
        }

        sf::Vector2f getPosition() const
        {
                return mTransform.getPosition();
        }

        void draw(sf::RenderTarget& target, sf::RenderStates states) const
        {
                states.transform = mTransform.getTransform();
                target.draw(mSprite, states);
        }


private:
        sf::Sprite mSprite;
        sf::Transformable mTransform;
};

int main()
{
        sf::RenderWindow window(sf::VideoMode(480u, 480u), "Tile tut");
        window.setVerticalSyncEnabled(true);

        sf::Texture texture1, texture2;
        if (!texture1.loadFromFile("0.png"))
                return 1;

        if (!texture2.loadFromFile("1.png"))
                return 1;

        Tile tile1(texture1), tile2(texture2);

        tile1.setPosition(100.f, 120.f);
        tile2.setPosition(100.f + texture1.getSize().x, 120.f);

        bool toggle = false;

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

                        else if (event.type == sf::Event::KeyPressed)
                        {
                                if (event.key.code == sf::Keyboard::Space)
                                {
                                        toggle = !toggle;
                                }
                        }
                }

                if (toggle)
                {
                        toggle = false;

                        // normal position swap works fine:~ do same thing for rotate and scale
                        //auto pos = tile1.getPosition();
                        //tile1.setPosition(tile2.getPosition());
                        //tile2.setPosition(pos);


                        // doesn't works
                        //auto tile = tile1;
                        //tile1 = tile2;
                        //tile2 = tile;
                       
                        //tile1.swap(tile2); // doesn't works
                        //std::swap(tile1, tile2); // doesn't works
                }

                window.clear();
                window.draw(tile1);
                window.draw(tile2);
                window.display();
        }
}

how to fixed this it, did i miss something that i should take care of?

Edit
sorry it seems the problem with sf::sprite's texture not with tansform, i fixed it

21
SFML projects / Simple 15 Puzzle Game
« on: January 14, 2016, 10:27:56 pm »
i have made simple puzzle game, it is quite simple and easy, i have done it before but in win32 console. when i start learning C++,

GamePlay:
the game is simple has only one button "scramble" it does shuffle the numbers and start from beginning, and user may use arrow keys to move in the only space available in the game. i didn't add time limit. it's a bit harder by itself.

finially i'm able to complete the puzzle. here a demo of game play
http://www.youtube.com/watch?v=qArw1fOMP04

22
General / read image from string[solved]
« on: January 06, 2016, 07:13:29 pm »
hello

i was working on sf::texture to load image from memory by encoding the source image in base46 and decode it back to be able to load it in sf::texture. i have create encoder.cpp and decoder.cpp to accomplish this as shown in these files

the encoder is simply encode the given image and create .pin file as binary
here encoder.cpp :  https://gist.github.com/MORTAL2000/05f5b100166203ed3cc7

the file being created like this. sfml-logo-small.pin
content : https://gist.github.com/MORTAL2000/4206d168740a8af7b295

the decoder is convert sfml-logo-small.pin to be readable in sf::Texture.
here decoder.cpp : https://gist.github.com/MORTAL2000/af02e3ac4212924a30e7

source image is found here:


if i loaded the encoded image "sfml-logo-small.pin", which is simply a string, from file, it works fine but if i copy and paste it into std::string object in encoder.cpp to read it directly instead of read it from file, i keep getting error says corrupt PNG. how to fix this.

P.S: i have to split the std::string object into two string like this:
static const std::string data0 = "copy and paste from sfml-logo-small.pin ... very long encoded string";
static const std::string data1 = "copy and paste from sfml-logo-small.pin ... very long encoded string";
otherwise the VC14 will complain about it as string is too big

and use it like this:
std::string decoded = base64_decode({ data0 + data1 });

sf::Texture texture;
if (!texture.loadFromMemory(decoded.c_str(), decoded.length()))
{
        return 1;
}

23
SFML projects / Simple Snake Game
« on: January 01, 2016, 06:00:19 pm »
hello everybody  :)

i was working recently on this project. after the project cleaned and tested, it looks fine for now to post it for educational purpose to beginners like me ;D
i have seek help just to make  this project as good as possible to be worthy as educational. lastly i apologize that source code lacks of comments but i think it is quite easy to grasp.
Also, i have implemented smooth movements for the snake to give realistic impression instead of tile movements as most of tutorials in snake-like games do.

gameplay
gameplay is simply if snake ate itself the lives decreased and it shrinks to where it gets bitten. but if snake hit the walls the game ends and  immediately, it restarts again.

Demo:
http://www.youtube.com/watch?v=BIIvjJfFf8U

24
General / understanding sfml and opengl2d
« on: December 22, 2015, 02:19:47 am »
for sake understanding sfml and how it handles opengl internally, i have created mini-opengl program that draw simple chess board on screen. of course this can be done in sfml like this:

sf::Sprite sprite(texture);
window.draw(sprite);

as i said, the purpose of this exercise is to understand sfml and opengl as well. the same above code can be writtern in opengl like this:
#include <SFML/OpenGL.hpp>
#include <SFML/Window.hpp>
#include <vector>

int main()
{
        sf::Window window(sf::VideoMode(800, 600), "OpenGL");

        // Set the viewport
        glViewport(0, 0, window.getSize().x, window.getSize().y);

        // Initialize Projection Matrix
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();

        // Set drawing surface properties - either Perspective or Orthographic: make origin (0,0) at top-left corner of screen
        glOrtho(0.0, window.getSize().x, window.getSize().y, 0.0, -1.0, 1.0);

        // Initialize Modelview Matrix
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

        // Initialize Texture Matrix
        glMatrixMode(GL_TEXTURE);
        glPushMatrix();

        // Initialize vertices: use window coordinate for width and height
        auto width = static_cast<float>(window.getSize().x);
        auto height = static_cast<float>(window.getSize().y);

        std::vector<float> vertices =
        {
                0,     0,
                0,     height,
                width, height,
                width, 0
        };

        // Initialize colors
        std::vector<float> colors =
        {
                1, 0, 0,
                0, 1, 0,
                0, 0, 1,
                0, 1, 1
        };

        // Initialize texture virtice
        std::vector<float> texCoord =
        {
                0, 0,
                0, 1,
                1, 1,
                1, 0
        };
       
        // Create texture: simple chess board
        std::vector<unsigned char> textureData(64);
        for (auto i = 0u; i < textureData.size(); ++i)
                textureData[i] = ((i + (i / 8)) % 2) * 128 + 127;

        // Upload to GPU texture
        GLuint texture;
        glGenTextures(1, &texture);
        glBindTexture(GL_TEXTURE_2D, texture);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 8, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, textureData.data());
        glBindTexture(GL_TEXTURE_2D, 0);

        // Initialize clear colors
        glClearColor(0.f, 0.f, 0.f, 1.f);

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

                // render
                glClear(GL_COLOR_BUFFER_BIT);

                glMatrixMode(GL_MODELVIEW);

                glBindTexture(GL_TEXTURE_2D, texture);
                glEnable(GL_TEXTURE_2D);
                glEnableClientState(GL_VERTEX_ARRAY);
                glEnableClientState(GL_COLOR_ARRAY);
                glEnableClientState(GL_TEXTURE_COORD_ARRAY);
       
                glVertexPointer(2, GL_FLOAT, 0, vertices.data());
                glColorPointer(3, GL_FLOAT, 0, colors.data());
                glTexCoordPointer(2, GL_FLOAT, 0, texCoord.data());

                glDrawArrays(GL_QUADS, 0, 4);

                glDisable(GL_TEXTURE_2D);
                glBindTexture(GL_TEXTURE_2D, 0);
                glDisableClientState(GL_TEXTURE_COORD_ARRAY);
                glDisableClientState(GL_VERTEX_ARRAY);
                glDisableClientState(GL_COLOR_ARRAY);

                window.display();
        }
}

i have two questions regarding this matter:

  • how sfml manged the coordinate system since it doesn't use either Perspective or Orthographic
  • i would like to get code review for my implementation

25
SFML projects / Car Racing For Beginners : Finished
« on: November 30, 2015, 01:09:40 pm »
i was reading about pseudo-3d racing game. the tutorial is here in this link below it's short and easy for read especially for beginner but unfortunately, it is for javascript language, the challenge is how to  make it in C++/SFML. Humbly i have done my first attempt in make this game.

Demo:

http://www.youtube.com/watch?v=c5ixex8Ty08

the tutorial: http://codeincomplete.com/posts/2012/6/22/javascript_racer/.

26
General / problem wih Pseudo 3D for car-racing[SOLVED]
« on: November 24, 2015, 05:11:23 pm »
hello

i have made small car-racing game by implementing Pseudo 3D based on tutorial in here http://codeincomplete.com/posts/2012/6/24/javascript_racer_v2_curves/.
the code runs fine but when i implemented the curves the car always stuck in middle. how can i fix this?

i want car drafts to opposite direction of curve's direction to give realistic view of this kind of games. in the tutorial, it suggests to use "easeIn()" and "easeInOut()" and adjust the player position like this
playerX = playerX - (dx * speedPercent * playerSegment.curve * centrifugal);

but those don't work correctly in my code. beside the tutorial doesn't explain the curves very well, it seems the author missed vital details in this section.

27
SFML projects / Space Invaders Clone - Game finished
« on: August 20, 2015, 11:23:36 pm »
Game finished

hello everybody i just finished reading the SFML Development Book. it really a great book many thanks to all authors. i have made a simple space invaders based on what i have learned from the Book.

here a new video with latest update where the player can spawn
https://youtu.be/0iaJHnNpWKo


source code is available hère:
https://github.com/MORTAL2000/Space-Invaders-Clone

NOTE: it tested on VS 2015.

28
General / My First openGL Program by using SFML
« on: August 03, 2015, 03:27:43 pm »
hello
i'm recently learning opengl and shader language and SFML. i have create my first GLSL program that draw colored rectangle on screen.

i'm looking for best practice in both SFML and openGL in this code

#include <GL/glew.h>
#include <SFML/Window.hpp>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <stdexcept>
#include <cassert>

#define GLSL(src) "#version 400 core\n" #src
#define GETERROR() getError(__FILE__,__LINE__)

namespace
{
        const unsigned CurrentWidth = 800;
        const unsigned CurrentHeight = 600;
}

void getError(const char *file, int line)
{
        GLenum error(glGetError());

        while (error != GL_NO_ERROR)
        {
                std::string errorString;

                switch (error)
                {
                case GL_INVALID_OPERATION:      errorString = "INVALID_OPERATION";      break;
                case GL_INVALID_ENUM:           errorString = "INVALID_ENUM";           break;
                case GL_INVALID_VALUE:          errorString = "INVALID_VALUE";          break;
                case GL_OUT_OF_MEMORY:          errorString = "OUT_OF_MEMORY";          break;
                case GL_INVALID_FRAMEBUFFER_OPERATION:  errorString = "INVALID_FRAMEBUFFER_OPERATION";  break;
                }

                throw std::runtime_error("GL_" + errorString + " - " + std::string(file) + ":" + std::to_string(line));
                error = glGetError();
        }
}

class Tutorial
{
public:
        Tutorial();
        ~Tutorial();
        void run();


private:
        void processEvent();
        void render();

        void createVBO();
        void destroyVBO();
        void createShaders();
        void destroyShaders();


private:
        sf::Window mWindow;

        GLuint mVertexShaderID;
        GLuint mFragmentShaderID;
        GLuint mProgramID;
        GLuint mVAOID;
        GLuint mVBOID;
        GLuint mColorBufferID;

        const std::vector<GLchar*> mVertexShader =
        {
                {
                        GLSL(
                                layout(location = 0) in vec4 in_Position;
                                layout(location = 1) in vec4 in_Color;

                                out vec4 ex_Color;

                                void main(void)
                                {
                                        gl_Position = in_Position;
                                        ex_Color = in_Color;
                                }
                        )
                }
        };
        const std::vector<GLchar*> mFragmentShader =
        {
                {
                        GLSL(
                                in vec4 ex_Color;
                                out vec4 out_Color;

                                void main(void)
                                {
                                        out_Color = ex_Color;
                                }
                        )
                }
        };

};

Tutorial::Tutorial()
        : mWindow(sf::VideoMode(CurrentWidth, CurrentHeight), "Example 00")
{
        glewExperimental = true; // Needed in core profile

        if (glewInit() != GLEW_OK)
        {
                throw std::runtime_error("Failed to initialize GLEW\n");
        }

        glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

        createShaders();
        createVBO();
}

void Tutorial::run()
{
        while (mWindow.isOpen())
        {
                processEvent();
                render();
        }
}

void Tutorial::processEvent()
{
        sf::Event event;
        while (mWindow.pollEvent(event))
        {
                if (event.type == sf::Event::Closed)
                        mWindow.close();
                if (event.type == sf::Event::Resized)
                        glViewport(0, 0, mWindow.getSize().x, mWindow.getSize().y);
        }
}
void Tutorial::render()
{
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glDrawArrays(GL_TRIANGLES, 0, 3);
        mWindow.display();
}

Tutorial::~Tutorial()
{
        destroyShaders();
        destroyVBO();
}

void Tutorial::createVBO()
{
        GLfloat Vertices[] =
        {
                -0.8f, -0.8f, 0.0f, 1.0f,
                 0.0f,  0.8f, 0.0f, 1.0f,
                 0.8f, -0.8f, 0.0f, 1.0f
        };

        GLfloat Colors[] =
        {
                1.0f, 0.0f, 0.0f, 1.0f,
                0.0f, 1.0f, 0.0f, 1.0f,
                0.0f, 0.0f, 1.0f, 1.0f
        };

        glGenVertexArrays(1, &mVAOID);
        glBindVertexArray(mVAOID);

        glGenBuffers(1, &mVBOID);
        glBindBuffer(GL_ARRAY_BUFFER, mVBOID);
        glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);
        glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
        glEnableVertexAttribArray(0);

        glGenBuffers(1, &mColorBufferID);
        glBindBuffer(GL_ARRAY_BUFFER, mColorBufferID);
        glBufferData(GL_ARRAY_BUFFER, sizeof(Colors), Colors, GL_STATIC_DRAW);
        glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, 0);
        glEnableVertexAttribArray(1);

        GETERROR();
}

void Tutorial::destroyVBO()
{
        glDisableVertexAttribArray(1);
        glDisableVertexAttribArray(0);

        glBindBuffer(GL_ARRAY_BUFFER, 0);
        glDeleteBuffers(1, &mColorBufferID);
        glDeleteBuffers(1, &mVBOID);

        glBindVertexArray(0);
        glDeleteVertexArrays(1, &mVAOID);

        GETERROR();
}

void Tutorial::createShaders()
{
        mVertexShaderID = glCreateShader(GL_VERTEX_SHADER);
        glShaderSource(mVertexShaderID, 1, &mVertexShader[0], NULL);
        glCompileShader(mVertexShaderID);

        mFragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
        glShaderSource(mFragmentShaderID, 1, &mFragmentShader[0], NULL);
        glCompileShader(mFragmentShaderID);

        mProgramID = glCreateProgram();
        glAttachShader(mProgramID, mVertexShaderID);
        glAttachShader(mProgramID, mFragmentShaderID);
        glLinkProgram(mProgramID);
        glUseProgram(mProgramID);

        GETERROR();
}

void Tutorial::destroyShaders()
{
        glUseProgram(0);

        glDetachShader(mProgramID, mVertexShaderID);
        glDetachShader(mProgramID, mFragmentShaderID);

        glDeleteShader(mFragmentShaderID);
        glDeleteShader(mVertexShaderID);

        glDeleteProgram(mProgramID);

        GETERROR();
}

int main()
{
        try
        {
                Tutorial tut;
                tut.run();
        }
        catch (std::runtime_error& e)
        {
                std::cout << "\nException: " << e.what() << std::endl;
                return 1;
        }
}

29
General / help with aurora library
« on: July 31, 2015, 06:40:30 pm »
i tried to use aurora lib just to understand it. however when i compiled the example in its official site i got errors. i don't know why this happened.

the code in official site:
#include <Aurora/Dispatch.hpp>
#include <iostream>

struct Object { virtual ~Object() {} };
struct Asteroid : Object {};
struct Ship : Object {};

void collisionAA(Asteroid*, Asteroid*) { std::cout << "Asteroid-Asteroid\n"; }
void collisionAS(Asteroid*, Ship*)     { std::cout << "Asteroid-Ship\n"; }
void collisionSS(Ship*, Ship*)     { std::cout << "Ship-Ship\n"; }


int main()
{
        // Register "overloaded" functions
        using aurora::Type;
        aurora::DoubleDispatcher<Object*> disp;
        disp.bind(Type<Asteroid>(), Type<Asteroid>(), &collisionAA);
        disp.bind(Type<Asteroid>(), Type<Ship>(), &collisionAS);
        disp.bind(Type<Ship>(), Type<Ship>(), &collisionSS);

        // Call function, given only base class pointers
        Asteroid a;  
        Object* pa = &a;
        Ship s;      
        Object* ps = &s;
        disp.call(pa, ps); // Output: Asteroid-Ship
        std::cin.ignore();
}

errors appear like this:
1>------ Build started: Project: junk_input, Configuration: Debug Win32 ------
1>  Source1.cpp
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\aurora\meta\templates.hpp(141): error C2027: use of undefined type 'aurora::detail::FunctionSignature<Signature>'
1>          with
1>          [
1>              Signature=Object *
1>          ]
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\aurora\dispatch\doubledispatcher.hpp(126) : see reference to class template instantiation 'aurora::FunctionResult<Signature>' being compiled
1>          with
1>          [
1>              Signature=Object *
1>          ]
1>          c:\users\mohammed\documents\sfml-working\junk_input\junk_input\source1.cpp(17) : see reference to class template instantiation 'aurora::DoubleDispatcher<Object *,aurora::RttiDispatchTraits<Signature,2>>' being compiled
1>          with
1>          [
1>              Signature=Object *
1>          ]
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\aurora\meta\templates.hpp(141): error C2146: syntax error : missing ';' before identifier 'Type'
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\aurora\meta\templates.hpp(141): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\aurora\meta\templates.hpp(141): error C2208: 'aurora::Type' : no members defined using this type
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\aurora\meta\templates.hpp(141): fatal error C1903: unable to recover from previous error(s); stopping compilation
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

i'm using VS 2013. how to solve those errors?

30
General discussions / SFML Game Development - Chapter - 4
« on: July 31, 2015, 02:32:15 pm »
first i want thanks everybody who contributed in the book, however, i'm reading chapter 4, i found  in std::fonctional expression in Command class
std::function<void(SceneNode&, sf::Time)>       action;
and functor in AircraftMover class
void operator() (Aircraft& aircraft, sf::Time) const
{
        aircraft.accelerate(velocity);
}
take two arguments. the second argument is sf::Time type which is never computed throughout all classes. My question why is it there while it never be considered?

Pages: 1 [2] 3