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

Pages: 1 [2] 3 4
16
Feature requests / Make the class serializable.
« on: July 23, 2014, 06:51:59 pm »
It would be nice to make some SFML classes like sf::Vector, sf::Rect, sf::Color, sf::Vertex, sf::VertexArray, ..., serializable.

It's sometimes paintfull to send complex entities throught the network or to save them into a file. (Especially when entities have a lot of objects and vectors)

template <typename Archive>
    void serialize(Archive & ar, const unsigned int version) {
        ar & position.x;
        ar & position.y;
        ar & position.z;
        ar & color.r;
        ar & color.g;
        ar & color.b;
        ar & color.a;
        ar & texCoords.x;
        ar & texCoords.y;
    }
 

Ok this code is good but I have to change everything because SFML classes are not serializable so :

class ODFAEG_GRAPHICS_API Material {
     friend class boost::serialization::access;
     private :
     struct TextureInfo {
        private :
        const Texture* texture;
        sf::IntRect rect;
        std::string texId;
        public :
        TextureInfo (const Texture* texture, sf::IntRect rect, std::string texId="") {
            this->texture = texture;
            this->rect = rect;
            this->texId = texId;
        }
        void setTexId(std::string texId) {
            this->texId = texId;
        }
        std::string getTexId() {
            return texId;
        }
        bool operator== (TextureInfo& info) {
            return texture == info.texture;
        }
        bool operator!= (TextureInfo& info) {
            return texture != info.texture;
        }
        const Texture* getTexture() const {
            return texture;
        }
        sf::IntRect getTexRect() {
            return rect;
        }
        template <typename Archive>
        void serialize(Archive & ar, const unsigned int version) {
            ar & texInfos;
            ar & color.r;
            ar & color.g;
            ar & color.b;
            ar & color.a;
        }
    };
    std::vector<TextureInfo*> texInfos;
    sf::Color color;
    public :
    int getNbTextures () {
        return texInfos.size();
    }
    void addTexture (const Texture* texture, sf::IntRect rect) {
        texInfos.push_back(new TextureInfo(texture, rect));
    }
    sf::IntRect getTexRect(int texUnit = 0) {
        return (texInfos.size() > 0) ? texInfos[texUnit]->getTexRect() : sf::IntRect(0, 0, 0, 0);
    }
    const Texture* getTexture(int texUnit = 0) {
        return (texInfos.size() > 0) ? texInfos[texUnit]->getTexture() : nullptr;
    }
    std::string getTexId(int texUnit = 0) {
        return (texInfos.size() > 0) ? texInfos[texUnit]->getTexId() : nullptr;
    }
    void setTexId(std::string texId, int texUnit = 0) {
        if (texInfos.size() > 0) {
            texInfos[texUnit]->setTexId(texId);
        }
    }
    bool useSameTextures (Material& material) {
        if (texInfos.size() != material.texInfos.size())
            return false;
        for (unsigned int i = 0; i < texInfos.size(); i++) {
            if (*texInfos[i] != *material.texInfos[i])
                return false;
        }
        return true;

    }
    bool hasSameColor (Material& material) {
        return color == material.color;
    }
    bool operator== (Material& material) {
        return useSameTextures(material) && hasSameColor(material);
    }
    bool operator!= (Material& material) {
        return !useSameTextures(material) || !hasSameColor(material);
    }

};
 

It'll not work because IntRect is not serializable.

For the texture it doesn't matter because I can't send the pointer to the texture directly, but, I send a string instead which tells me which texture to use.

I can make the sf::Texture class serializable and send the image throught the network but I don't thing that's a good idea.

17
Graphics / Bug with render textures.
« on: July 13, 2014, 10:47:06 am »
Hi, in a early post, I was wondering why some opengl functions didn't work with when I use a render texture, and I've found why, the raison is because the window have a n opengl 3 context and the rendertexture an opengl2 context, so, I've changed the render texture class to have the same context than the render window, by passing an sf::CotextSettings object instead of the boolean :

