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

Pages: [1]
1
Graphics / sf::Text is giving me an Access Violation read location error
« on: September 10, 2015, 08:56:11 am »
I'm using Visual Studio Express 2013 on Windows 8 , and using SFML 2.1 from here

When ever I try to draw a text (which the font is loaded properly) it gives me this
Quote
   sfml-graphics-d-2.dll!0f76dce2()   Unknown
    [Frames below may be incorrect and/or missing, no symbols loaded for sfml-graphics-d-2.dll]   
    sfml-graphics-d-2.dll!0f772d9e()   Unknown
    sfml-graphics-d-2.dll!0f769bc1()   Unknown
    sfml-graphics-d-2.dll!0f75c7dd()   Unknown
    sfml-graphics-d-2.dll!0f7b29ba()   Unknown
    sfml-graphics-d-2.dll!0f78e583()   Unknown
>   SpellswordEditor.exe!Button::draw(sf::RenderTarget & target, sf::RenderStates states) Line 34   C++
    sfml-graphics-d-2.dll!0f78e583()   Unknown
    SpellswordEditor.exe!UserInterface::update() Line 71   C++
    SpellswordEditor.exe!main() Line 63   C++
    [External Code]   

Here is the code

Button.h
#ifndef BUTTON_H
#define BUTTON_H

#include <SFML/Graphics.hpp>
#include <iostream>

class Button : public sf::Drawable, public sf::Transformable
{
public:
        Button();
        Button(sf::Vector2f s, sf::Vector2f p, const char* f, const char* displayText = "Button", sf::Color tc = sf::Color::Black);
        ~Button();
        bool isClicked();
        void setPosition(sf::Vector2f p);
        void setSize(sf::Vector2f s);
        void setColor(sf::Color c);
        void update(sf::Event& e, sf::RenderWindow& window);
private:
        virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
        {
                // apply the transform
                states.transform *= getTransform();

               
                switch (state)
                {
                case State::normal:
                        target.draw(normalStyle);
                case State::inactive:
                        target.draw(clickStyle);
                default:
                        target.draw(normalStyle);
                }
                target.draw(text);
        };

        enum State{
                normal = 0,
                hover = 1,
                clicked = 2,
                inactive = 3,
        };

        void checkMouseInButton();

        State state;
        bool isActive;
        bool mouseInButton;
        sf::Vector2f position;
        sf::Vector2i mousePosition;
        sf::Vector2f size;
        sf::RectangleShape normalStyle;
        sf::RectangleShape hoverStyle;
        sf::RectangleShape clickStyle;
        sf::Color textColor;

        sf::Font font;
        sf::Text text;

};

#endif BUTTON_H
 

Button.cpp
#include "Button.h"


Button::Button()
{
}

Button::Button(sf::Vector2f s, sf::Vector2f p, const char* f, const char* displayText, sf::Color tc) : textColor(tc), size(s), position(p)
{
        if (font.loadFromFile(f))
        {
                isActive = true;
                text.setFont(font);
                text.setString(displayText);
                text.setCharacterSize(size.x);
                text.setColor(sf::Color::Black);
                text.setPosition(position);
                setPosition(position);
                setSize(size);
                setColor(sf::Color::Blue);
        }
}

void Button::setPosition(sf::Vector2f p)
{
        normalStyle.setPosition(p);
        hoverStyle.setPosition(p);
        clickStyle.setPosition(p);
}

void Button::setSize(sf::Vector2f s)
{
        normalStyle.setSize(s);
        hoverStyle.setSize(s);
        clickStyle.setSize(s);
}

void Button::setColor(sf::Color c)
{
        normalStyle.setFillColor(c);
        hoverStyle.setFillColor(c);
        clickStyle.setFillColor(c);
}

bool Button::isClicked()
{
        if (state == State::clicked)
                return true;
        return false;
}      

