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

Pages: [1]
1
Graphics / Re: mixing SFML Graphics and OpenGL / GLEW
« on: September 13, 2013, 09:02:38 pm »
Correct, I can get rid of all push/pop/reset in my example by adding

glBindBuffer(GL_ARRAY_BUFFER, 0);
glUseProgram(0);

after the opengl code and then all gets displayed as expected.

Now that all make sense!

Thanks all for your help.

2
Graphics / Re: mixing SFML Graphics and OpenGL / GLEW
« on: September 13, 2013, 07:36:51 pm »
Here it is. Not so minimal, but hard to make it short when using the programmable pipeline...
On my computer, if I comment out the push/pop surrounding the sfml code and uncomment the push/pop/reset, then I can see the sfml drawings. I can see the opengl drawing in any case.

#include <GL/glew.h>
#include <SFML/Graphics.hpp>

int main()
{
        const int POSITION_ATTRIBUTE_INDEX = 0;

        const int width = 800;
        const int height = 600;

        sf::RenderWindow window(sf::VideoMode(width, height), "SFML!");
        glewInit();

////window.pushGLStates();

        // compile vertex shader source
    const char* vertexShaderSource =
                "#version 330\n\
                 uniform mat4 mvpMatrix;\
        uniform vec4 color;\
        in vec3 vpos;\
        out vec4 vcolor;\
                 void main(void) {\
                        gl_Position = mvpMatrix * vec4(vpos, 1.0f);\
                        vcolor = color;\
                }"
;
    int vertexShaderSourceLength = strlen(vertexShaderSource);
    GLuint vertexShaderId = glCreateShader(GL_VERTEX_SHADER);
    glShaderSource(vertexShaderId, 1, &vertexShaderSource, &vertexShaderSourceLength);
    glCompileShader(vertexShaderId);

        // compile fragment shader source
    const GLchar* fragmentShaderSource =
                "#version 330\n\
                 in vec4 vcolor;\
        out vec4 fcolor;\
                 void main(void) {\
                        fcolor = vcolor;\
                 }"
;
    int fragmentShaderSourceLength = strlen(fragmentShaderSource);
    GLuint fragmentShaderId = glCreateShader(GL_FRAGMENT_SHADER);
    glShaderSource(fragmentShaderId, 1, &fragmentShaderSource, &fragmentShaderSourceLength);
    glCompileShader(fragmentShaderId);

        // link shader program
    GLuint programId = glCreateProgram();
    glAttachShader(programId, vertexShaderId);
    glAttachShader(programId, fragmentShaderId);
    glBindAttribLocation(programId, POSITION_ATTRIBUTE_INDEX, "position");
    glLinkProgram(programId);

        // create the triangle vertex buffer
        GLuint trianglesId;
    float triangleVertices[] = {
            -0.5f, -0.5f, 0.0f,
            1.0f, -0.5f, 0.0f,
            -0.5f, 1.0f, 0.0f
    };
    glGenBuffers(1, &trianglesId);
    glBindBuffer(GL_ARRAY_BUFFER, trianglesId);
    glBufferData(GL_ARRAY_BUFFER, sizeof(triangleVertices), triangleVertices, GL_STATIC_DRAW);

        // defines the orthographic projection matrix
        float m[16];
        const float left = -1.5f;
        const float right = 1.5f;
        const float bottom = -1.5f;
        const float top = 1.5f;
        const float nearPlane = 1.0f;
        const float farPlane = -1.0f;
        m[0] = 2 / (right - left);
    m[1] = 0.0f;
    m[2] = 0.0f;
    m[3] = 0.0f;
    m[4] = 0.0f;
    m[5] = 2 / (top - bottom);
    m[6] = 0.0f;
    m[7] = 0.0f;
    m[8] = 0.0f;
    m[9] = 0.0f;
    m[10] = 2 / (farPlane - nearPlane);
    m[11] = 0.0f;
    m[12] = -(right + left) / (right - left);
    m[13] = -(top + bottom) / (top - bottom);
    m[14] = -(farPlane + nearPlane) / (farPlane - nearPlane);
    m[15] = 1.0f;

////window.popGLStates();

        bool running = true;
    while (running)
    {
                sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                                running = false;
        }
        window.clear();
               
////////window.resetGLStates();
                window.pushGLStates();
                sf::CircleShape shape(200.f);
                shape.setFillColor(sf::Color::Green);
        window.draw(shape);
                window.popGLStates();

////////window.pushGLStates();
                glUseProgram(programId);
                GLuint matrixUniform = glGetUniformLocation(programId, "mvpMatrix");
                glUniformMatrix4fv(matrixUniform, 1, false, m);
                GLuint color = glGetUniformLocation(programId, "color");
                glUniform4f(color, 1.0f, 1.0f, 0.0f, 0.7f);
                glEnableVertexAttribArray(POSITION_ATTRIBUTE_INDEX);
                glBindBuffer(GL_ARRAY_BUFFER, trianglesId);
                glVertexAttribPointer(POSITION_ATTRIBUTE_INDEX, 3, GL_FLOAT, GL_FALSE, 0, 0);
                glDrawArrays(GL_TRIANGLES, 0, 3);
                glDisableVertexAttribArray(POSITION_ATTRIBUTE_INDEX);
////////window.popGLStates();

                window.display();
    }

    return 0;
}

 

3
Graphics / Re: mixing SFML Graphics and OpenGL / GLEW
« on: September 12, 2013, 10:32:24 pm »
Hmm, not what see: if I surround my SFML code with push/pop, only my opengl related code gets on screen.
If I surround my opengl code with push/pop and add resetGLStates() before calling my SFML code, both opengl and SFML related code get on screen...

I'm using shaders, can this somehow be linked to that?

4
Graphics / Re: mixing SFML Graphics and OpenGL / GLEW
« on: September 12, 2013, 09:38:10 pm »
Thanks for your answer, you put me on the right track!
I was using pushGLStates() and popGLStates() to surround my opengl code. This is not enough apparently.

Now I just added a resetGLStates() call before using SFML graphics functions and it works fine.

So I just misunderstood the tutorial I guess...


5
Graphics / mixing SFML Graphics and OpenGL / GLEW
« on: September 12, 2013, 08:33:33 pm »
Hi,

I'm trying to combine SFML graphics and modern OpenGL with GLEW.
My application compiles fine, and my opengl calls are applied and work fine. However, the SFML graphics draw operations seem to be ignored...

I followed the information about mixing SFML Graphics and opengl GLEW in http://www.sfml-dev.org/tutorials/2.1/window-opengl.php

The SFML graphics calls seem to be ignored as soon as I call glewInit()...
If I don't call glewInit(), my opengl code crashes (extension functions not initialized)...

I know that SFML uses GLEW internally. So my question is: is it possible to combine SFML Graphics and OpenGL / GLEW in my code? If yes, how?

Vincent

Pages: [1]