bool RenderTextureImplFBO::create(unsigned int width, unsigned int height, ContextSettings settings, unsigned int textureId)
{
    // Create the context
    m_context = new Context(settings, width, height);

    // Create the framebuffer object
    GLuint frameBuffer = 0;
    glCheck(glGenFramebuffersEXT(1, &frameBuffer));
    m_frameBuffer = static_cast<unsigned int>(frameBuffer);
    if (!m_frameBuffer)
    {
        err() << "Impossible to create render texture (failed to create the frame buffer object)" << std::endl;
        return false;
    }
    glCheck(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_frameBuffer));

    // Create the depth buffer if requested
    if (settings.depthBits > 0)
    {
        GLuint depth = 0;
        glCheck(glGenRenderbuffersEXT(1, &depth));
        m_depthBuffer = static_cast<unsigned int>(depth);
        if (!m_depthBuffer)
        {
            err() << "Impossible to create render texture (failed to create the attached depth buffer)" << std::endl;
            return false;
        }
        glCheck(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_depthBuffer));
        glCheck(glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, width, height));
        glCheck(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthBuffer));
    }

    // Link the texture to the frame buffer
    glCheck(glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, textureId, 0));

    // A final check, just to be sure...
    if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT)
    {
        glCheck(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
        err() << "Impossible to create render texture (failed to link the target texture to the frame buffer)" << std::endl;
        return false;
    }

    return true;
}
 

And now it works, when I want to load a shader after I create a rendertexture it doesn't tell me that only the GLSL 1.x is supported.

 shadowMap = new RenderTexture();
        lightMap = new RenderTexture();
        normalMap = new RenderTexture();
        shadowMap->create(frcm->getWindow().getSize().x, frcm->getWindow().getSize().y,frcm->getWindow().getSettings());
        lightMap->create(frcm->getWindow().getSize().x, frcm->getWindow().getSize().y,frcm->getWindow().getSettings());
        normalMap->create(frcm->getWindow().getSize().x, frcm->getWindow().getSize().y,frcm->getWindow().getSettings());
        resolution = sf::Vector3i ((int) frcm->getWindow().getSize().x, (int) frcm->getWindow().getSize().y, frcm->getWindow().getView().getSize().z);
        perPixLightingShader = new Shader();
        buildNormalMapShader = new Shader();
 

glGetString get me the same version now before and after I create the render texture.

You should modify your render texture classes.

18
Graphics / SFML : how to enable core profile with mesa drivers.
« on: July 11, 2014, 10:10:17 pm »
Hi!
I'm trying to use GLSL 3.30 but it's always telling me that's not supported, I've changed this line and recompiled SFML but it doesn't work :
int attributes[] =
                    {
                        GLX_CONTEXT_MAJOR_VERSION_ARB, static_cast<int>(m_settings.majorVersion),
                        GLX_CONTEXT_MINOR_VERSION_ARB, static_cast<int>(m_settings.minorVersion),
                        GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
                        0, 0
                    };
 

Here is what the console shows :

Code: [Select]
glxinfo | grep OpenGL
OpenGL vendor string: X.Org
OpenGL renderer string: Gallium 0.4 on AMD CEDAR
OpenGL core profile version string: 3.3 (Core Profile) Mesa 10.3.0-devel (git-ee2a818 trusty-oibaf-ppa)
OpenGL core profile shading language version string: 3.30
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 3.0 Mesa 10.3.0-devel (git-ee2a818 trusty-oibaf-ppa)
OpenGL shading language version string: 1.30
OpenGL context flags: (none)
OpenGL extensions:

Why doesn't he want to activate the new opengl profile ?

19
Network / Trouble while receiving data. (TCP mode)
« on: June 14, 2014, 11:26:56 am »
Hi,
I'm trying to send encrypted packet, it works perfectly when i put and extract data from a packet (without sending it with a TCPSocket)

But when I want to send the encrypted data with a TCP Socket, sometimes the data sent and the data received are not the same!

I'm always forced to launch the server again when it happens.

And sometimes the ports doesn't close immediately after it crashes, I must wait for a few minutes.

Here is a case where it crashe :

The encrypted data that I send (for example) is like this :

2????-;??c?Sg?#&IRB?5_p;???

And the data that I receive is like that :

2���-;��c�Sg�#&IRB�5_��p;���

There are too much data so, I think I should report this as an issue.

20
Graphics / Drawing on a rendertexture with moddern opengl fails...
« on: May 30, 2014, 04:31:08 pm »
I don't know if it's a bug of opengl or of SFML, but, when I draw with opengl on a renderwindow. (I mean by using the functions glVertexAttribPointer and the corresponding attribute location in the shaders) it works but when I want to draw it on a rendertexture, it doesn't draw anything!