void Button::checkMouseInButton()
{
        mouseInButton = mousePosition.x <= position.x + size.x
                && mousePosition.x >= position.x
                && mousePosition.y <= position.y + size.y
                && mousePosition.y >= position.y;
}

void Button::update(sf::Event& e, sf::RenderWindow& window)
{
        if (isActive)
        {
                mousePosition = sf::Mouse::getPosition(window);
                checkMouseInButton();
                if (mouseInButton)
                {
                        state = State::hover;
                }
        }
        else{
                state = State::normal;
        }


}

Button::~Button()
{
}
 

UserInterface.cpp

#include "UserInterface.h"
#include <iostream>


UserInterface::UserInterface(sf::Event& e, float window_w, float window_h, sf::RenderWindow &w) : window(w), window_width(window_w), window_height(window_h), event(e)
{
        createToolbar();
        createMapView();
        createPropMenu();
        button = Button(sf::Vector2f(100.0f, 75.0f), sf::Vector2f(0.0f, 0.0f), "Fonts/MontereyFLF.ttf");
}


UserInterface::~UserInterface()
{
}

void UserInterface::createToolbar()
{
        toolbarView.setSize(window_width, window_height * 0.05f);
        toolbarView.setCenter(window_width / 2, (window_height * 0.05f) / 2);
        toolbarView.setViewport(sf::FloatRect(0, 0, 1.0f, 0.05f));

        toolbarBackground.setSize(sf::Vector2f(toolbarView.getSize().x, toolbarView.getSize().y));
        toolbarBackground.setFillColor(sf::Color(100, 100, 100, 255));
        toolbarBackground.setOutlineThickness(-3);
        toolbarBackground.setOutlineColor(sf::Color(150, 150, 150, 255));
}

void UserInterface::createMapView()
{
        mapView.setSize(window_width * 0.8f, window_height * 0.95f);
        mapView.setCenter(window_width/2, (window_height * 0.95f)/2);
        mapView.setViewport(sf::FloatRect(0, 0.05f, 0.8f, 0.95f));
}

void UserInterface::createPropMenu()
{
        propMenuView.setSize(window_width * 0.2f, window_height * 0.95f);
        propMenuView.setCenter((window_width * 0.2f) / 2, (window_height * 0.95f) / 2);
        propMenuView.setViewport(sf::FloatRect(0.8f, 0.05f, 0.2f, 0.95f));

        propMenuBackground.setSize(sf::Vector2f(propMenuView.getSize().x, propMenuView.getSize().y));
        propMenuBackground.setFillColor(sf::Color(100, 100, 100, 255));
        propMenuBackground.setOutlineThickness(-3);
        propMenuBackground.setOutlineColor(sf::Color(150, 150, 150, 255));
}

void UserInterface::moveMapView(float amountX, float amountY)
{
        mapView.move(sf::Vector2f(amountX, amountY));
        window.setView(mapView);
}

sf::Vector2f UserInterface::getMapCenter()
{
        return mapView.getCenter();
}

sf::Vector2f UserInterface::getMouseToWorldCords()
{
        return window.mapPixelToCoords(sf::Mouse::getPosition(window),window.getView());
}

void UserInterface::update()
{
        window.setView(toolbarView);
        window.draw(toolbarBackground);

        button.update(event, window);
        window.draw(button);

        window.setView(propMenuView);
        window.draw(propMenuBackground);
        window.setView(mapView);
};
 

2
General / Re: Reference to render window not working.
« on: September 07, 2015, 08:50:53 am »
Durp, I forgot to center the view.  :-X

3
General / Reference to render window not working.
« on: September 07, 2015, 06:30:17 am »
So, after just laying out a bunch of code to test things out I decided to organize some things into a class. I created a class to manage the creation and drawing of the interface (at this stage just a tool bar). I pass a reference of my RenderWindow to that class so it can handle the creation and drawing of the interface all in one place, then I just call userInterface.draw() However, the view or the RectangleShape I setup seem not to be working with the reference of RenderWindow I passed, at least, I'm assuming that's why it's not displaying anything from UserInterface class when I try to call it's draw() function. Why is my UserInterface::draw() function not actually drawing anything to the RenderWindow or displaying the view I made?

