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

Pages: [1]
1
General / SFML 2.0 and CEGUI 7.7 issue
« on: November 11, 2012, 05:18:54 pm »
I'm having trouble implementing CEGUI into my SFML game. I did some testing and found out that it's to do with drawing a sprite.

Here's what the basic Hello World CEGUI tutorial window looks like for me when I also try to draw a sprite:



And this is what it looks like with the sprite draw call commented out:



Here's the code:

#include <CEGUI.h>
#include <RendererModules\OpenGL\CEGUIOpenGLRenderer.h>
#include <SFML\Graphics.hpp>
#include <SFML\System.hpp>
using namespace CEGUI;

int main(int /*argc*/, char* /*argv*/[])
{
        sf::RenderWindow window(sf::VideoMode(1280, 720), "SFML works!");
        sf::CircleShape shape(100.f);
        shape.setFillColor(sf::Color::Green);

        CEGUI::OpenGLRenderer& myRenderer = CEGUI::OpenGLRenderer::create();
        CEGUI::System::create( myRenderer );

        // initialise the required dirs for the DefaultResourceProvider
        CEGUI::DefaultResourceProvider* rp = static_cast<CEGUI::DefaultResourceProvider*>
                (CEGUI::System::getSingleton().getResourceProvider());
        rp->setResourceGroupDirectory("schemes", "datafiles/schemes/");
        rp->setResourceGroupDirectory("imagesets", "datafiles/imagesets/");
        rp->setResourceGroupDirectory("fonts", "datafiles/fonts/");
        rp->setResourceGroupDirectory("layouts", "datafiles/layouts/");
        rp->setResourceGroupDirectory("looknfeels", "datafiles/looknfeel/");
        rp->setResourceGroupDirectory("lua_scripts", "datafiles/lua_scripts/");
        // This is only really needed if you are using Xerces and need to
        // specify the schemas location
        rp->setResourceGroupDirectory("schemas", "datafiles/xml_schemas/");

        // set the default resource groups to be used
        CEGUI::Imageset::setDefaultResourceGroup("imagesets");
        CEGUI::Font::setDefaultResourceGroup("fonts");
        CEGUI::Scheme::setDefaultResourceGroup("schemes");
        CEGUI::WidgetLookManager::setDefaultResourceGroup("looknfeels");
        CEGUI::WindowManager::setDefaultResourceGroup("layouts");
        CEGUI::ScriptModule::setDefaultResourceGroup("lua_scripts");
        // setup default group for validation schemas
        CEGUI::XMLParser* parser = CEGUI::System::getSingleton().getXMLParser();
        if (parser->isPropertyPresent("SchemaDefaultResourceGroup"))
                parser->setProperty("SchemaDefaultResourceGroup", "schemas");

        SchemeManager::getSingleton().create("TaharezLook.scheme");
        System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow");
        WindowManager& winMgr = WindowManager::getSingleton();
        DefaultWindow* root = (DefaultWindow*)winMgr.createWindow("DefaultWindow", "Root");
        System::getSingleton().setGUISheet(root);
        FrameWindow* wnd = (FrameWindow*)winMgr.createWindow("TaharezLook/FrameWindow", "Demo Window");
        root->addChildWindow(wnd);
        wnd->setPosition(UVector2(cegui_reldim(0.25f), cegui_reldim( 0.25f)));
    wnd->setSize(UVector2(cegui_reldim(0.5f), cegui_reldim( 0.5f)));
        wnd->setMaxSize(UVector2(cegui_reldim(1.0f), cegui_reldim( 1.0f)));
    wnd->setMinSize(UVector2(cegui_reldim(0.1f), cegui_reldim( 0.1f)));
        wnd->setText("Hello World!");

        sf::Texture     texture;
        sf::Sprite sprite;
        texture.loadFromFile("Data/Textures/Ship.png");
        sprite.setTexture(texture);

        while (window.isOpen())
        {
                sf::Event event;

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

                window.clear(sf::Color(255, 255, 255));
                window.draw(sprite);
                CEGUI::System::getSingleton().renderGUI();
                window.display();
        }

        return 0;
}

Drawing a shape works properly, it's only a sprite which messes things up. Also, once the sprite draw call has been called once, I can stop calling it and the issue still persists. It's messing with the underlying OpenGL somehow.

Anybody have any advice?

2
Graphics / Help with classes
« on: October 14, 2010, 05:49:46 pm »
I'm trying to get my head around classes. I want to create the sprite in the tutorial but implement it using a class. The tutorial has some examples on how to use sprites as classes but I'm not experienced enough with C++ to get them to work. Here is what I have so far..

Code: [Select]
// SFMLTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <SFML/Graphics.hpp>
#include "Mario.h"

int main()
{
    // Create the main rendering window
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");

Mario Mario(App);

    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

        // Get elapsed time
        float ElapsedTime = App.GetFrameTime();

        // Clear screen
        App.Clear();

    // Draw Mario
    Mario.draw(App);

        // Display window contents on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}


Code: [Select]
// Mario.h

#pragma once
#include <SFML/Graphics.hpp>

class Mario
{
public:

static bool Init(const std::string& ImageFile)
    {
        return Image.LoadFromFile("sprite.png");
    }

Mario(sf::RenderWindow &App);

~Mario(void);

void draw(sf::RenderWindow &App);

private :

    static sf::Image Image; // shared by every instance

    sf::Sprite Sprite; // one per instance

sf::RenderWindow &myWindow;
};


Code: [Select]
// Mario.cpp

#include "StdAfx.h"
#include "Mario.h"

Mario::Mario(sf::RenderWindow &App) : myWindow (App)
{
Sprite.SetImage(Image); // every sprite uses the same unique image
}

Mario::~Mario(void)
{
}

void Mario::draw(sf::RenderWindow &App)
{
App.Draw(Sprite);
}


I managed to iron out all the errors apart from this:

Quote
Error   1   error LNK2001: unresolved external symbol "private: static class sf::Image Mario::Image" (?Image@Mario@@0V0sf@@A)   Mario.obj   SFMLTest


I assume it's something to do with this code, because I don't really know what it means (I just copied it from the tutorial):

Code: [Select]
static bool Init(const std::string& ImageFile)
    {
        return Image.LoadFromFile("sprite.png");
    }


I've been trying to figure this out for a few hours before posting here, please help me :).

Pages: [1]
anything