Here it's a source code :
int main(void)
{
    odfaeg::RenderWindow window(sf::VideoMode(800, 600), "Test odfaeg");
    odfaeg::RenderTexture rTex;
    rTex.create(800, 600);
  odfaeg::Shader shader;
    const std::string vertexCode =  
    "attribute vec3 vertexPosition_modelspace;"
    "attribute vec4 vertex_color;"  
    "void main() {"
        "vec4 vertex = vec4(vertexPosition_modelspace.xyz, 1.0f);"
        "gl_Position = gl_ModelViewProjectionMatrix * vertex;"      
        "gl_FrontColor = vertex_color;"
    "}";
    const std::string fragmentCode =  
    "void main() {"      
        "gl_FragColor = gl_Color;"
    "}";
    shader.loadFromMemory(vertexCode, fragmentCode);
    shader.bindAttribute(0, "vertexPosition_modelspace");
    shader.bindAttribute(1, "vertex_color");
    odfaeg::Texture tex;
    tex.loadFromFile("tilesets/herbe.png");
    Tile tile(&tex, Vec2f(0, 0), Vec2f(120, 60), IntRect(0, 0, 100, 50));
     while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed)
                window.close();
        }
       odfaeg::RenderStates states;
        states.shader = &shader;
        window.clear();
        rTex.clear();
        rTex.draw(tile, states);
        rTex.display();
        odfaeg::Texture tex2 = rTex.getTexture();
        Tile tile2 (&tex2, Vec2f(0, 0), Vec2f(800, 600), IntRect(0, 0, 800, 600));
        window.draw(tile2);
        window.display();
    }
    return 0;
}
 

21
Graphics / How to use preprocessor for shader in loadFromMemory ???
« on: May 30, 2014, 04:14:03 pm »
Hi.

I try to load a shader from memory, which use the version 130 of GLSL but it fails to compile :

const std::string vertexCode =
    "#version 130"
    "attribute vec3 vertexPosition_modelspace;"
    "attribute vec3 vertex_color;"
    "out vec3 color;"
    "void main() {"
        "vec4 vertex = vec4(vertexPosition_modelspace.xyz, 1.0f);"
        "gl_Position = gl_ModelViewProjectionMatrix * vertex;"
        "color = vertex_color;"
    "}";
    const std::string fragmentCode =
    "#version 130"
    "in vec3 color;"
    "out vec3 fragmentColor;"
    "void main() {"
        "fragmentColor = color;"
    "}";
 

Here is the error :
Code: [Select]
preprocessor error : syntax error, unexcepted identifier, unexpected  new line.

Is there a way to do this ?

22
Feature requests / Passing arrays to shader.
« on: May 23, 2014, 01:45:06 pm »
Hi, it should be nice if we can pass also arrays to shader and not only SFML variables

By example an array of float.


23
General / Failed to compile SFML on my raspberry pi.
« on: May 21, 2014, 04:20:20 pm »
Hi, I tried to compile SFML on a raspberry pi but I get this error :

Code: [Select]

[ 17%] Building CXX object src/SFML/Window/CMakeFiles/sfml-window.dir/GlContext.cpp.o
In file included from /home/pi/Development/SFML-master/src/SFML/Window/GlContext.cpp:70:0:
/home/pi/Development/SFML-master/src/SFML/Window/EglContext.hpp:163:12: error: ‘XVisualInfo’ does not name a type
     static XVisualInfo selectBestVisual(::Display* display, unsigned int bitsPerPixel, const ContextSettings& settings);
            ^
src/SFML/Window/CMakeFiles/sfml-window.dir/build.make:80: recipe for target 'src/SFML/Window/CMakeFiles/sfml-window.dir/GlContext.cpp.o' failed
make[2]: *** [src/SFML/Window/CMakeFiles/sfml-window.dir/GlContext.cpp.o] Error 1
CMakeFiles/Makefile2:155: recipe for target 'src/SFML/Window/CMakeFiles/sfml-window.dir/all' failed
make[1]: *** [src/SFML/Window/CMakeFiles/sfml-window.dir/all] Error 2
Makefile:116: recipe for target 'all' failed
make: *** [all]

24
General / How to activate xrandr on a rapsberrypi to run SFML ???
« on: May 20, 2014, 01:51:56 pm »
Hi, when I try to run an SFML Program on a rapsberry pi I get this error :

failed to use xrandr extension while trying to get the desktop videos modes

I know that there is some changes to do in the /etc/config.txt file but I don't know which changes to make to do it works.

Can someone help me ?

PS : xrandr is installed.

25
Hi!

I'm trying to build SFML on a rapsberry pi but I got this following error :

