SFML community forums

Help => General => Topic started by: herotom99 on March 23, 2016, 11:29:29 am

Title: OpenGL: Version 0.0
Post by: herotom99 on March 23, 2016, 11:29:29 am
Hi,
I'm trying to use correclty OpenGL on two different pc.

The first is a Laptop and it works perfectly:
-Intel(R) HD Graphics 4000
-Drivers updated
-Windows 10

But on my second pc (more powerful  :) ), I have an error:
-NVIDIA GeForce GTX770 4Go
-Drivers updated
-Windows 7

Here is the error message:
https://gyazo.com/7aae9d9c6f14e3dcac6b9f4899f212cc

I use the same code and it is recompiled before use it.

Code:
#include <iostream>
#include <string>

#include "GL\glew.h"

#include "SFML\OpenGL.hpp"
#include "SFML\Graphics.hpp"
#include "SFML\Window.hpp"

#include "glm\gtx\transform.hpp"

#include "Camera.h"

using namespace std;

int main(int argc, char *args[])
{
        sf::Context context;
        sf::ContextSettings settings;
        settings.depthBits = 24;
        settings.stencilBits = 8;
        settings.majorVersion = 4;
        settings.minorVersion = 0;
        settings.antialiasingLevel = 8;

        sf::RenderWindow window(sf::VideoMode(1280, 800), "OpenGL",sf::Style::Close, settings);

        glewExperimental = GL_TRUE;
        glewInit();

        sf::Event event;

        Camera camera(glm::vec3(4,4,3),1280.f / 800.f, glm::radians(90.f), 0.0001f, 1000.0f);

        bool IsRunning = true;

        //OPENGL//

        float points[] = {
                0.0f, 0.5f, 0.0f,
                0.5f, -0.5f, 0.0f,
                -0.5f, -0.5f, 0.0f
        };

        GLuint vbo = 0;
        glGenBuffers(1, &vbo);
        glBindBuffer(GL_ARRAY_BUFFER, vbo);
        glBufferData(GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW);

        GLuint vao = 0;
        glGenVertexArrays(1, &vao);
        glBindVertexArray(vao);
        glEnableVertexAttribArray(0);
        glBindBuffer(GL_ARRAY_BUFFER, vbo);
        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);

        const char* vertex_shader =
                "#version 400\n"
                "in vec3 vp;"
                "uniform mat4 MVP;"
                "void main () {"
                "  gl_Position = MVP * vec4 (vp, 1.0);"
                "}";

        const char* fragment_shader =
                "#version 400\n"
                "out vec4 frag_colour;"
                "void main () {"
                "  frag_colour = vec4 (1.0, 0.0, 0.0, 1.0);"
                "}";

        GLuint vs = glCreateShader(GL_VERTEX_SHADER);
        glShaderSource(vs, 1, &vertex_shader, NULL);
        glCompileShader(vs);
        GLuint fs = glCreateShader(GL_FRAGMENT_SHADER);
        glShaderSource(fs, 1, &fragment_shader, NULL);
        glCompileShader(fs);

        GLuint shader_programme = glCreateProgram();
        glAttachShader(shader_programme, fs);
        glAttachShader(shader_programme, vs);
        glLinkProgram(shader_programme);



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

                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

                glUseProgram(shader_programme);

                GLuint MVPID = glGetUniformLocation(shader_programme, "MVP");
                glUniformMatrix4fv(MVPID, 1, GL_FALSE, &camera.MVPMatrix()[0][0]);

                glBindVertexArray(vao);
                glDrawArrays(GL_TRIANGLES, 0, 3);

                window.display();
        }

        window.close();

        return 0;
}

Thanks for your help !
Title: Re: OpenGL: Version 0.0
Post by: ka0s420 on March 23, 2016, 07:12:18 pm
Sounds more like some sort of driver error to me, try updating your graphics card drivers perhaps.
Title: Re: OpenGL: Version 0.0
Post by: herotom99 on March 23, 2016, 07:34:15 pm
I've already updated my drivers :/
My friend has also tried the program and it works (GTX 950m).
Title: Re: OpenGL: Version 0.0
Post by: herotom99 on March 23, 2016, 08:00:06 pm
I have reroll my drivers but it doesn't works then re-updated and nothing ...
Title: AW: OpenGL: Version 0.0
Post by: eXpl0it3r on March 23, 2016, 08:45:15 pm
The only thing I can think of is GLEW screwing something up. Maybe binary1248 will know.
Title: Re: OpenGL: Version 0.0
Post by: binary1248 on March 23, 2016, 09:11:28 pm
What does the string returned when calling glGetString(GL_VERSION) contain?
Title: Re: OpenGL: Version 0.0
Post by: herotom99 on March 23, 2016, 10:10:57 pm
It just crash on this line (with debug mode) so I have nothing.

By the way, I have made a total clean up of my card drivers and the problem still here.
So, I think drivers are not the problem or the installation is always corrupted.
Title: Re: OpenGL: Version 0.0
Post by: binary1248 on March 23, 2016, 10:14:15 pm
Call it without GLEW around... just with an SFML window. GLEW causes it to crash if it can't load functions.
Title: Re: OpenGL: Version 0.0
Post by: herotom99 on March 23, 2016, 10:24:13 pm
Hum... I don't understand I can't call this function without glew:

Error   1   error LNK2019: unresolved external symbol __imp__glGetString@4 referenced in function _main   


I can't call this function because I need an OpenGL Context and it is the problem.
And I use a char*, it return NULL :/
Title: AW: OpenGL: Version 0.0
Post by: eXpl0it3r on March 24, 2016, 08:00:04 am
Do you link OpenGL?
Title: Re: OpenGL: Version 0.0
Post by: herotom99 on March 24, 2016, 03:35:26 pm
I think this is what you want:
https://gyazo.com/def7cb3534693548320471bb2e6483ad

