Sign in to follow this  
tom_mai78101

Graphics card vendor OpenGL drivers: How do you create an OpenGL context?

Recommended Posts

tom_mai78101    693
I am looking for a guide on implementing OpenGL with versions larger than what Visual Studios has provided. In Visual Studios, you get OpenGL 1.1.

I am using Nvidia Geforce 640, but I am assuming that I may want to learn about creating OpenGL context on AMD and Intel. I do know that Geforce 6XX supports OpenGL 4.4, according to the Nvidia specs.

On the Nvidia site, I see that they provided the OpenGL 4.4 specs and driver, along with the latest include header files. But they don't provide any info on what default OpenGL context they meant for my programs to use GL 4.4, let alone anything above GL 1.1.

I do have a few questions:

1. Calling the default OpenGL context automatically tells the graphic card driver to instantiate an OpenGL context that supports from 1.2 and up?

2. If I were to use a library that supports OpenGL context creation, such as SDL, how would I create an OpenGL context from the library that supports OpenGL 1.2 all the way to OpenGL 4.4 (in this case, from SDL itself)?

3. How do I create an OpenGL context that supports 1.2 and up, without relying on extensions such as FreeGLUT and GLEW? This is for learning purposes and understanding the fundamental C++ and C implementations, not for game development.

4. As above per #3, where can I view an example code?

Thanks in advance.

Share this post


Link to post
Share on other sites
slicer4ever    6760
if you want a light-weight extension library, i'd recommend grabbing http://www.opengl.org/sdk/libs/GLee/ it's sole purpose is automatically finding all the appropriate GL function pointers, and does all the work without having to do anything but include it. note: that link claims all upto 3.0, but if you do a bit of googling, you can find a version that has everything upto 4.x. i forget where i found that, so i can't toss you a link. Edited by slicer4ever

Share this post


Link to post
Share on other sites
arka80    1959

You have to use glew.

 

It's a simple to use library. Just include and link and use #include<gl/glew.h> instead of traditional #include <gl/gl.h>, and the lib will do the magic for you, so that you can simply write glGenBuffers (for example).

Share this post


Link to post
Share on other sites
richardurich    1352

I am looking for a guide on implementing OpenGL with versions larger than what Visual Studios has provided. In Visual Studios, you get OpenGL 1.1.

I am using Nvidia Geforce 640, but I am assuming that I may want to learn about creating OpenGL context on AMD and Intel. I do know that Geforce 6XX supports OpenGL 4.4, according to the Nvidia specs.

On the Nvidia site, I see that they provided the OpenGL 4.4 specs and driver, along with the latest include header files. But they don't provide any info on what default OpenGL context they meant for my programs to use GL 4.4, let alone anything above GL 1.1.

I do have a few questions:

1. Calling the default OpenGL context automatically tells the graphic card driver to instantiate an OpenGL context that supports from 1.2 and up?

2. If I were to use a library that supports OpenGL context creation, such as SDL, how would I create an OpenGL context from the library that supports OpenGL 1.2 all the way to OpenGL 4.4 (in this case, from SDL itself)?

3. How do I create an OpenGL context that supports 1.2 and up, without relying on extensions such as FreeGLUT and GLEW? This is for learning purposes and understanding the fundamental C++ and C implementations, not for game development.

4. As above per #3, where can I view an example code?

Thanks in advance.

1. No clue what the default behavior is. You should explicitly state the version you want your code to use. The way to do this varies depending on what you're using. See (2) for SDL approach.

 

2. For SDL:

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 4);

SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); //COMPATIBILITY instead of CORE if you really, really want to use old versions (you probably don't!)

 

You do that after SDL_Init() and before SDL_GL_CreateContext().

 

3. http://www.opengl.org/wiki/OpenGL_Loading_Library lists various options (including glew). You could also hand-code each call individually. I think the Rastertek tutorials take that approach. It's an incredible waste of time to do it that way though, especially if you ever have to track down a typo.

 

4. Rastertek tutorials show the manual approach (linked in 3). glew and equivalents have the headers to view.

Share this post


Link to post
Share on other sites
powly k    657

For 1: the default context is a compatibility profile, it should let you mix up any and all OpenGL extensions and versions your graphics card supports. This often makes writing it less nice; I'd recommend to stick to either the core 3.3 or 4.3 profiles, depending on what hardware you have. That way you'll have way less driver dependent behaviour to debug.

Share this post


Link to post
Share on other sites
tom_mai78101    693


You could also hand-code each call individually. I think the Rastertek tutorials take that approach. It's an incredible waste of time to do it that way though, especially if you ever have to track down a typo.

 

It's exactly relevant to my learning purposes. I would rather waste my time learning these during my retirement and not having to use the libraries and still not knowing how to do them before I die.

 


For 1: the default context is a compatibility profile, it should let you mix up any and all OpenGL extensions and versions your graphics card supports. This often makes writing it less nice; I'd recommend to stick to either the core 3.3 or 4.3 profiles, depending on what hardware you have. That way you'll have way less driver dependent behaviour to debug.

 

Duly noted.

Share this post


Link to post
Share on other sites
BitMaster    8651

You could also hand-code each call individually. I think the Rastertek tutorials take that approach. It's an incredible waste of time to do it that way though, especially if you ever have to track down a typo.

 
It's exactly relevant to my learning purposes. I would rather waste my time learning these during my retirement and not having to use the libraries and still not knowing how to do them before I die.


If you want to know 'how it works', you should do it by querying exactly one function by hand. Querying one or querying thousands makes no difference. The concept is always the same. It's just tedious, lengthy and error-prone without gaining even a teeny tiny bit more knowledge.

If you wanted something slightly more interesting, you could write a tool which parses an input glext.h header and produces the querying code automatically, as it is done in GLEW.

Personally, I would not do either because there are so many interesting problems with far more learning opportunities around.

Share this post


Link to post
Share on other sites
tom_mai78101    693

Thanks for sharing your thoughts.

 

But I have encountered something anew. I have been following RasterTek's tutorial on OpenGL 4.0 up to Lesson 3, just after where I used #pragma to link to opengl32.lib. After that, I get confused as to how to get OpenGL 1.2 and above inside my header file.

  1. Do I really have to create (or rather, copy) the list of typedefs in the tutorial?
  2. Can't I just link to some Nvidia LIB file located somewhere in the drivers folder?
  3. Do I also have to include the latest include header file from Nvidia's Developers Site in order to unlock OpenGL 1.2 and up?

I never thought that creating a simple OpenGL context need to have relied upon copy/pasting so many typedef in the header file.

Share this post


Link to post
Share on other sites
BitMaster    8651

Do I really have to create (or rather, copy) the list of typedefs in the tutorial?

Yes.

Can't I just link to some Nvidia LIB file located somewhere in the drivers folder?

Nvidia has nothing to do with it. If such a lib existed, it would have to come from opengl.org to be any use.

Do I also have to include the latest include header file from Nvidia's Developers Site in order to unlock OpenGL 1.2 and up?

Again, this has nothing to do with Nvidia. You would need a header file/extension description which contains the feature you are interested in. You do not need the latest whatever.

I never thought that creating a simple OpenGL context need to have relied upon copy/pasting so many typedef in the header file.

This is purely a Windows problem. Microsoft requires all OpenGL implementation to stick to OpenGL 1.1. Anything above that has to be queried by the extension mechanism.
Exactly because that is a lot of boring work with a high potential for errors, libraries like GLEW exist. GLEW is a very simple library with a very permissive license.

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