Could not find Freetype (missing Freetype include dirs).

I'm sure I've installed Freetype :with this command and it installed well.

apt-get install libfreetype6-dev.




26
Hi!
glEnable and glDisable client states are deprecated and doesn't work anymore with vbo until opengl 3.

So I've decided to write modern opengl source code for graphics cards which support new opengl versions.

#include <SFML/Graphics.hpp>
#include <glew.h>
#include <SFML/OpenGL.hpp>
#include <fstream>
GLuint LoadShaders(const char * vertex_file_path,const char * fragment_file_path){

    // Create the shaders
    GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
    GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);

    // Read the Vertex Shader code from the file
    std::string VertexShaderCode;
    std::ifstream VertexShaderStream(vertex_file_path, std::ios::in);
    if(VertexShaderStream.is_open())
    {
        std::string Line = "";
        while(getline(VertexShaderStream, Line))
            VertexShaderCode += "\n" + Line;
        VertexShaderStream.close();
    }

    // Read the Fragment Shader code from the file
    std::string FragmentShaderCode;
    std::ifstream FragmentShaderStream(fragment_file_path, std::ios::in);
    if(FragmentShaderStream.is_open()){
        std::string Line = "";
        while(getline(FragmentShaderStream, Line))
            FragmentShaderCode += "\n" + Line;
        FragmentShaderStream.close();
    }

    GLint Result = GL_FALSE;
    int InfoLogLength;

    // Compile Vertex Shader
    printf("Compiling shader : %s\n", vertex_file_path);
    char const * VertexSourcePointer = VertexShaderCode.c_str();
    glShaderSource(VertexShaderID, 1, &VertexSourcePointer , NULL);
    glCompileShader(VertexShaderID);

    // Check Vertex Shader
    glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
    glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
    std::vector<char> VertexShaderErrorMessage(InfoLogLength);
    glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
    fprintf(stdout, "%s\n", &VertexShaderErrorMessage[0]);

    // Compile Fragment Shader
    printf("Compiling shader : %s\n", fragment_file_path);
    char const * FragmentSourcePointer = FragmentShaderCode.c_str();
    glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer , NULL);
    glCompileShader(FragmentShaderID);

    // Check Fragment Shader
    glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
    glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
    std::vector<char> FragmentShaderErrorMessage(InfoLogLength);
    glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]);
    fprintf(stdout, "%s\n", &FragmentShaderErrorMessage[0]);

    // Link the program
    fprintf(stdout, "Linking program\n");
    GLuint ProgramID = glCreateProgram();
    glAttachShader(ProgramID, VertexShaderID);
    glAttachShader(ProgramID, FragmentShaderID);
    glLinkProgram(ProgramID);

    // Check the program
    glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
    glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
    std::vector<char> ProgramErrorMessage(std::max(InfoLogLength, int(1)) );
    glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]);
    fprintf(stdout, "%s\n", &ProgramErrorMessage[0]);

    glDeleteShader(VertexShaderID);
    glDeleteShader(FragmentShaderID);

    return ProgramID;
}
int main()
{
    // create the window
    sf::Window window(sf::VideoMode(800, 600), "My window", sf::Style::Default, sf::ContextSettings(32));
    glewInit();
    GLuint VertexArrayID;
    glGenVertexArrays(1, &VertexArrayID);
    glBindVertexArray(VertexArrayID);
    static const GLfloat g_vertex_buffer_data[] = {
       -1.0f, -1.0f, 0.0f,
       1.0f, -1.0f, 0.0f,
       0.0f,  1.0f, 0.0f,
    };

    // This will identify our vertex buffer
    GLuint vertexbuffer;
    // Generate 1 buffer, put the resulting identifier in vertexbuffer
    glGenBuffers(1, &vertexbuffer);
    // The following commands will talk about our 'vertexbuffer' buffer
    glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);

    // Give our vertices to OpenGL.
    glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);
    //Unbind the buffer.
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    // Create and compile our GLSL program from the shaders
    GLuint programID = LoadShaders( "SimpleVertexShader.vertexshader", "SimpleFragmentShader.fragmentshader" );
    // run the program as long as the window is open
    glBindAttribLocation(programID, 0, "vertexPosition_modelspace");
    while (window.isOpen())
    {
        // check all the window's events that were triggered since the last iteration of the loop
        sf::Event event;
        while (window.pollEvent(event))
        {
            // "close requested" event: we close the window
            if (event.type == sf::Event::Closed)
                window.close();
            else if (event.type == sf::Event::Resized)
                // adjust the viewport when the window is resized
                glViewport(0, 0, event.size.width, event.size.height);
        }

        // clear the window with black color
        glClear(GL_COLOR_BUFFER_BIT);
        glEnableVertexAttribArray(0);
        glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
        //const char* data = reinterpret_cast<const char*>(&vertices[0]);
        glVertexAttribPointer(
           0,                  // attribute 0. No particular reason for 0, but must match the layout in the shader.
           3,                  // size
           GL_FLOAT,           // type
           GL_FALSE,           // normalized?
           0,                  // stride
           (void*)0            // array buffer offset
        );
        // Use our shader
        glUseProgram(programID);
        // Draw the triangle !
        glDrawArrays(GL_TRIANGLES, 0, 3); // Starting from vertex 0; 3 vertices total -> 1 triangle

        glDisableVertexAttribArray(0);
        glBindBuffer(GL_ARRAY_BUFFER, 0);
        // draw everything here...
        // window.draw(...);

        // end the current frame
        window.display();
    }
    glDeleteBuffers(1, &vertexbuffer);
    return 0;
}
 
