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

Author Topic: SFML/OpenGL.hpp doesn't need Windows.h  (Read 3844 times)

0 Members and 1 Guest are viewing this topic.

vanisher

  • Newbie
  • *
  • Posts: 7
    • View Profile
SFML/OpenGL.hpp doesn't need Windows.h
« on: August 30, 2011, 11:56:44 am »
Please do not include Windows.h in <SFML/OpenGL.hpp>.

The intention of the header file is good (different include GL path on MacOS), but i won't let Windows.h sneak into all my sources, as they are 100% Windows-clean. Windows.h is huge, and the GL includes don't need any of it.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML/OpenGL.hpp doesn't need Windows.h
« Reply #1 on: August 30, 2011, 12:02:58 pm »
They do, GL.h on Windows uses macros defined in windows.h such as APIENTRY. You can't use OpenGL on Windows without windows.h included first -- try it if you're not convinced ;)

But maybe I could be more precise and find which minimal set of Windows headers are needed rather than including the big windows.h. This requires further investigation.
Laurent Gomila - SFML developer

vanisher

  • Newbie
  • *
  • Posts: 7
    • View Profile
SFML/OpenGL.hpp doesn't need Windows.h
« Reply #2 on: August 30, 2011, 07:46:20 pm »
Quote from: Laurent
They do, GL.h on Windows uses macros defined in windows.h such as APIENTRY. You can't use OpenGL on Windows without windows.h included first -- try it if you're not convinced ;)

Heres what my gl.h looks like:

#if !defined(APIENTRY)
#  if defined(__WIN32__)
#    define APIENTRY __stdcall
#  else
#    define APIENTRY
#  endif
#endif

My sourcecode:

#include <GL/gl.h>

int main(void)
{
  //DWORD nothing;  // error: DWORD not defined

  glIndexi(1);
  return(0);
}

> g++ -o test.exe main.cpp -lOpenGL32

...compiles fine only if the DWORD line stays commented.

Maybe we got a different gl.h header?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML/OpenGL.hpp doesn't need Windows.h
« Reply #3 on: August 30, 2011, 08:54:43 pm »
Quote
Maybe we got a different gl.h header?

Yes, mine doesn't define APIENTRY nor WINGDIAPI, and triggers compile errors if included alone.

I don't know if it would be 100% safe to include Windows headers only with VC++. This would require further investigation too :)
Laurent Gomila - SFML developer

vanisher

  • Newbie
  • *
  • Posts: 7
    • View Profile
SFML/OpenGL.hpp doesn't need Windows.h
« Reply #4 on: August 30, 2011, 10:40:38 pm »
Quote from: "Laurent"
Quote
Maybe we got a different gl.h header?

Yes, mine doesn't define APIENTRY nor WINGDIAPI, and triggers compile errors if included alone.


Poor MSC users then... :P

Bottom line is, this issue applies to MinGW users.

Btw., MinGW could be identified by checking:

#ifndef __MINGW32__
  #include <Windows.h>
#endif // __MINGW32__

Cheers.