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

Pages: [1]
1
General / Re: Linking SFML static lib into a DLL?
« on: June 27, 2013, 02:25:13 pm »
Thanks for the quick reply. That worked perfectly.  ;)

2
General / Linking SFML static lib into a DLL?
« on: June 27, 2013, 01:49:38 pm »
Hi,

I have the following problem. I would like to use the static libs of SFML, not the dynamic ones.

However, my project is a DLL (the DLL is intended to be used in another language), so the static SFML libs need to be linked against the dll.

I'm using Visual C++ Express 2008, and get the following errors:
error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Clock::clock(void)" (__imp_??0Clock@sf@@QAE@XZ) referenced in function "public: __thiscall cSomeClass::cSomeClass(void)"

The class in the static library looks like this:

class cSomeClass
{
public:
   cSomeClass(void){ m_Clock = new sf::Clock(); }
   ~cSomeClass(void){ delete m_Clock; }
private:
   sf::Clock* m_Clock;
};

Is there something I'm missing? From what I've found on google, linking static libs into DLLs is a royal pain.

I also came across the linker option used in GCC --whole-archive, which would force the inclusion of the entire static library and resolve the problem above. What is the equivalent in VC++?

Do I need to do something with SFML_SYSTEM_EXPORTS to make everything visible to the DLL?

Thanks,

TheComet

3
Graphics / Re: Shader not working when drawing VertexArray?
« on: May 31, 2013, 08:37:05 pm »
Perfect, thanks a lot for all of the help!

4
Graphics / Re: Shader not working when drawing VertexArray?
« on: May 31, 2013, 07:59:06 pm »
Doh, I literally facepalmed when I read that.  ;D

Just one more problem left now. In the fragment program, gl_TexCoord[0] doesn't seem to ever change, i.e. it isn't returning the coordinates of the current pixel, but it's always zero.

What could be causing this?

Vertex:
void main( void )
{
        vec4 colour = vec4(gl_TexCoord[0].xy, 0.4f, 1.0);
        gl_FragColor = colour;
}

Fragment:
void main()
{
    // transform the vertex position
    gl_Position = ftransform();

    // transform the texture coordinates
    gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;

    // forward the vertex color
    gl_FrontColor = gl_Color;
}

5
Graphics / Re: Shader not working when drawing VertexArray?
« on: May 31, 2013, 05:14:58 pm »
Sure, here you go:

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

// -------------------------------------------------------------------
// Main entry point
int main( int argc, char* argv[] )
{

        // setup stuff
        sf::RenderWindow window( sf::VideoMode( 800, 600 ), "GPU Fractal Zoomer", sf::Style::Close | sf::Style::Titlebar );
        sf::Event event;

        // vertex shader
        const std::string vertexShader = \
                "void main()\n"\
                "{\n"\
                        "// transform the vertex position\n"\
                        "gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"\
                        "\n"\
                        "// transform the texture coordinates\n"\
                        "gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;\n"\
                        "\n"\
                        "// forward the vertex color\n"\
                        "gl_FrontColor = gl_Color;\n"\
                "}\n";

        // fragment shader
        const std::string fragmentShader = \
                "void main( void )\n"\
                "{\n"\
                        "vec4 colour = vec4(0.4f, 0.8f, 0.1f, 0.0);\n"\
                        "gl_FragColor = colour;\n"\
                "}\n";

        // load shader
        sf::Shader shader;
        shader.loadFromMemory( vertexShader, fragmentShader );

        // create quad
        sf::VertexArray quad( sf::Quads, 4 );
        quad[0].position = sf::Vector2f( 0, 0 );
        quad[1].position = sf::Vector2f( static_cast<float>(window.getSize().x), 0.0 );
        quad[2].position = sf::Vector2f( static_cast<float>(window.getSize().x), static_cast<float>(window.getSize().y) );
        quad[3].position = sf::Vector2f( 0.0, static_cast<float>(window.getSize().y) );

        // main loop
        while( window.isOpen() )
        {

                // render
                window.clear( sf::Color::Black );
                window.draw( quad, &shader );
                window.display();

                // poll window events
                while( window.pollEvent( event ) )
                {
                        switch( event.type )
                        {

                                // close window was requested
                                case sf::Event::Closed :
                                        window.close();
                                        break;

                                // not interested in this event
                                default :
                                        break;

                        }
                }

        }

        return 0;
}

6
Graphics / Re: Shader not working when drawing VertexArray?
« on: May 31, 2013, 04:42:22 pm »
Quote
Is the black color outputed by the shader, or is it the window's clear color?

