PDA

View Full Version : Using OpenGL without GLEW



Lars Jahr
09-20-2011, 06:07 AM
I'm trying to use OpenGL without the use of glew. The reason is that I want to modify the plotting in octave (a matlab clone) and I run into problems with shared libraries when I try to include GLEW and then compile.

The rendering in the application is now done with deprecated functionality and I want to use OpenGL 3.3 in the parts that I implement. Any ideas on how to manage this? I'm really quite confused on the point of loading functions in OpenGL, usually I've just included glew.h and haven't thought much about what it does. I read the thread http://www.opengl.org/discussion_boards/...;gonew=1#UNREAD (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=303152&gonew=1# UNREAD)
but I'm still not quite sure how I can manage without glew.

Do I have to manually load OpenGL functions? And if yes, are there any examples which shows this? I think I've seen gl code before that doesn't use glew or glXGetProcAddress, how is this possible?

Aleksandar
09-20-2011, 07:52 AM
Do I have to manually load OpenGL functions? And if yes, are there any examples which shows this?
First of all, term "loading extensions" is not adequate. It is in common use, but it is not correct. You have to "grab" pointers to a functions exposed by the driver. Don't worry, it is quite easy.

Take a look at this:
Introduction to Opengl 3.2 (http://sites.google.com/site/opengltutorialsbyaks/introduction-to-opengl-3-2---tutorial-01)
Although it is for Windows, I guess you'll get the basic skills.


I think I've seen gl code before that doesn't use glew or glXGetProcAddress, how is this possible?
On Windows it is possible for GL 1.1 functionality only. GL 1.1 is not exposed through the extensions, but it is a part of WinAPI.

Lars Jahr
09-20-2011, 08:31 AM
Do I have to manually load OpenGL functions? And if yes, are there any examples which shows this?
First of all, term "loading extensions" is not adequate. It is in common use, but it is not correct. You have to "grab" pointers to a functions exposed by the driver. Don't worry, it is quite easy.

Take a look at this:
Introduction to Opengl 3.2 (http://sites.google.com/site/opengltutorialsbyaks/introduction-to-opengl-3-2---tutorial-01)
Although it is for Windows, I guess you'll get the basic skills.

That didn't look too hard, thanks! Things are never easy though, I'm a linux user, so I have a few questions:

Is the #include "stdafx.h" something windows specific?

And are you creating the ogl.h and ogl.cc files in the project folder? I'll give this a go as soon as I'm back at my own computer!

Alfonse Reinheart
09-20-2011, 11:51 AM
This is perhaps a more thorough (http://www.opengl.org/wiki/Load_OpenGL_Functions), platform-neutral discussion of how to do it. Though honestly, if you're having problem linking libraries to your project, you should fix that first.

Aleksandar
09-20-2011, 12:43 PM
Is the #include "stdafx.h" something windows specific?
It is a VS specific pre-compiled header. You don't need it.


And are you creating the ogl.h and ogl.cc files in the project folder?
Yes, but it is not important. ogl.h/.cpp are used just to define global (extern) pointers (i.e. function names) visible from all files/classes.

Basically, you just have to do the following:


#include "glext.h"
#include "glxext.h"

// For each function you need, grab the pointer
PFNGLCREATEPROGRAMPROC glCreateProgram = NULL;
glCreateProgram = (PFNGLCREATEPROGRAMPROC)wglGetProcAddress("glCreateProgram");

If the pointer is NULL, then the extension is not supported.

Also read Alfonse's Wiki. It is well written. Just ignore the second sentence. ;)