UserInterface.h
#include <SFML/Graphics.hpp>

class UserInterface
{

public:
        UserInterface(float window_w, float window_h, sf::RenderWindow &w);
        ~UserInterface();
        void draw();

private:
        void createToolbar();
        sf::View toolbarView;
        sf::RectangleShape toolbarBackground;
        float window_width;
        float window_height;
        sf::RenderWindow& window;
};

UserInterface.cpp
#include "UserInterface.h"


UserInterface::UserInterface(float window_w, float window_h, sf::RenderWindow &w) : window(w), window_width(window_w), window_height(window_h)
{
        createToolbar();
}


UserInterface::~UserInterface()
{
}

void UserInterface::createToolbar()
{
        toolbarView.setSize(window_width, window_height / 10);
        toolbarView.setViewport(sf::FloatRect(0, 0, 1.0f, 0.05f));

        toolbarBackground.setSize(sf::Vector2f(window_width, window_height / 10));
        toolbarBackground.setFillColor(sf::Color(100, 100, 100, 255));
        toolbarBackground.setOutlineThickness(-3);
        toolbarBackground.setOutlineColor(sf::Color(150, 150, 150, 255));
}

void UserInterface::draw()
{
        window.setView(toolbarView);
        window.draw(toolbarBackground);
};
 

main.cpp
#ifdef SFML_STATIC
#pragma comment(lib, "glew.lib")
#pragma comment(lib, "freetype.lib")
#pragma comment(lib, "jpeg.lib")
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "gdi32.lib")  
#endif // SFML_STATIC

#define WINDOW_WIDTH 1024
#define WINDOW_HEIGHT 512
#define TILE_SIZE 32

#include <iostream>
#include <SFML/Graphics.hpp>
#include "Tilemap.h"
#include "UserInterface.h"




int main()
{
        sf::Vector2i levelSize;

        sf::RenderWindow window(sf::VideoMode(1280, 720, 32), "Spellsword Map Editor");

        sf::View mapView(sf::FloatRect(0,0,WINDOW_WIDTH, WINDOW_HEIGHT));
        mapView.setViewport(sf::FloatRect(0,0.05f,1.0f,0.95f));

        UserInterface userInterface(WINDOW_WIDTH, WINDOW_HEIGHT, window);
        const int level[] =
        {//I removed all this for sake of space in my post

        };
        levelSize.x = (sizeof(level)/sizeof(*level))/TILE_SIZE;
        levelSize.y = (sizeof(level)/sizeof(*level))/TILE_SIZE;
        Tilemap map;
        if (!map.load("Textures/tilemap.png", sf::Vector2u(TILE_SIZE, TILE_SIZE), level, levelSize.x, levelSize.y))
                return -1;

        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::KeyPressed)
                        {
                                if (event.key.code == sf::Keyboard::Down)
                                {
                                        mapView.move(0, 32);
                                        window.setView(mapView);
                                }
                                if (event.key.code == sf::Keyboard::Up)
                                {
                                        mapView.move(0, -32);
                                        window.setView(mapView);
                                }
                                if (event.key.code == sf::Keyboard::Left)
                                {
                                        mapView.move(-32, 0);
                                        window.setView(mapView);
                                }
                                if (event.key.code == sf::Keyboard::Right)
                                {
                                        mapView.move(32, 0);
                                        window.setView(mapView);
                                }
                        }
                        if (event.type == sf::Event::Closed)
                                window.close();
                }

                window.clear();

                window.setView(mapView);
                window.draw(map);

                userInterface.draw();

                window.display();
        }

        return 0;
}

Pages: [1]
anything