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

Pages: [1]
1
General / Re: Custom App Engine with SFML & ImGUI Not Drawing
« on: February 28, 2019, 01:14:49 am »
ok, here is the screen class:

Quote
class Screen {
       
    private:
       
       
       
    public:
       
        //name
        std::string SCREEN_NAME;
       
        //functions
        virtual void Load() = 0;
        virtual void Update(const float dt) = 0;
        virtual void HandleInput(sf::Event event) = 0;
        virtual void Draw(sf::RenderWindow& window, const float dt) = 0;
       
        Screen(ScreenManager& screenManager);
       
    };

And i get the following error:
Quote
Unknown type name 'ScreenManager'

Why does it not recognize this even though I have included "ScreenManager.hpp"?

2
General / Re: Custom App Engine with SFML & ImGUI Not Drawing
« on: February 28, 2019, 12:32:29 am »
Ok, how would I do that? I am still relatively new to C++, so Im not exactly sure what you mean.

3
General / Re: Custom App Engine with SFML & ImGUI Not Drawing
« on: February 27, 2019, 11:36:10 pm »
Thank you! That worked great!

Just a quick question, I made a TextureManager class to handle all the textures. Is there a way I can define a TextureManager in main and access it in other screen files?

4
General / Custom App Engine with SFML & ImGUI Not Drawing
« on: February 27, 2019, 07:18:17 pm »
Hello!

I am building an engine relying on SFML for graphics/text and ImGUI for simple GUI. I have been approaching my engine in a similar way to my 2D Java engine works, as well as grabbing some tools from another tutorial online.

Essentially, there are "screens" which are different states of the game (Menu, GamePlay, etc). The main function houses the default SFML code and a screenManager, which handles all of the drawing and updating for each screen. The program runs fine, except that it does not draw any of the sprites. I get no errors for loading the files, but nothing draws. I assume my approach to drawing is not correct, so included below is the code for the necessary files.

** all ImGUI code is commented out as I am not focused on getting that to work right now **

In the ScreenSplash (a splash screen), i tried to render the sprite, and nothing happens, just a big empty background.

In main.cpp, i made a sf::Sprite test to see if that would draw normally, and it does not. A big white rectangle appears that is the size of the image, so something to do with rendering is not right.

main.cpp:
Quote


#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/System/Clock.hpp>
#include <SFML/Window/Event.hpp>

#include "AppConstants.hpp"
#include "imgui.h"
#include "imgui-SFML.h"
#include "ScreenManager.hpp"
#include "ScreenSplash.hpp"

//screen manager
WRT::ScreenManager screenManager;

int main() {

    sf::RenderWindow window(sf::VideoMode(WINDOW_DIMENSIONS.x, WINDOW_DIMENSIONS.y), WINDOW_TITLE);
    window.setVerticalSyncEnabled(true);
    window.setFramerateLimit(60);
    //ImGui::SFML::Init(window);
   
    // let's use char array as buffer, see next part
    // for instructions on using std::string with ImGui

    //window.resetGLStates(); // call it if you only draw ImGui. Otherwise not needed.
   
    //start the screen manager
    screenManager.PushScreen(new ScreenSplash());
   
    //test sprite
    sf::Sprite test = LoadSprite("splash.png");
   
   
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    //main game loop
    sf::Clock clock;
   
    while (window.isOpen()) {
       
        sf::Time elapsed = clock.restart();
        float dt = elapsed.asSeconds();
       
        sf::Event event;
       
        while (window.pollEvent(event)) {
           
            if(screenManager.PeekScreen() == nullptr) continue;
            screenManager.PeekScreen()->HandleInput(event);
           
            //ImGui::SFML::ProcessEvent(event);
           
            if (event.type == sf::Event::Closed) {
               
                while(!screenManager.screens.empty()) screenManager.PopScreen();
                window.close();
               
            }
           
        }
       
        //update all the game data
        //ImGui::SFML::Update(window, clock.restart());
       
        //update the current screen
        if(screenManager.PeekScreen() == nullptr) continue;
        screenManager.PeekScreen()->Update(dt);
 
       
       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //ImGui::Begin("Sample window"); // begin window
       
        // Window title text edit
        //ImGui::InputText("Window title", windowTitle, 500);
        /*
        if (ImGui::Button("Update window title")) {
            // this code gets if user clicks on the button
            // yes, you could have written if(ImGui::InputText(...))
            // but I do this to show how buttons work :)
            window.setTitle(windowTitle);
           
        }
         */
       
        //ImGui::End(); // end window
        window.clear(GREY_BK_COLOR); // fill background with color
        //ImGui::SFML::Render(window);
        screenManager.PeekScreen()->Draw(window, dt);
        window.draw(test);
        window.display();
       
    }
   
    //ImGui::SFML::Shutdown();
   
    return 0;
   
}


