Skip to main content
GameDev.net gamedev.net
🔒 Locked

Configure Visual Studio 2010 from ogl 1.1 to ogl 3.x or 4.x

Started by Kurt_duncan Jul 29, 2012 at 3:02 PM 7 replies 3.6k views
Original Post
Kurt_duncan
Kurt_duncan
Hello experts,

I learned a bit opengl on version 1.1 . I want to upgrade my knowledge to actual versions but i am facing the first (stupid) problem on that. I am using Visual Studio C++ 2010 on a Windows 7 x64. My graphics card is a nvidia gt540M with latest driver. Well, on my visual studio i only found version 1.1 of opengl under include/GL/ . The gl.h is from the last century, and i think that libopengl32.lib is too. I spent last day looking for how to configure visual studio to use latest opengl versions, but i wasn't able to achieve it.

Please, could someone explain how to get latest gl.h and opengl libraries and configure visual studio to start with latest versions?

Thanks in advance!
Brother Bob
Brother Bob
There are no newer files, but you don't need any either. You can see pretty much any tutorial on OpenGL that has anything to do with version 1.2 or later. It will describe how to access later versions.
Kurt_duncan
Kurt_duncan
Thanks for your fast reply Brother Bob!

I was trying to find a tutorial explaining me how to do that, but they seem to be hidden from me. Please, could you paste any resource explaining how to setup visual studio to use opengl 3.x or 4.x ?

Thanks in advance!
beans222
beans222
Anything beyond 1.1 you need to query the function pointer through wglGetProcAddress. Using the library called GLEW is a fairly popular choice for gaining access to newer GL functions with minimal work on your part. If you search for GLEW, you'll likely find other libraries that would work just as well.
New C/C++ Build Tool 'Stir' (doesn't just generate Makefiles, it does the build): https://github.com/space222/stir  
Brother Bob
Brother Bob
You seem to be talking about two things; using anything beyond version 1.1, and using the features in the modern api (version 3 and later). The former should be in any tutorial (see the first tutorials at nehe.gamedev.net). For tutorials on the modern api you can check the links in the getting started box in the OpenGL subforum. Note that you need the former to do the latter since you will run into the same problems in both cases.
Kurt_duncan
Kurt_duncan
Thanks to you too beans222.
I downloaded glew 1.8 and i am trying to see this code:

[source lang="cpp"]#include
#include
#include


using namespace std;

void main(int argc, char** argv)
{
if(glGetString(GL_VERSION) == NULL){
GLenum glError = glGetError();
cout << glError;
}
else{

string version( (const char*)glGetString(GL_VERSION) );
cout << version.data();
}
}[/source]

But i am getting error 1282, invalid operation. It seems that it is because opengl context it is not setted up. How i can do that?

Brother Bob, the nehe tutorials that i saw, are based on opengl 1.1 and they are, in my opinion, very good but very old. When i ask you before about a tutorial, i was thinking on a tutorial that explains how to configure visual studio to uses latest versions of opengl.

Has Glew an implementation of latest versions of opengl or how it works to get functions work? I told that because although i am getting error 1282, visual studio finds functions that are part of latest versions! Like glDrawElements, for example.

Thanks for everything.
beans222
beans222
You need to create a context like you were doing before in order for glew to be able to set up all the function pointers (it just calls wglGetProcAddress *a lot*). Then, you use some of the function pointers glew set up to get a GL3 context.
See this (under "Proper Context Creation"): http://www.opengl.org/wiki/Creating_an_OpenGL_Context

ps. All you need for glew to work is a context and then call glewInit
New C/C++ Build Tool 'Stir' (doesn't just generate Makefiles, it does the build): https://github.com/space222/stir  
slicer4ever
slicer4ever
I'd recommend using Glee http://www.opengl.org/sdk/libs/GLee/ for extension managment in windows, it'll get everything upto 3.0 standards, and relieves the headache of having to setup correct function pointers when you have a valid openGL context, as well makes it easy to determine what openGL version the system is using, and what extensions are supported.
Neilo
Neilo

Thanks to you too beans222.
I downloaded glew 1.8 and i am trying to see this code:

[source lang="cpp"]#include
#include
#include


using namespace std;

void main(int argc, char** argv)
{
if(glGetString(GL_VERSION) == NULL){
GLenum glError = glGetError();
cout << glError;
}
else{

string version( (const char*)glGetString(GL_VERSION) );
cout << version.data();
}
}[/source]

But i am getting error 1282, invalid operation. It seems that it is because opengl context it is not setted up. How i can do that?

Brother Bob, the nehe tutorials that i saw, are based on opengl 1.1 and they are, in my opinion, very good but very old. When i ask you before about a tutorial, i was thinking on a tutorial that explains how to configure visual studio to uses latest versions of opengl.

Has Glew an implementation of latest versions of opengl or how it works to get functions work? I told that because although i am getting error 1282, visual studio finds functions that are part of latest versions! Like glDrawElements, for example.

Thanks for everything.


You need to init GLEW before you do anything...

int kContextFlags = WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
#ifdef _DEBUG
| WGL_CONTEXT_DEBUG_BIT_ARB;
#else
;
#endif
bool Device::Initialize(HWND window)
{
// TODO: assert window is valid, make sure get a valid device context also
this->window = window;
deviceContext = ::GetDC(this->window);
PIXELFORMATDESCRIPTOR pfd = { 0 };
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 32;
pfd.iLayerType = PFD_MAIN_PLANE;
int pixelFormat = ::ChoosePixelFormat(deviceContext, &pfd);
if(pixelFormat == 0)
{
return false;
}
if(SetPixelFormat(deviceContext, pixelFormat, &pfd) == FALSE)
{
return false;
}
HGLRC tempContext = ::wglCreateContext(deviceContext);
::wglMakeCurrent(deviceContext, tempContext);
GLenum result = glewInit();
if(result != GLEW_OK)
{
return false;
}
if(wglewIsSupported("WGL_ARB_create_context") == 1)
{
renderingContext = ::wglCreateContextAttribsARB(deviceContext, NULL, kOpenGLAttribs);
BOOL success = ::wglMakeCurrent(NULL, NULL);
::wglDeleteContext(tempContext);
::wglMakeCurrent(deviceContext, renderingContext);
wglSwapIntervalEXT(1);
SetupDebugOutput();
}
else
{
//renderingContext = tempContext;
return false;
}
GLenum error = glGetError();
glGetIntegerv(GL_MAJOR_VERSION, &OpenGLVersion[0]);
glGetIntegerv(GL_MINOR_VERSION, &OpenGLVersion[1]);
return error == GL_NO_ERROR;
}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.