It's the window's clear colour.

7
Graphics / Re: Shader not working when drawing VertexArray?
« on: May 31, 2013, 04:31:56 pm »
That was just my foolish editing of the shader in the last minute while I was writing that forum post. :P

The exception isn't being thrown now, I double checked. The shaders appear to compile and link successfully.

Could it have something to do with not setting the shader's "current texture"?


8
Graphics / Re: Shader not working when drawing VertexArray?
« on: May 31, 2013, 04:09:24 pm »
Fixed. :)

However, the problem still persists: I just get a black screen. My rendering routine looks like this now:

// -------------------------------------------------------------------
// render fractal to window
void cFractalFrame::render( sf::RenderWindow* window )
{

        // set shader uniforms
        /*
        this->m_pShader->setParameter( "maxX", maxX );
        this->m_pShader->setParameter( "maxY", maxY );
        this->m_pShader->setParameter( "minX", minX );
        this->m_pShader->setParameter( "minY", minY );
        this->m_pShader->setParameter( "maxIterations", maxIterations );*/


        // render to window
        window->draw( *this->m_pQuad, this->m_pShader );
}

The quad renders if I change the last line to this:

        // render to window
        window->draw( *this->m_pQuad );

It's very strange. I'm going to assume I'm doing something wrong in the vertex shader, but I can't see what.

9
Graphics / Shader not working when drawing VertexArray?
« on: May 31, 2013, 03:36:04 pm »
Hi,

I'm trying to render a fractal using a shader, and all I get is a black screen when I render the VertexArray.

I created a quad which covers the entire screen:

        // set up vertex array
        this->m_pQuad = new sf::VertexArray( sf::Quads, 4 );
        (*this->m_pQuad)[0].position = sf::Vector2f( 0, 0 );
        (*this->m_pQuad)[1].position = sf::Vector2f( static_cast<float>(window->getSize().x), 0.0 );
        (*this->m_pQuad)[2].position = sf::Vector2f( static_cast<float>(window->getSize().x), static_cast<float>(window->getSize().y) );
        (*this->m_pQuad)[3].position = sf::Vector2f( 0.0, static_cast<float>(window->getSize().y) );

And in my render routine, I do the following:

        // set shader uniforms
        this->m_pShader->setParameter( "maxX", maxX );
        this->m_pShader->setParameter( "maxY", maxY );
        this->m_pShader->setParameter( "minX", minX );
        this->m_pShader->setParameter( "minY", minY );
        this->m_pShader->setParameter( "maxIterations", maxIterations );

        // render to window
        window->draw( *this->m_pQuad, this->m_pShader );

The quad draws to the window if I change the last line to this:

        // render to window
        window->draw( *this->m_pQuad );

The vertex shader looks like this:

void main()
{
    // transform the vertex position
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

    // transform the texture coordinates
    gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;

    // forward the vertex color
    gl_FrontColor = gl_Color;
}

The fragment shader looks like this:

void main( void )
{
        vec4 colour = vec4(0.4f, 0.8f 0.1f, 0.0);
        gl_FragColor = colour;
}

Here is the entire class:

cFractalFrame.hpp
// -------------------------------------------------------------------
// Handles drawing of the fractal
// -------------------------------------------------------------------

#ifndef _CFRACTALFRAME_HPP_
#define _CFRACTALFRAME_HPP_

// -------------------------------------------------------------------
// include files
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>

namespace GPUFractalZoomer {

class cFractalFrame
{
public:

        // factal types
        enum FractalType
        {
                Mandelbrot
        };

        // constructor, destructor
        cFractalFrame( sf::RenderWindow* window );
        ~cFractalFrame( void );

        // load a fractal
        void load( FractalType type );

        // render fractal to window
        void render( sf::RenderWindow* window );

private:

        // use a quad to render the fractal
        sf::VertexArray* m_pQuad;

        // fragment program of the current fractal
        sf::Shader* m_pShader;

        // fractal parameters to be passed to the shader
        float minX;
        float maxX;
        float minY;
        float maxY;
        float maxIterations;
};

} // namespace GPUFractalZoomer

#endif // _CFRACTALFRAME_HPP_

cFractalFrame.cpp
// -------------------------------------------------------------------
// Handles drawing of the fractal
// -------------------------------------------------------------------

// -------------------------------------------------------------------
// include files
#include <cFractalFrame.hpp>
#include <cException.hpp>
#include <iostream>

