开发者

Vertex Buffer Objects with SDL

When using SDL 1.2, what do I need to include to be able to use OpenGL Vertex Buffer Objects (VBOs)?

Currently, I only include SDL.h, SDL_opengl.h, SDL_image.h

And get the errors:

g开发者_C百科lGenBuffersARB, glBindBufferARB, glBufferDataARB not declared in this scope


If you want to use SDL_opengl.h define GL_GLEXT_PROTOTYPES before including it.

#define GL_GLEXT_PROTOTYPES

#include "SDL.h"
#include "SDL_opengl.h"

I may or might not work. If you want to do it the "proper" way, use something like glew.


You should include <GL/gl.h> and <GL/glext.h>. Sometimes OpenGl extension functions are not directly available and must be loaded using SDL_GL_GetProcAddress (this returns the function pointer or 0 if extension is not available). You may be interested to have a look to libglew which loads the extension functions.

Here is how you may do it (if not using glew):

extern PFNGLGENBUFFERSARBPROC glGenBuffers; // Function pointer declaration, in a header file.

// Function pointer initialization
glGenBuffers = 0;

// Get the function (you should have checked that extension is available)
glGenBuffers = (PFNGLGENBUFFERSARBPROC)SDL_GL_GetProcAddress("glGenBuffersARB");


It is possible to get the underdevelopment 1.3 version of SDL to open a OpenGL 3.2 context with a bit of work.

It's also worth checking out SFML, it's similar to SDL but is hardware accelerated for the 2D stuff, object orientated C++ and is much easier to use. OpenGL is particularly simple to use with it. Once again it's the development 2.0 version that supports OpenGL 3.2 contexts (although it's close to being released.)

You will probably need to use the non-ARB versions with the above.


I find the SDL_opengl.h file to be fairly useless. Personally, I recommend using GLEW or GLee. GLee is easier to add to your project but stops at OpenGL 3.0 (usually fine in SDL apps since SDL only enables an OpenGL 2.1 context). GLEW requires just a bit more work but enables stuff up through OpenGL 4.

I ran into this same problem regarding VBOs in SDL.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