Sign in to follow this  
Kurt_duncan

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

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Thanks to you too beans222.
I downloaded glew 1.8 and i am trying to see this code:

[source lang="cpp"]#include <gl/glew.h>
#include <iostream>
#include <stdlib.h>


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.

Share this post


Link to post
Share on other sites
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"): [url="http://www.opengl.org/wiki/Creating_an_OpenGL_Context"]http://www.opengl.org/wiki/Creating_an_OpenGL_Context[/url]

ps. All you need for glew to work is a context and then call glewInit

Share this post


Link to post
Share on other sites
I'd recommend using Glee [url="http://www.opengl.org/sdk/libs/GLee/"]http://www.opengl.org/sdk/libs/GLee/[/url] 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. Edited by slicer4ever

Share this post


Link to post
Share on other sites
[quote name='Kurt_duncan' timestamp='1343582284' post='4964278']
Thanks to you too beans222.
I downloaded glew 1.8 and i am trying to see this code:

[source lang="cpp"]#include <gl/glew.h>
#include <iostream>
#include <stdlib.h>


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.
[/quote]

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

[code]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;
}[/code]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this