The LoadSprite function:
Quote
sf::Sprite LoadSprite(std::string filename) {
   
    std::string filePath = ResourcePath() + filename;
    sf::Texture tex;
    sf::Sprite sprite;
   
    tex.loadFromFile(filePath);
   
    sprite.setTexture(tex);
   
    return sprite;
   
}

Screen.hpp:
Quote
namespace WRT {
   
    class Screen {
       
    private:
       
       
       
    public:
       
        std::string SCREEN_NAME;
       
        virtual void Load() = 0;
        virtual void Update(const float dt) = 0;
        virtual void HandleInput(sf::Event event) = 0;
        virtual void Draw(sf::RenderWindow& window, const float dt) = 0;
       
    };
   
}

ScreenManager.cpp:
Quote
#include "ScreenManager.hpp"


WRT::ScreenManager::ScreenManager() {
   
   
   
}

WRT::ScreenManager::~ScreenManager() {
   
    while(!this->screens.empty()) PopScreen();
   
}

void WRT::ScreenManager::PushScreen(Screen* screen) {
   
    this->screens.push(screen);
   
    return;
}

void WRT::ScreenManager::PopScreen() {
   
    delete this->screens.top();
    this->screens.pop();
   
    return;
}

void WRT::ScreenManager::ChangeScreen(Screen* screen) {
   
    if(!this->screens.empty())
        PopScreen();
    PushScreen(screen);
   
    return;
}

WRT::Screen* WRT::ScreenManager::PeekScreen() {
   
    if(this->screens.empty()) return nullptr;
    return this->screens.top();
}


and ScreenSplash.cpp:
Quote
#include <SFML/Window/Event.hpp>
#include <iostream>

#include "ScreenSplash.hpp"
#include "ResourcePath.hpp"
#include "AppConstants.hpp"


void ScreenSplash::Load() {
   
    //set up the view
    sf::Vector2f pos = sf::Vector2f(WINDOW_DIMENSIONS);
    this->view.setSize(pos);
    pos *= 0.5f;
    this->view.setCenter(pos);
   
    splash = LoadSprite("splash.png");
   
}

void ScreenSplash::Update(const float dt) {
   
   
   
}

void ScreenSplash::HandleInput(sf::Event event) {
   
   
   
}

void ScreenSplash::Draw(sf::RenderWindow& window, const float dt) {
   
    //prep the view to draw
    window.setView(view);
    window.clear(GREY_BK_COLOR);
   
    //draw
    splash.setScale(float(sf::VideoMode::getDesktopMode().width) / float(splash.getTexture()->getSize().x), float(sf::VideoMode::getDesktopMode().height) / float(splash.getTexture()->getSize().y));
    window.draw(splash);
   
   
}

ScreenSplash::ScreenSplash() {
   
    Load();
   
}

So, sorry it's a lot of code, I'm just not sure where the error lies, and you kinda need all of it to be able to find the error. Thank you so much for your help!


5
General / Re: Errors in C++ with Abstract Class and SFML
« on: February 22, 2019, 07:23:53 pm »
Ok, so to understand, because it is "overriding" the draw function of drawable, it has to be lowercase to match that function?

also, i changed it and built it and it worked, but now the compiler gets this error:

Quote
/clang:-1: linker command failed with exit code 1 (use -v to see invocation)

is that related to the recent change I made?

Edit: Here is more info from the error:

Quote
ld: warning: directory not found for option '-L/usr/local/lib/'
Undefined symbols for architecture x86_64:
  "tileTypeToStr(TileType)", referenced from:
      GameStateEditor::Update(float) in GameStateEditor.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Thanks!

EDIT:

I fixed it, i looked more closely at the log and found the source of the problem!

6
General / Re: Errors in C++ with Abstract Class and SFML
« on: February 22, 2019, 06:51:45 pm »
Ok, so if i understand you correctly, I need to have the draw() function be somewhere? I have the following in the GUI.cpp

Quote
void GUI::Draw(sf::RenderTarget& target, sf::RenderStates states) const {

    if(!visible) return;

    /* Draw each entry of the menu */
    for(auto entry : this->entries) {
   
        /* Draw the entry */
        target.draw(entry.shape);
        target.draw(entry.text);
    }

    return;
}

