0

I don't really know what i'm doing wrong. I'm not using a loading library so I can have more control over my code. I am using windows os.

#include <gl/GL.h>
#include <windows.h>

typedef BOOL(WINAPI wglSwapInterval_t) (int interval);
static wglSwapInterval_t* wglSwapInterval;

#ifndef GLAPI
#define GLAPI extern
#endif

#ifndef APIENTRYP
#define APIENTRYP APIENTRY *
#endif

#define GL_VERTEX_SHADER 0x8B31
#define GL_FRAGMENT_SHADER 0x8B30

typedef GLuint(APIENTRYP PFNGLCREATEPROGRAMPROC) (void);
PFNGLCREATEPROGRAMPROC glCreateProgram = (PFNGLCREATEPROGRAMPROC)wglGetProcAddress("glCreateProgram");

Error:

(5): error C2086: 'wglSwapInterval_t (__stdcall *__stdcall wglSwapInterval)': redefinition
(5): note: see declaration of 'wglSwapInterval'
(19): error C2374: 'glCreateProgram': redefinition; multiple initialization
(19): note: see declaration of 'glCreateProgram'
  • Which error do you get? What is it that is not working? Do you have a valid OpenGL context? – BDL Jan 23 '19 at 13:24
  • Sorry, I posted the error in the edit –  Jan 23 '19 at 13:39
  • @BobTheTreeGod see [wglext - extension not installed in OpenGL context](https://stackoverflow.com/a/36980406/2521214) my bet is you are either doing multiple include of itself (simple `#ifndef xxx #define xxx ... #endif` would repair it) or redefinig something that is already included like `wglSwapInterval_t` – Spektre Jan 23 '19 at 13:47
  • Seems to work now with ifndef –  Jan 23 '19 at 13:53
  • @BobTheTreeGod yep so you are including the file more than once ... I also saw on some platforms (AVR32/GCC) that compiler compile all C or Cpp files in directory so if you are including a C or Cpp file on such its compiled twice ... if you have include of the same file more than once its the same so I usually add `#ifndef XXX ...` where the XXX is the filename encoded as macro token like `_file_h` that way even on multiple include/compile it will compile just once for each separate object ... – Spektre Jan 24 '19 at 09:30

1 Answers1

1
  • Error C2086 says that you have defined wglSwapInterval multiple times.

  • Error C2374 says that you have defined and initialized glCreateProgram multiple times.

The common reason for such problems is including an unguarded .h file more than once in a single .cpp file directly or indirectly (i.e. included in another file which itself is included in the current file).

To avoid such problems, always put #ifndef or #pragma once in your .h files as the include guard.

frogatto
  • 28,539
  • 11
  • 83
  • 129