and I am using the opengl32.dll


#include <iostream>
#include <string>

#include "GL\glew.h"

#include "SFML\OpenGL.hpp"
#include "SFML\Graphics.hpp"
#include "SFML\Window.hpp"

#include "glm\gtx\transform.hpp"
Title: Re: OpenGL: Version 0.0
Post by: binary1248 on March 24, 2016, 07:55:55 pm
You shouldn't include both SFML/OpenGL.hpp and GL/GLEW.h at the same time. You include either one or the other, and your choice will also determine what libraries you have to link against. In fact, if you had included GL/GLEW.h after SFML/OpenGL.hpp, it would have detected multiple OpenGL includes and not allowed you to compile.

Remove all traces of GLEW and show us the output of glGetString(GL_VERSION). If it doesn't link properly, then fix the problem and get it to link. It isn't that complicated. Trying to do too many things at the same time makes it harder to find out what went wrong when something does.
Title: Re: OpenGL: Version 0.0
Post by: herotom99 on March 24, 2016, 08:14:34 pm
Hum... Really I don't understand.
I have remove everything about glew.

And it still to return a null pointer ...

#include <iostream>
#include <string>

#include "SFML\OpenGL.hpp"
#include "SFML\Graphics.hpp"
#include "SFML\Window.hpp"

using namespace std;

int main(int argc, char *args[])
{
        sf::RenderWindow(sf::VideoMode(100, 100), "Opengl");

        const char* gl_version = (const char*)(glGetString(GL_VERSION));
        printf("GLVersion: %s\n", gl_version);

        system("pause");

        return 0;
}

Same thing without creating a window.

The result:
https://gyazo.com/37cad4f7696610d7e53712b67a530970

And when I use:
std::cout << glGetString(GL_VERSION) << std::endl;
It just crash :/
Title: Re: OpenGL: Version 0.0
Post by: binary1248 on March 24, 2016, 08:28:44 pm
This means that OpenGL simply isn't available in the required form on this specific machine. What is the exact version of the Nvidia driver you installed? Is this a desktop or laptop?
Title: Re: OpenGL: Version 0.0
Post by: herotom99 on March 24, 2016, 08:31:56 pm
It is a Desktop and I have the last nvidia driver: 364.51
Title: Re: OpenGL: Version 0.0
Post by: herotom99 on March 24, 2016, 08:36:41 pm
When go in the files drivers I have (about OpenGL):

For 32 bits:
-NvIFROpenGL.dll  (version: 10.18.13.6451)
-OpenCL.dll (version: 1.2.11.0)
-nvopencl.dll (version: 6.14.13.6451)

And 64 bits:
-OpenCL64.dll (version: 1.2.11.0)
-nvopencl.dll (version: 6.14.13.6451)

I don't know if it can help
Title: Re: OpenGL: Version 0.0
Post by: binary1248 on March 24, 2016, 08:40:11 pm
According to "the internet" e.g. here (https://www.reddit.com/r/gamedev/comments/4am0il/possible_bug_in_nvidia_36451_driver/), 364.51 seems to have a bunch of bugs in it... Try reverting to an older more stable driver and trying again.
Title: Re: OpenGL: Version 0.0
Post by: herotom99 on March 24, 2016, 08:42:21 pm
I have already tried to rollback the driver to the previous but it doesn't work, I will try to use a "more" old driver.
Title: Re: OpenGL: Version 0.0
Post by: herotom99 on March 24, 2016, 10:16:30 pm
I have installed different drivers:
-362.00
-361.91
-358.50
then come back to 364.51 but it doesn't works.
Title: Re: OpenGL: Version 0.0
Post by: herotom99 on March 24, 2016, 11:07:50 pm
I have downloaded OpenGL Extensions Viewer, make a complete test and there is no problem to create a context 4.4. It's very stange. I think it's not a problem of driver because everything else works...
Title: Re: OpenGL: Version 0.0
Post by: binary1248 on March 24, 2016, 11:20:04 pm
You never mentioned what version of SFML you are using... a lot of these kinds of bugs have been fixed by now.
Title: Re: OpenGL: Version 0.0
Post by: herotom99 on March 24, 2016, 11:23:42 pm
SFML 2.3.2 Visual Studio 2013 32bits
I think it's the last version
Title: Re: OpenGL: Version 0.0
Post by: herotom99 on March 24, 2016, 11:56:26 pm
Another thing, I have tried the OpenGL example in the "examples" file.
It works and I tried to recreate the program with the "OpenGL.cpp". It compiled
but it crashs when I launch the program.
It spams "Failed to activate the window's context"
Title: Re: OpenGL: Version 0.0
Post by: binary1248 on March 25, 2016, 12:39:26 am
That means that the error has something to do with how you build your code. Double-check everything again. Don't assume that something isn't a problem just because it does not lead to any obvious effects.
Title: Re: OpenGL: Version 0.0
Post by: herotom99 on March 25, 2016, 10:39:49 am
I found the problem !

It was about my opengl32.dll
I used an old .dll because it was the same on my laptop.
I took the opengl32.dll in C:/Windows/system32/ and now it work !

I have also tried to use the "new" .dll on my laptop to be sure that I can switch between two pc without having to change the .dll and it looks to works correctly.

Thanks a lot for your help and your time !
You are awesome (first meaning)  :D !
Title: AW: OpenGL: Version 0.0
Post by: eXpl0it3r on March 25, 2016, 02:02:09 pm
Don't copy the OpenGL DLL. It gets installed by your driver and will automatically be available on your system...