is that what you mean by implement?

7
General / Errors in C++ with Abstract Class and SFML
« on: February 22, 2019, 06:06:46 pm »
So I have been working with a tutorial using Xcode, C++, and SFML (Link to Tutorial Website)

I built the code and it worked perfectly. Then, I went through and changed the names of a few of the classes (from lower case to upper case). I went through and built everything to make sure i had changed everything i needed to and i did. Then, when i built and ran the program, i got the follow two errors:

Quote
Field type 'GUI' is an abstract class
and
Quote
Allocating an object of abstract class type 'GUI'

I know that an abstract class contains a "virtual" function, which GUI does, but why would the error be caused if i havent touched the function at all? I guess I just dont really understand what is causing the error, nor do i know how to fix it.

Here is the code for the GUI class:

Quote
class GUI : public sf::Transformable, public sf::Drawable {

private:

/* If true the menu entries will be horizontally, not vertically, adjacent */
bool horizontal;

GUIStyle style;

sf::Vector2f dimensions;

int padding;

public:

std::vector<GUIEntry> entries;

bool visible;

/* Constructor */
GUI(sf::Vector2f dimensions, int padding, bool horizontal, GUIStyle& style, std::vector<std::pair<std::string, std::string>> entries) {

    visible = false;
    this->horizontal = horizontal;
    this->style = style;
    this->dimensions = dimensions;
    this->padding = padding;

    /* Construct the background shape */
    sf::RectangleShape shape;
    shape.setSize(dimensions);
    shape.setFillColor(style.bodyCol);
    shape.setOutlineThickness(-style.borderSize);
    shape.setOutlineColor(style.borderCol);

    /* Construct each gui entry */
    for(auto entry : entries) {

        /* Construct the text */
        sf::Text text;
        text.setString(entry.first);
        text.setFont(*style.font);
        text.setFillColor(style.textCol);
        text.setCharacterSize(dimensions.y-style.borderSize-padding);

        this->entries.push_back(GUIEntry(entry.second, shape, text));

    }

}

sf::Vector2f GetSize();

/* Return the entry that the mouse is hovering over. Returns
 * -1 if the mouse if outside of the Gui */
int GetEntry(const sf::Vector2f mousePos);

/* Change the text of an entry */
void SetEntryText(int entry, std::string text);

/* Change the entry dimensions */
void SetDimensions(sf::Vector2f dimensions);

/* Draw the menu */
virtual void Draw(sf::RenderTarget& target, sf::RenderStates states) const;

void Show();

void Hide();

/* Highlights an entry of the menu */
void Highlight(const int entry);

/* Return the message bound to the entry */
std::string Activate(const int entry);
std::string Activate(const sf::Vector2f mousePos);

};


And here is the line where the error is (the underlined GUI is where the error is):
Quote
this->guiSystem.emplace("rightClickMenu", GUI(sf::Vector2f(196, 16), 2, false, this->game->stylesheets.at("button"),
    {
        std::make_pair("Flatten $"          + this->game->tileAtlas["grass"].GetCost(), "grass"),
        std::make_pair("Forest $"           + this->game->tileAtlas["forest"].GetCost(), "forest" ),
        std::make_pair("Residential Zone $" + this->game->tileAtlas["residential"].GetCost(), "residential"),
        std::make_pair("Commercial Zone $"  + this->game->tileAtlas["commercial"].GetCost(), "commercial"),
        std::make_pair("Industrial Zone $"  + this->game->tileAtlas["industrial"].GetCost(), "industrial"),
        std::make_pair("Road $"             + this->game->tileAtlas["road"].GetCost(), "road")
    }));

Anyways, the question I have is what is causing this error and how do I fix it?

Thank you!

8
General / Using SFML in NetBeans on Mac
« on: July 17, 2018, 07:51:19 pm »
Hello!

I am a macOS user and use NetBeans as my preferred IDE. I have one or two tutorials on how to install SFML in NetBeans, but none have worked. Does anyone know how to get SFML to work in NetBeans on macOS?

Thanks!

9
Hello all,

I am on a Mac and keep getting the following error after following the directions in the above guide:

dyld: Library not loaded: @rpath/libsfml-graphics.2.5.dylib
  Referenced from: /Users/willbur/Desktop/School/CompSci142/SFML-Demo/Debug/SFML-Demo
  Reason: image not found
Abort trap: 6

Does anyone know how to fix this? The codelite version is the 2.5 MacOS Clang. Thanks!

Pages: [1]
anything