The shaders :
#version 130
attribute vec3 vertexPosition_modelspace;
void main() {
    gl_Position.xyz = vertexPosition_modelspace;
    gl_Position.w = 1.0;
}
 
#version 130
out vec3 color;
 
void main(){
    color = vec3(1,0,0);
}
 

In your tutorials it only explain how to pass uniform variables to sf::Shaders but in modern opengl we need to pass attributes to sf::Shader because glVertexPointer, glColorPointer, ... are deprecated.

Should I modify the class sf::Shader myself to pass vertex attributes into my shader ?

27
General discussions / SFML compatibility.
« on: May 03, 2014, 09:58:50 am »
Hi, I have some questions about the futur of SFML :

Will be SFML compatible with all of these plateforms : (IOS, Android, Win8 Phone, PC, Mac and Tablets) ?

Will SFML provides the possibility to develop games introducing touchscreen interfaces ?

If I'm asking all of that it's because, in the future, I would like to create a development studio like this one :
http://seriousgaming.fishingcactus.com/en/Technologie.html

But with SFML and my own engine using SFML. :)

I'm sure they don't use SFML. (I know them quite well)
They are using unity and SDL but to be honest I didn't know unity and SDL quite well to create games with it and I don't want to learn it because I prefer to be independant from an existing editor.

So I want something like Irrlicht by example but not only to create 3D FPS but also applis on new plateforms.

28
Network / Crash on linux with selector.isReady
« on: April 27, 2014, 11:35:30 am »
Hi!

I've a crash in the function selector.isReady.

When I connect a client once it works, but, when I connect and then disconnect the client a second time, it crash.

Here's what the debugguer shows ;

#0 0x7ffff6535f79       __GI_raise(sig=sig@entry=6) (../nptl/sysdeps/unix/sysv/linux/raise.c:56)
#1 0x7ffff6539388       __GI_abort() (abort.c:89)
#2 0x7ffff65731d4       __libc_message(do_abort=do_abort@entry=2, fmt=fmt@entry=0x7ffff667f415 "*** %s ***: %s terminated\n") (../sysdeps/posix/libc_fatal.c:175)
#3 0x7ffff660ab2c       __GI___fortify_fail(msg=<optimized out>, msg@entry=0x7ffff667f3ac "buffer overflow detected") (fortify_fail.c:37)
#4 0x7ffff66099f0       __GI___chk_fail() (chk_fail.c:28)
#5 0x7ffff660aa77       __fdelt_chk(d=<optimized out>) (fdelt_chk.c:25)
#6 0x7ffff7bd3d9c       sf::SocketSelector::isReady(sf::Socket&) const() (/usr/local/lib/libsfml-network.so.2:??)
#7 0x43e3c4     odfaeg::SrkServer::run(this=0x8052f0) (/home/laurent/Projets-dev/Projets-c++/ODFAEG/src/odfaeg/Network/srkserveur.cpp:79)
#8 0x7ffff6e92bf0       ??() (/usr/lib/x86_64-linux-gnu/libstdc++.so.6:??)
#9 0x7ffff62e9182       start_thread(arg=0x7ffff20fc700) (pthread_create.c:312)
#10 0x7ffff65fa30d      clone() (../sysdeps/unix/sysv/linux/x86_64/clone.S:111)
 

