using OpenGL buffer objects with SDL

Started by
11 comments, last by CodeMunkie 16 years, 2 months ago
hi, I have written an OpenGL application using SDL. Now I'd like to extend my application with pixel buffer objects. However I was not able to compile the code because glGenBuffers/glBindBuffer/glBufferData: identifier not found. I put #define GL_GLEXT_PROTOTYPES in front of #include SDL_OpenGL.h and was able to compile but not link my code because glGenBuffers/glBindBuffer/glBufferData: unresolved external symbol. How can I get this to work ? tahnks, quak
Advertisement
You're using old opengl headers and/or libraries. You'll need to either get updated ones, or use the equivalent extensions.

Unfortunately, I think vs.net doesn't come with up to date opengl libs and headers. Don't quote me on that though.
Use GLee for dealing with OpenGL extensions. It makes life very easy indeed.
"When you die, if you get a choice between going to regular heaven or pie heaven, choose pie heaven. It might be a trick, but if it's not, mmmmmmm, boy."
How to Ask Questions the Smart Way.
Yes, I know about Glee, however if I include the header additionally to my SDL_OpenGL.h I can't compile because of redefinitions. If I comment out these definitions in the SDL header I can compile but gleeInit() fails.
You don't include SDL_OpenGL.h (or gl.h for that matter) if you use GLee. Just include glee.h.
"When you die, if you get a choice between going to regular heaven or pie heaven, choose pie heaven. It might be a trick, but if it's not, mmmmmmm, boy."
How to Ask Questions the Smart Way.
Thanks, that worked. I included GLee.h and GLee.c in my project and I link against OpenGL32.lib. Linking against GLee.lib resulted in a "cannot find LIBC.LIB" error. However, if I use glGenBuffers it returns 0 which is wrong of course. I am using VC Express 2005 by the way.
Quote:However, if I use glGenBuffers it returns 0 which is wrong of course

Maybe, maybe not. You need to query your driver and see which version of OpenGL it exposes. Call glGetString(GL_VERSION) to see the version of OpenGL you are actually dealing with as reported by your driver. If it is less than 2.1, then that is why you are not able to use those functions. The solution is usually to update your video card driver.
"When you die, if you get a choice between going to regular heaven or pie heaven, choose pie heaven. It might be a trick, but if it's not, mmmmmmm, boy."
How to Ask Questions the Smart Way.
glGetString(GL_VERSION) returns <NULL>.
If I call GLeeInit() and GLeeGetErrorString() afterwards, it returns "GL extension querying failed".
I am sure that my driver and hardware supports buffer objects because I can run different applications that use them.
Sounds like you are making OpenGL calls before the rendering context is created. Could you post some code. I am mostly concerned with the order of your calls to SDL_Init, SDL_SetVideoMode, and then any OpenGL calls. Also, you should make sure all your SDL_Init and SDL_SetVideoMode are succeeding, and to be safe you could query SDL_GetAttribute to see what the actual values are for your OpenGL attributes. You may need to manually call SDL_GL_SetAttribute to specify your color and depth buffer bits if SDL_SetVideoMode is failing.
"When you die, if you get a choice between going to regular heaven or pie heaven, choose pie heaven. It might be a trick, but if it's not, mmmmmmm, boy."
How to Ask Questions the Smart Way.
My code looks like this:

int main( int argc, char* argv[] )
{
if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER ) < 0 )
return -1;

g_engine.init( 512, 512 );

...
}

void Engine::init( const uint resX, const uint resY ){

glEnable( GL_TEXTURE_2D );
glGenBuffers( 1, &pbo );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 512, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, 0 );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glBindBuffer( GL_PIXEL_UNPACK_BUFFER_ARB, pbo );
glBufferData( GL_PIXEL_UNPACK_BUFFER_ARB, 2048*2048*4, 0, GL_STREAM_DRAW_ARB );

...
}

This topic is closed to new replies.

Advertisement