namespace GPUFractalZoomer {

// -------------------------------------------------------------------
// constructor
cFractalFrame::cFractalFrame( sf::RenderWindow* window ) :
        m_pQuad( NULL ),
        m_pShader( NULL )
{
        // debug
        std::cout << "constructed cFractalFrame" << std::endl;

        // set up vertex array
        this->m_pQuad = new sf::VertexArray( sf::Quads, 4 );
        (*this->m_pQuad)[0].position = sf::Vector2f( 0, 0 );
        (*this->m_pQuad)[1].position = sf::Vector2f( static_cast<float>(window->getSize().x), 0.0 );
        (*this->m_pQuad)[2].position = sf::Vector2f( static_cast<float>(window->getSize().x), static_cast<float>(window->getSize().y) );
        (*this->m_pQuad)[3].position = sf::Vector2f( 0.0, static_cast<float>(window->getSize().y) );

        // create shader
        this->m_pShader = new sf::Shader();
}

// -------------------------------------------------------------------
// destructor
cFractalFrame::~cFractalFrame( void )
{
        // debug
        std::cout << "destructed cFractalFrame" << std::endl;

        delete this->m_pShader;
        delete this->m_pQuad;
}

// -------------------------------------------------------------------
// load a fractal
void cFractalFrame::load( FractalType type )
{
        switch( type )
        {

                // mandelbrot
                case Mandelbrot :

                        // attempt to load shader
                        if( !this->m_pShader->loadFromFile( "media/shaders/commonVertexShader.vsh", "media/shaders/simpletest.fsh" ) )
                        {
                                throw cException();
                        }

                        // set default zoom values
                        minX = -2.0f;
                        maxX = 1.0f;
                        minY = -1.2f;
                        maxY = 1.2f;
                        maxIterations = 10.0;

                        break;

                default :
                        break;
        }
}

// -------------------------------------------------------------------
// render fractal to window
void cFractalFrame::render( sf::RenderWindow* window )
{

        // set shader uniforms
        this->m_pShader->setParameter( "maxX", maxX );
        this->m_pShader->setParameter( "maxY", maxY );
        this->m_pShader->setParameter( "minX", minX );
        this->m_pShader->setParameter( "minY", minY );
        this->m_pShader->setParameter( "maxIterations", maxIterations );

        // render to window
        window->draw( *this->m_pQuad, this->m_pShader );
}

} // namespace GPUFractalZoomer

Where did I go wrong?

10
Feature requests / Re: Virtual Destructors?
« on: May 31, 2013, 12:48:22 am »
Thanks for the link, thor is going to help a great deal with my project. :)

11
Feature requests / Re: Virtual Destructors?
« on: May 30, 2013, 09:48:26 pm »
I wanted to write a texture manager class which would keep track of all loaded textures. There are numerous cases where the same texture is used multiple times, and I wanted to write a class which would keep track of all of the loaded textures and prevent duplicates in memory. For this to happen, each texture needs to store some additional data about it (perhaps the path it was loaded from).

My thoughts were to write another class inheriting the sf::Texture class in order to add more methods and attributes to it, which would look somewhat like this:

class cTexture : public sf::Texture
{
   // inherits everything from sf::Texture

private:
   
   // stores the file path the texture was loaded from so it can be compared with other textures in the future
   std::string filePath;
};

I'm unsure if this is the correct way to approach this, any feedback is appreciated. :)

12
Feature requests / Virtual Destructors?
« on: May 30, 2013, 08:50:42 pm »
Hey,

I'm very new to SFML, so I don't know the guts of it.

However, I couldn't help but notice that no destructors in any of the classes are declared virtual, which could cause memory leaks when trying to inherit them, and using a base pointer to address the object.

This is an example of what I mean:

class cDerivedTexture : public sf::Texture
{
public:
   cDerivedTexture( void );
   ~cDerivedTexture( void );
private:
   // stuff, not really important
};


// Then, later on...


// make a new texture
sf::Texture* myTexture = new cDerivedTexture();

/* --- SNIP --- */

// now delete the texture
delete myTexture; // Oh oh, destructor of sf::Texture isn't called!

I'm going to assume the destructor sf::Texture::~Texture() plays an important role in freeing up memory of loaded images, but in the above example, it isn't called when deleting the derived texture class.

The fix would be to make it virtual:

// The SFML texture class
class Texture
{
   // destructor of sf::Texture
   virtual ~Texture();

   // other stuff
}

Any thoughts or ideas?

TheComet

Pages: [1]
anything