Is seems that there is a buffer overflow somewhere.

29
Network / Putting messages on packets.
« on: April 26, 2014, 01:26:11 pm »
Hi, I'm on ubuntu.

I would like to put contents on packet with the operator <<.

But it doesn't seems to work.

sf::Packet packet;
for (unsigned int i = 0; i < texPaths.size(); i++) {
        packet<<texPaths[i];
        if (i != texPaths.size() - 1)
               packet<<"*";
}                
std::string message;
packet>>message;
std::cout<<"message : "<<message<<std::endl;
 

Is it normal that only the first std::string of my std::vector si putted into the packet ?

30
Hi, I'm trying to debug a project so I'm currently trying to use the openg4.1 extension in the resource class of SFML but it crash :

////////////////////////////////////////////////////////////
GlResource::GlResource(){

        // Protect from concurrent access

        #ifdef SFML_DEBUG
        #ifndef DEBUG_FUNCTIONS_LOADED
        std::cout<<"loading internal sfml debug function"<<std::endl;
        OpenGL::LoadDebugFunctions();
        #define  DEBUG_FUNCTIONS_LOADED
        #endif
        #endif
        // If this is the very first resource, trigger the global context initialization
        Lock lock(mutex);
        if (count == 0)
            priv::GlContext::globalInit();
        #ifdef SFML_DEBUG
        #ifndef DEBUG_FUNCTIONS_INITIALIZED
        std::cout<<"initializing internal opengl debug functions"<<std::endl;
        OpenGL::InitialiseDebugFunctions();
        #define DEBUG_FUNCTIONS_INITIALIZED
        #endif
        #endif // DEBUG_FUNCTIONS_INITIALIZED
        // Increment the resources counter
        count++;


    // Now make sure that there is an active OpenGL context in the current thread
    priv::GlContext::ensureContext();
}
 

Here is the file that someone passed to me :

/***************************************************************************
 * @file GlDebug.cpp
 * @author dragonjoker59
 * @date 07/03/2014
 *
 * @brief Permet l'affichage des informations de debug provenant d'OpenGL
 *
 * @details Utilise les extensions GL_ARB_debug_output et GL_AMDX_debug_output si elles sont disponibles.
 *
 ***************************************************************************/


 #include "GlDebug.hpp"

#include <cstdint>
#include <iostream>

#if defined( _WIN32 )
#   include <Windows.h>
#else
#   include <GL/glx.h>
#endif

#include <GL/gl.h>

//*************************************************************************************************

namespace gl_api
{
    /** Récupère une fonction dans la dll OpenGL actuellement chargée
    @param p_strName
        Le nom de la fonction
    @param p_func
        Reçoit la fonction
    @return
        true si la fonction a été trouvée, false sinon
    */

        template< typename Func >
        bool GetFunction( std::string const & p_strName, Func & p_func )
        {
#if defined( _WIN32 )
                p_func = reinterpret_cast< Func >( wglGetProcAddress( p_strName.c_str() ) );
#elif defined( __linux__ )
                p_func = reinterpret_cast< Func >( glXGetProcAddress( (GLubyte const *)p_strName.c_str() ) );
#endif
                return p_func != NULL;
        }

#define MAKE_GL_EXTENSION( x )  static const std::string x = "GL_"#x;

    MAKE_GL_EXTENSION( ARB_debug_output )
    MAKE_GL_EXTENSION( AMDX_debug_output )

    //! Dit que l'on veut les informations de debug en synchrone
    static const int iGL_DEBUG_OUTPUT_SYNCHRONOUS = 0x8242;

    /** Les types d'informations
    */

    typedef enum eGL_DEBUG_TYPE : uint32_t
    {   eGL_DEBUG_TYPE_ERROR                            = 0x824C
    ,   eGL_DEBUG_TYPE_DEPRECATED_BEHAVIOR      = 0x824D
    ,   eGL_DEBUG_TYPE_UNDEFINED_BEHAVIOR       = 0x824E
    ,   eGL_DEBUG_TYPE_PORTABILITY                      = 0x824F
    ,   eGL_DEBUG_TYPE_PERFORMANCE                      = 0x8250
    ,   eGL_DEBUG_TYPE_OTHER                            = 0x8251
    }   eGL_DEBUG_TYPE;

    /** Les sources des informations
    */

