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'
5
  • Which error do you get? What is it that is not working? Do you have a valid OpenGL context? Commented Jan 23, 2019 at 13:24
  • Sorry, I posted the error in the edit Commented Jan 23, 2019 at 13:39
  • @BobTheTreeGod see wglext - extension not installed in OpenGL context 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 Commented Jan 23, 2019 at 13:47
  • Seems to work now with ifndef Commented Jan 23, 2019 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 ... Commented Jan 24, 2019 at 9:30

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.