Configure Visual Studio 2010 from ogl 1.1 to ogl 3.x or 4.x
#1 Members - Reputation: 103
Posted 29 July 2012 - 09:02 AM
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!
#3 Members - Reputation: 103
Posted 29 July 2012 - 10:45 AM
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!
#4 Members - Reputation: 674
Posted 29 July 2012 - 10:55 AM
#5 Moderators - Reputation: 4637
Posted 29 July 2012 - 11:01 AM
#6 Members - Reputation: 103
Posted 29 July 2012 - 11:18 AM
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.
#7 Members - Reputation: 674
Posted 29 July 2012 - 12:32 PM
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
#8 Crossbones+ - Reputation: 1450
Posted 29 July 2012 - 02:05 PM
Edited by slicer4ever, 29 July 2012 - 02:07 PM.
#9 Members - Reputation: 284
Posted 30 July 2012 - 08:19 AM
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.
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;
}