    typedef enum eGL_DEBUG_SOURCE : uint32_t
    {   eGL_DEBUG_SOURCE_API                = 0x8246
    ,   eGL_DEBUG_SOURCE_WINDOW_SYSTEM      = 0x8247
    ,   eGL_DEBUG_SOURCE_SHADER_COMPILER    = 0x8248
    ,   eGL_DEBUG_SOURCE_THIRD_PARTY        = 0x8249
    ,   eGL_DEBUG_SOURCE_APPLICATION        = 0x824A
    ,   eGL_DEBUG_SOURCE_OTHER                          = 0x824B
    }   eGL_DEBUG_SOURCE;

    /** Les catégories d'informations
    */

    typedef enum eGL_DEBUG_CATEGORY : uint32_t
    {   eGL_DEBUG_CATEGORY_API_ERROR                    = 0x9149
    ,   eGL_DEBUG_CATEGORY_WINDOW_SYSTEM                = 0x914A
    ,   eGL_DEBUG_CATEGORY_DEPRECATION                  = 0x914B
    ,   eGL_DEBUG_CATEGORY_UNDEFINED_BEHAVIOR   = 0x914C
    ,   eGL_DEBUG_CATEGORY_PERFORMANCE                  = 0x914D
    ,   eGL_DEBUG_CATEGORY_SHADER_COMPILER              = 0x914E
    ,   eGL_DEBUG_CATEGORY_APPLICATION                  = 0x914F
    ,   eGL_DEBUG_CATEGORY_OTHER                                = 0x9150
    }   eGL_DEBUG_CATEGORY;

    /** Les importances des informations
    */

    typedef enum eGL_DEBUG_SEVERITY : uint32_t
    {   eGL_DEBUG_SEVERITY_HIGH         = 0x9146
    ,   eGL_DEBUG_SEVERITY_MEDIUM       = 0x9147
    ,   eGL_DEBUG_SEVERITY_LOW          = 0x9148
    }   eGL_DEBUG_SEVERITY;
}

//*************************************************************************************************

typedef void (CALLBACK * PFNGLDEBUGPROC)( uint32_t source, uint32_t type, uint32_t id, uint32_t severity, int length, const char * message, void * userParam );
typedef void (CALLBACK * PFNGLDEBUGAMDPROC)( uint32_t id, uint32_t category, uint32_t severity, int length, const char* message, void* userParam );
typedef void (CALLBACK * PFNGLDEBUGMESSAGECALLBACK)( PFNGLDEBUGPROC callback, void * userParam );
typedef void (CALLBACK * PFNGLDEBUGMESSAGECALLBACKAMD)( PFNGLDEBUGAMDPROC callback, void * userParam );

PFNGLDEBUGMESSAGECALLBACK glDebugMessageCallback = NULL;
PFNGLDEBUGMESSAGECALLBACKAMD glDebugMessageCallbackAMD = NULL;

void OpenGL::LoadDebugFunctions()
{
    std::string l_strExtensions = (char const *)glGetString( GL_EXTENSIONS );

    if( l_strExtensions.find( gl_api::ARB_debug_output ) != std::string::npos )
    {
        if( !gl_api::GetFunction( "glDebugMessageCallback", glDebugMessageCallback ) )
        {
            if( !gl_api::GetFunction( "glDebugMessageCallbackARB", glDebugMessageCallback ) )
            {
                std::cout << "Unable to retrieve function glDebugMessageCallback" << std::endl;
            }
        }
    }
    else if( l_strExtensions.find( gl_api::AMDX_debug_output ) != std::string::npos )
    {
        if( !gl_api::GetFunction( "glDebugMessageCallbackAMD", glDebugMessageCallbackAMD ) )
        {
            std::cout << "Unable to retrieve function glDebugMessageCallbackAMD" << std::endl;
        }
    }
}

void OpenGL::InitialiseDebugFunctions()
{
    if( glDebugMessageCallback )
    {
        glDebugMessageCallback( PFNGLDEBUGPROC( &CallbackDebugLog ), NULL );
        glEnable( gl_api::iGL_DEBUG_OUTPUT_SYNCHRONOUS );
    }
    else if( glDebugMessageCallbackAMD )
    {
         glDebugMessageCallbackAMD( PFNGLDEBUGAMDPROC( &CallbackDebugLogAMD ), NULL );
        glEnable( gl_api::iGL_DEBUG_OUTPUT_SYNCHRONOUS );
    }
}

