Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How to include the SFML intern GLEW header  (Read 5436 times)

0 Members and 1 Guest are viewing this topic.

sharethis

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
How to include the SFML intern GLEW header
« on: January 14, 2013, 05:25:33 pm »
Hello, I am developing a OpenGL application using SFML for some months now.

Since now I used a "sf::Window" and included my own GLEW library and header file to draw OpenGL stuff. Trying to use SFML's two dimensional drawing capabilities (want to draw debug messaged using "sf::Text"), I found out that I have to use "sf::RenderWindow" instead of "sf::Window" because I need "pushGLStates()" and "popGLStates()".

After removing my own GLEW library from the linker includes, I got my project to compile and run as expected. But I am still using my own GLEW header file "#include <GLEW/glew.h>". How can I include the GLEW file shipped with SFML in my own files? What I mean is something like "#include <SFML/.../glew.h>".

The reason that I do not prefer using my own GLEW header file is for consistency and because that might be from another release and version of GLEW. By the way I already included "#include <SFML/OpenGL.hpp>" but that does not provide functions like "glUniformMatrix4fv", "glEnableVertexAttribArray", "glBindBuffer", and others.

It would be nice if there is an easy way to access the SFML internal GLEW header file because that would provide every SFML user the most simple way to directly start developing OpenGL applications without struggling with GLEW. Moreover I heard that beginners ofter fail to properly include GLEW in SFML. So if there is no such feature yet, you might consider implementing that, that would be awesome! Why should GLEW be included multiple times in the same project?

If I am on the wrong path, please tell how I can use both SFML drawing and my own OpenGL drawing. Thanks a lot in advance!
« Last Edit: January 14, 2013, 05:35:14 pm by sharethis »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: How to include the SFML intern GLEW header
« Reply #1 on: January 14, 2013, 05:48:54 pm »
You can easily add /path/to/SFML-root/extlibs/headers to the include directory of your compiler/IDE and then just call #include <glew/glew.h>
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

sharethis

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: How to include the SFML intern GLEW header
« Reply #2 on: January 14, 2013, 06:25:26 pm »
Why not include the GLEW headers in the "SFML/OpenGL.hpp" header?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: How to include the SFML intern GLEW header
« Reply #3 on: January 14, 2013, 06:27:55 pm »
Why not include the GLEW headers in the "SFML/OpenGL.hpp" header?
Because not everyone who uses OpenGL wants to use GLEW? ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

sharethis

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: How to include the SFML intern GLEW header
« Reply #4 on: January 14, 2013, 06:38:15 pm »
Because not everyone who uses OpenGL wants to use GLEW? ;)

No? Okay. ;-)

I got it to compile but now I face another problem. My OpenGL scene is drawn fine but no text is displayed and there is an error message from SFML which reads "An internal OpenGL call failed in RendererTarger.cpp (255) : GL_INVALID_OPERATION, the specified operation is not allowed in the current state".

My code is as follows.

Font font;

void Init()
{
        bool result = font.loadFromFile("other/verdana.ttf");
}

void Update()
{
        auto wnd = ...; // get pointer to the RenderWindow

        wnd->pushGLStates();

        Text text("Test", font, 15);
        wnd->draw(text);

        wnd->popGLStates();
}

Font loading is successful so I do not know how to fix that. Do you have any idea?

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: How to include the SFML intern GLEW header
« Reply #5 on: January 14, 2013, 06:42:15 pm »
Why not include the GLEW headers in the "SFML/OpenGL.hpp" header?
So that evil Laurent™ can make SFGUI run into even more problems with GLEW withing SFML and force them to use GLee. ;D
Back to C++ gamedev with SFML in May 2023

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: How to include the SFML intern GLEW header
« Reply #6 on: January 14, 2013, 06:51:13 pm »
So that evil Laurent™ can make SFGUI run into even more problems with GLEW withing SFML and force them to use GLee. ;D
That's a whole different problem... ;)

Font loading is successful so I do not know how to fix that. Do you have any idea?
That small snippet of code won't help us understand what you're doing. A complete and minimal example is needed. ;)

From the snippet I can deduce though: Don't use global SFML resources or any globals at all, instead use class to encapsulate everything nicely.
With a class you also won't need an Init function, since you get a constructor who's job it is to initialize all member objects.
Don't use pointers when you can use reference.

Over all your coding style looks heavily influenced by C. Not sure if you intend to go the C way, but I personally would advice to get a good understanding of C++, because it's a bit cleaner and you can come around quite a few problems, that you can't do with C or C-like style. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Re: How to include the SFML intern GLEW header
« Reply #7 on: January 15, 2013, 11:35:06 am »
Why not include the GLEW headers in the "SFML/OpenGL.hpp" header?
So that evil Laurent™ can make SFGUI run into even more problems with GLEW withing SFML and force them to use GLee. ;D
lol ;)

Actually, for the FlexWorld game, eXpl0it3r and me were able to workaround the problems with multiple GLEW linkings. Just follow 2 simple rules:

1) On Linux, do not, never ever, link to external libraries when building a library yourself (e.g. SFML shouldn't link to OpenGL, OpenAL, GLEW and all the other dependencies itself; both for shared and static builds). Instead, delegate that to the final executable/user. On Windows it doesn't matter, because Laurent does not export GLEW's symbols, so shared and static builds are safe.
2) glewInit() yourself before SFML has the chance to. ;)

I will soon try to adapt that for SFGUI and see how things work out. To be honest, I really would like to replace the ugly GLee by the shiny GLEW. ;)