Using OpenGL in VC++

Hello all,

I was having issues with OpenGL in VC++, so I created the following simple test files and tested them under Dev-C++, which I previously had always used:

GLClass.h:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#ifndef MY_GL_CLASS_H
#define MY_GL_CLASS_H

#include <gl/gl.h>

class GLClass {

protected:
    GLfloat f;

public:
    GLClass(float value) : f(value) {}
    GLfloat doSomeStuff() const;
};

#endif //MY_GL_CLASS_H 


GLClass.cpp:
1
2
3
4
5
6
7
8
9
10
#include "GLClass.h"

GLfloat GLClass::doSomeStuff() const  {
	
    //Do some random pointless math
	GLfloat x = f - 3.0f;
	GLfloat y = f * 99.0f;
	return x / y;
	
}


main.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include "GLClass.h"
using namespace std;

int main() {
    
    GLClass myClass(1.0f);
    cout << myClass.doSomeStuff();
    
    cin.get();
    return 0;
    
}


In Dev-C++, I simply add '-lopengl32' to linker command line options, under 'Compiler Options'.

In VC++, I added 'opengl32.lib', under Properties->ConfigurationProperties->Linker->Input->Additional Dependencies. Is that not the correct thing to do? I get a list of 143 errors, the first few of which are shown below:

error C2144: syntax error : 'void' should be preceded by ';'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2146: syntax error : missing ';' before identifier 'glAccum'
error C2182: 'APIENTRY' : illegal use of type 'void'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2144: syntax error : 'void' should be preceded by ';'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2086: 'int WINGDIAPI' : redefinition


I'm sure this is just something simple about VC++ that I don't properly understand. Any help is greatly appreciated!
The VS OpenGL libraries appear to be Windows dependant. You will need to include windows.h before including OpenGL headers:

1
2
3
4
5
#ifdef _MSC_VER   // if the compiler is MSVS
#  include <windows.h>
#endif

// .. include GL or other headers here 
The errros are in the gl.h file(s). They use WINAPI, APIENTRY, and other macros defined in windows.h

Whether or not your gl.h has them depends entrely on the disribution/library you're using. For many versions of VS (all of the ones I've used) the GL lib comes as described above.

If you're not using VS or if you reinstalled OpenGL from another source, then you probably wouldn't have this problem.
Thank you. That appears to have done it. Problem solved.
Topic archived. No new replies allowed.