void OpenGL::CallbackDebugLog( uint32_t source, uint32_t type, uint32_t id, uint32_t severity, int length, const char * message, void * userParam  )
{
    std::cout << "OpenGL Debug - ";

    switch( source )
    {
    case gl_api::eGL_DEBUG_SOURCE_API:                          std::cout << "Source:OpenGL\t";                     break;
    case gl_api::eGL_DEBUG_SOURCE_WINDOW_SYSTEM:        std::cout << "Source:Windows\t";                        break;
    case gl_api::eGL_DEBUG_SOURCE_SHADER_COMPILER:      std::cout << "Source:Shader compiler\t";        break;
    case gl_api::eGL_DEBUG_SOURCE_THIRD_PARTY:          std::cout << "Source:Third party\t";            break;
    case gl_api::eGL_DEBUG_SOURCE_APPLICATION:          std::cout << "Source:Application\t";            break;
    case gl_api::eGL_DEBUG_SOURCE_OTHER:                        std::cout << "Source:Other\t";                          break;
    }

    switch( type )
    {
    case gl_api::eGL_DEBUG_TYPE_ERROR:                                  std::cout << "Type:Error\t";                            break;
    case gl_api::eGL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:    std::cout << "Type:Deprecated behavior\t";      break;
    case gl_api::eGL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:             std::cout << "Type:Undefined behavior\t";       break;
    case gl_api::eGL_DEBUG_TYPE_PORTABILITY:                    std::cout << "Type:Portability\t";                      break;
    case gl_api::eGL_DEBUG_TYPE_PERFORMANCE:                    std::cout << "Type:Performance\t";                      break;
    case gl_api::eGL_DEBUG_TYPE_OTHER:                                  std::cout << "Type:Other\t";                            break;
    }

    std::cout << "ID:" << id << "\t";

    switch( severity )
    {
    case gl_api::eGL_DEBUG_SEVERITY_HIGH:       std::cout << "Severity:High\t";     break;
    case gl_api::eGL_DEBUG_SEVERITY_MEDIUM:     std::cout << "Severity:Medium\t";       break;
    case gl_api::eGL_DEBUG_SEVERITY_LOW:        std::cout << "Severity:Low\t";          break;
    }

    std::cout << "Message:" << message << std::endl;
}

void OpenGL::CallbackDebugLogAMD( uint32_t id, uint32_t category, uint32_t severity, int length, const char* message, void* userParam )
{
    std::cout << "OpenGL Debug - ";

    switch( category )
    {
    case gl_api::eGL_DEBUG_CATEGORY_API_ERROR:                  std::cout << "Category:OpenGL\t";                               break;
    case gl_api::eGL_DEBUG_CATEGORY_WINDOW_SYSTEM:              std::cout << "Category:Windows\t";                              break;
    case gl_api::eGL_DEBUG_CATEGORY_DEPRECATION:                std::cout << "Category:Deprecated behavior\t";  break;
    case gl_api::eGL_DEBUG_CATEGORY_UNDEFINED_BEHAVIOR: std::cout << "Category:Undefined behavior\t";   break;
    case gl_api::eGL_DEBUG_CATEGORY_PERFORMANCE:                std::cout << "Category:Performance\t";                  break;
    case gl_api::eGL_DEBUG_CATEGORY_SHADER_COMPILER:    std::cout << "Category:Shader compiler\t";              break;
    case gl_api::eGL_DEBUG_CATEGORY_APPLICATION:                std::cout << "Category:Application\t";                  break;
    case gl_api::eGL_DEBUG_CATEGORY_OTHER:                              std::cout << "Category:Other\t";                                break;
    }

    std::cout << "ID:" << id << "\t";

    switch( severity )
    {
    case gl_api::eGL_DEBUG_SEVERITY_HIGH:       std::cout << "Severity:High\t"; break;
    case gl_api::eGL_DEBUG_SEVERITY_MEDIUM:     std::cout << "Severity:Medium\t";       break;
    case gl_api::eGL_DEBUG_SEVERITY_LOW:        std::cout << "Severity:Low\t";  break;
    }

    std::cout << "Message:" << message << std::endl;
}

//*************************************************************************************************
 

It crash in the function loadDebugFunctions and give me this error :
#0 0044CAA0     __cxa_throw () (??:??)
#1 0044AFDB     std::__throw_logic_error(char const*) () (??:??)
#2 004A3714     char* std::string::_S_construct<char const*>(char const*, char const*, std::allocator<char> const&, std::forward_iterator_tag) () (??:??)
 

Does the version of glew used by SFML support the new opengl4.1 extension ?

Or should I get a newest version of glew ?


Pages: 1 [2] 3 4