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

Author Topic: Using GLEW with SFML  (Read 19917 times)

0 Members and 1 Guest are viewing this topic.

sharethis

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Using GLEW with SFML
« on: November 19, 2012, 05:18:42 pm »
I am working on my first bigger game. After a long conceptual period of time I come up with a appropriate architecture design. Now I try to implement the basic components. The window component is finished now and the renderer component comes next.

What I need for the renderer is OpenGL and as I read here, an extension wrapper like GLEW.

I am struggling with including and initializing GLEW.

#define GLEW_STATIC
#include <glew/glew.h>

glewExperimental = GL_TRUE;
glewInit();

I correctly added GLEW header and library to the project. Without the glewInit() my code compiles. The error message reads as follows. In English it means that there are several symbols defined multiple times. So the problem is that some GLEW constants also are defined somewhere else. My assumption is that SFML/Window.cpp could do that. Because that is the only SFML header I include for now, except of SFML/OpenGL.cpp which definitely stays after the GLEW include.

Quote
Fehler 2516 error LNK1169: Mindestens ein mehrfach definiertes Symbol gefunden.
Fehler 1945 error LNK2005: ___GLEW_3DFX_multisample ist bereits in sfml-graphics-s-d.lib(glew.obj) definiert.
Fehler 1946 error LNK2005: ___GLEW_3DFX_tbuffer ist bereits in sfml-graphics-s-d.lib(glew.obj) definiert.
Fehler 1947 error LNK2005: ___GLEW_3DFX_texture_compression_FXT1 ist bereits in sfml-graphics-s-d.lib(glew.obj) definiert.
...
Fehler 2466 error LNK2005: ___wglewWaitForSbcOML ist bereits in sfml-graphics-s-d.lib(glew.obj) definiert.
Fehler 2514 error LNK2005: _glewExperimental ist bereits in sfml-graphics-s-d.lib(glew.obj) definiert.

My architecture is complicated to explain, because it isn't a common solution but my own invention.

Facts: Windows 8, Visual Studio 11, OpenGL 3.0+, SFML 2.0 RC (static linked), GLEW newest
« Last Edit: November 19, 2012, 07:26:40 pm by sharethis »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Using GLEW with SFML
« Reply #1 on: November 19, 2012, 06:05:57 pm »
SFML comes with it's own GLEW version and already initializes it, so afaik you don't/shouldn't try to init it again.
Then there's the problem when you want to use your own GLEW version described here...
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: Using GLEW with SFML
« Reply #2 on: November 19, 2012, 06:58:07 pm »
SFML comes with it's own GLEW version and already initializes it, so afaik you don't/shouldn't try to init it again.

Why can't I use glGenBuffers() or glGenVertexArrays() then? I took a look into SFML/OpenGL.hpp and it doesn't include an extension wrapper.

What do I need to include to use the built in version of GLEW?

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Using GLEW with SFML
« Reply #3 on: November 19, 2012, 07:15:52 pm »
I don't know anything about opengl but there's that in the tutorials:
http://www.sfml-dev.org/tutorials/2.0/window-opengl.php
Quote
#include <SFML/OpenGL.hpp>

This header includes OpenGL and GLU functions, and nothing else. People sometimes think that SFML automatically includes GLEW (a library which manages OpenGL extensions) because it uses it internally, but it's only an implementation detail. From the user's point of view, GLEW must be handled like any other extra library.
Back to C++ gamedev with SFML in May 2023

sharethis

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: Using GLEW with SFML
« Reply #4 on: November 19, 2012, 07:23:24 pm »
Thank you, so why do I face the compiler error then?

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Using GLEW with SFML
« Reply #5 on: November 19, 2012, 07:33:43 pm »
You said you only added lib and includes of glew and I don't know opengl so I can only guess:
Quote
You will then need to link your program to the OpenGL library. Unlike what it does with the headers, SFML can't provide a unified way of linking OpenGL. Therefore, you need to know which library to link to according to what OS you're using ("opengl32" on Windows, "GL" on Linux, etc.). Same thing for GLU, in case you use it too: "glu32" on Windows, "GLU" on Linux, etc.
Back to C++ gamedev with SFML in May 2023

sharethis

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: Using GLEW with SFML
« Reply #6 on: November 19, 2012, 07:48:51 pm »
This is the error message.

Quote
fatal error LNK1169: one or more multiply defined symbols found

I exactly get 2515 of these errors. I thought it could be a namespace conflict but even without "using namespace sf;" I get the same errors.

I also added the OpenGL and Glu libraries but that didn't help.
« Last Edit: November 19, 2012, 08:14:58 pm by sharethis »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Using GLEW with SFML
« Reply #7 on: November 19, 2012, 08:48:31 pm »
If you link SFML statically, you mustn't link GLEW, because the SFML static libraries already contain it. It has already been debated and it may change in the future.
Laurent Gomila - SFML developer

sharethis

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: Using GLEW with SFML
« Reply #8 on: November 19, 2012, 11:01:00 pm »
If you link SFML statically, you mustn't link GLEW, because the SFML static libraries already contain it. It has already been debated and it may change in the future.

Which header file would I need then? It doesn't work with the header of the lastest GLEW release.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Using GLEW with SFML
« Reply #9 on: November 19, 2012, 11:06:07 pm »
Quote
Which header file would I need then?
It's not a header problem.

If you don't link GLEW yourself, you shouldn't have the same errors as before.
Laurent Gomila - SFML developer

sharethis

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: Using GLEW with SFML
« Reply #10 on: November 19, 2012, 11:10:00 pm »
If you don't link GLEW yourself, you shouldn't have the same errors as before.

That is right, now I have a unresolved external symbol error. Alle the other linker errors are gone.

Quote
error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "_glewInit@0" in Funktion ""private: virtual void __thiscall ComponentRenderer::Init(void)" (?Init@ComponentRenderer@@EAEXXZ)".

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Using GLEW with SFML
« Reply #11 on: November 19, 2012, 11:14:53 pm »
Strange, I don't know why it can't find glewInit.
Laurent Gomila - SFML developer

sharethis

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: Using GLEW with SFML
« Reply #12 on: November 19, 2012, 11:20:01 pm »
These are the headers I included.

#define GLEW_STATIC
#include <GLEW/glew.h>
#include <SFML/OpenGL.hpp>
#include <SFML/Window.hpp>

My initialization call looks like that.

glewExperimental = GL_TRUE;
glewInit();

And I linked the following libraries to the Visual Studio project. (debug, release)

sfml-window-s-d.lib
sfml-graphics-s-d.lib
sfml-system-s-d.lib
sfml-window-s.lib
sfml-graphics-s.lib
sfml-system-s.lib

Do you need additional informations?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Using GLEW with SFML
« Reply #13 on: November 19, 2012, 11:28:37 pm »
Quote
Do you need additional informations?
Nop ;)

Can you try to use the GLEW header which is shipped with SFML?
Laurent Gomila - SFML developer

sharethis

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: Using GLEW with SFML
« Reply #14 on: November 19, 2012, 11:31:35 pm »
Can you try to use the GLEW header which is shipped with SFML?

This is what I wanted to do but I do not find that file.

Update: I got it working now!

What I did was to link to the new glew32s.lib first, and then to the SFML libs.

glew32s.lib
sfml-window-s.lib
sfml-graphics-s.lib
sfml-system-s.lib
« Last Edit: November 19, 2012, 11:38:16 pm by sharethis »

 

anything