PDA

View Full Version : glGenBuffersARB problem



RigidBody
11-08-2004, 01:21 AM
hi folks,

i'm trying to get into using VBOs and experienced some problems from the very beginning- starting with glGenBuffersARB. when i run the following code, the initial value of array_id remains unchanged, so GenBuffers doesn't seem to work properly. anybody else encountered this problem?

i'm working on redhat linux with a nvidia quadro 900 xgl, driver 43.63



typedef void ( *PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers);

PFNGLGENBUFFERSARBPROC glGenBuffersARB;

uint array_id = 123456;

void init() {

if((glGenBuffersARB = (PFNGLGENBUFFERSARBPROC)glXGetProcAddressARB((cons t GLubyte*)"glGenBuffersARB")) == NULL)
printf("\tGEN BUFFERS ARB NOT FOUND\n");

glGenBuffersARB(1, &array_id);
printf("\n\tbufid = %i\n", array_id); }

Bob
11-08-2004, 07:45 AM
You need an active rendering context at the time you generate buffer IDs, or rather, do anything with OpenGL.

RigidBody
11-08-2004, 08:13 AM
sorry- i HAVE a current context, which of course you couldn't see in the code snippet...actually i'm sure that i have everything i need to get it working- that's why i put this in the advanced and not in the beginners' forum :D

if you take a look at this- i've tried it on redhat/nvidia quadro at work and on suse 9.0 with geforce4mx440/driver version 61.11 at home. it just doesn't work...the values in vbuf do not change


#define GLX_GLXEXT_PROTOTYPES 0xffff

#include<stdio.h>
#include<X11/Xlib.h>
#include<GL/glx.h>

Display *dpy = XOpenDisplay(NULL);
Window root = DefaultRootWindow(dpy);
GLint att[] = {GLX_RGBA, None};
XVisualInfo *vi = glXChooseVisual(dpy, 0, att);
GLXContext glc = glXCreateContext(dpy, vi, NULL, False);
Visual *vis = DefaultVisual(dpy, 0);
Colormap cmap = XCreateColormap(dpy, root, vis, AllocNone);
int dep = DefaultDepth(dpy, 0);
XSetWindowAttributes swa;
Window win;
GLuint vbuf[] = {98, 99, 100};

typedef void (APIENTRY * PFNGLGENBUFFERSARBPROC) (GLsizei , GLuint *);

PFNGLGENBUFFERSARBPROC glGenBuffersARB = NULL;

int main(int argc, char *argv[]){
swa.colormap = cmap;
swa.border_pixel = 0;

win = XCreateWindow(dpy, root, 0, 0, 100, 100, 0, dep, InputOutput, vis, CWColormap | CWBorderPixel, &amp;swa);
XMapWindow(dpy, win);
glXMakeCurrent(dpy, win, glc);

glGenBuffersARB = (PFNGLGENBUFFERSARBPROC) glXGetProcAddressARB((const GLubyte*) "glGenBuffersARB");
glGenBuffersARB(3, &amp;(vbuf[0]));
printf("\n\tBUFFER IDS = %i, %i, %i\n\n", vbuf[0], vbuf[1], vbuf[2]); }

V-man
11-08-2004, 11:58 AM
So everything else is working except VBO?

Try

int main(int argc, char *argv[])
{
.........
.........
GLuint bufferID=0;
glGenBuffersARB(1, &bufferID);
.........
.........
}

RigidBody
11-08-2004, 12:14 PM
well- seems that now i've woken up canada :D

but if you look at my first code sample- it looks pretty much like your proposal. believe me, i've tried uint, GLuint and arrays of both. but it still doesn't work. i have a current gl context. i set the pointer for glGenBuffersARB to NULL, so if glXGetProcAdressARB would not work, the call to GenBuffers should result in core dump, but it doesn't...

WHAT THE HELL AM I DOING WRONG???

this is not a fake- can anybody compile this stuff on their linux machine and tell me that it works- then i'll gladly throw my hardware out the window and buy something new <sob>

rgpc
11-08-2004, 12:29 PM
I think what V-man is getting at is initialising the value of your variable to "0" before you call glGenBuffers(). It might be that glGenBuffers() is using the value you pass it as the ID. Have you actually called glGetError() after calling glGenBuffers() to see if there is actually an error?

Ysaneya
11-09-2004, 12:23 AM
Each time i've seen this kind of error it was due to the context. Double, triple check that your context is correct.

Y.

RigidBody
11-09-2004, 01:06 AM
i create a window and a context, make it current, draw a quad, no problem. so the context is good for me.

idr
11-11-2004, 12:23 AM
As a side note, on Linux it is illegal to name your function pointer the same as the function. You wouldn't put 'void * (*malloc)(size_t);' in a program and expect things to be happy, would you? glGetBuffersARB is exactly the same.

RigidBody
11-11-2004, 12:13 PM
? i don't get your point- there's no glGenBuffersARB defined in any of the header files.

anyway, there's no difference if i call my function glGenBuffersNarf...

rgpc
11-11-2004, 01:07 PM
I'll ask it again:

Have you actually called glGetError() after calling glGenBuffers() to see if there is actually an error?

RigidBody
11-12-2004, 01:24 AM
...GL_NO_ERROR...

rgpc
11-12-2004, 04:16 AM
And if you try to use the buffers (or rather than values in the buffers) what happens?

idr
11-12-2004, 09:19 AM
It doesn't matter if glGenBuffersARB or glFooBar are in the header files. Symbols that are part of the public OpenGL API may be exported by libGL. If a symbol is publicly exported by a library, replacing it with a symbol with the same name but different type (e.g., function vs. function pointer) can cause problems.

The problem is if libGL or the loaded driver tries to call the function you're overloading. If the driver calls glGenBuffersARB (unlikely!), it will jump to your function pointer and your program will crash. Just like if you overload malloc with 'void * (*malloc)(size_t)'. Something in another library will try to call malloc, jump to the pointer, and crash.

However, other libraries that you load might do that. For example, a future version of GLUT (or FreeGLUT) could, legally directly call glMultiTexCoord2D if GL version 1.3 was detected. If you have a function pointer called glMultiTexCoord2D in your app, BOOM.

Note: this has nothing to do with the problem you're seeing here. That's why I prefaced my original comment with "As a side note..."

RigidBody
11-13-2004, 08:50 AM
ok, here's the complete code. what happens is a segmentation fault when glDrawarrays is called




#define GLX_GLXEXT_PROTOTYPES 0xffff

#include<stdio.h>
#include<X11/Xlib.h>
#include<GL/glx.h>

Display *dpy = XOpenDisplay(NULL);
Window root = DefaultRootWindow(dpy);
GLint att[] = {GLX_RGBA, None};
XVisualInfo *vi = glXChooseVisual(dpy, 0, att);
GLXContext glc = glXCreateContext(dpy, vi, NULL, False);
Visual *vis = DefaultVisual(dpy, 0);
Colormap cmap = XCreateColormap(dpy, root, vis, AllocNone);
int dep = DefaultDepth(dpy, 0);
XSetWindowAttributes swa;
Window win;
GLuint vbuf[] = {98, 99, 100};

#define GL_ARRAY_BUFFER_ARB 0x8892
#define GL_STATIC_DRAW_ARB 0x88E4

typedef void (APIENTRY * PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer);
typedef void (APIENTRY * PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers);
typedef void (APIENTRY * PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers);
typedef void (APIENTRY * PFNGLBUFFERDATAARBPROC) (GLenum target, int size, const GLvoid *data, GLenum usage);
typedef bool (APIENTRY * PFNGLISBUFFERARBPROC) (GLuint);

PFNGLGENBUFFERSARBPROC glGenBuffersARB = NULL;
PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB = NULL;
PFNGLBINDBUFFERARBPROC glBindBufferARB = NULL;
PFNGLBUFFERDATAARBPROC glBufferDataARB = NULL;
PFNGLISBUFFERARBPROC glIsBufferARB = NULL;

GLfloat vbo_data[] = {0., 0., 0., 1., 0., 0., 0., 1., 0.};

int main(int argc, char *argv[]){
swa.colormap = cmap;
swa.border_pixel = 0;

win = XCreateWindow(dpy, root, 0, 0, 100, 100, 0, dep, InputOutput, vis, CWColormap | CWBorderPixel, &amp;swa);
XMapWindow(dpy, win);
glXMakeCurrent(dpy, win, glc);

glGenBuffersARB = (PFNGLGENBUFFERSARBPROC) glXGetProcAddressARB((const GLubyte*) "glGenBuffersARB");
glDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC) glXGetProcAddressARB((const GLubyte*) "glDeleteBuffersARB");
glBindBufferARB = (PFNGLBINDBUFFERARBPROC) glXGetProcAddressARB((const GLubyte*) "glBindBufferARB");
glBufferDataARB = (PFNGLBUFFERDATAARBPROC) glXGetProcAddressARB((const GLubyte*) "glBufferDataARB");
glIsBufferARB = (PFNGLISBUFFERARBPROC) glXGetProcAddressARB((const GLubyte*) "glIsBufferARB");

if(glGenBuffersARB &amp;&amp; glDeleteBuffersARB &amp;&amp; glBindBufferARB &amp;&amp; glBufferDataARB &amp;&amp; glIsBufferARB)
printf("\n\tVBO SETUP OK\n");

glGenBuffersARB(3, vbuf);
printf("\n\tBUFFER IDS = %i, %i, %i\n\n", vbuf[0], vbuf[1], vbuf[2]);
printf("\tGEN BUFFER : ERROR = %i\n", glGetError());

if(glIsBufferARB(vbuf[0]) == False)
printf("\n\tBUFFER NOT VALID\n\n");

glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbuf[0]);
printf("\tBIND BUFFER : ERROR = %i\n", glGetError());

glBufferDataARB(GL_ARRAY_BUFFER_ARB, 9*sizeof(float), vbo_data, GL_STATIC_DRAW_ARB);
printf("\tBUFFER DATA : ERROR = %i\n", glGetError());

glEnableClientState(GL_VERTEX_ARRAY);
printf("\tENABLE ARRAY : ERROR = %i\n", glGetError());

glVertexPointer(3, GL_FLOAT, 0, NULL);
printf("\tVERTEX POINTER : ERROR = %i\n", glGetError());

glDrawArrays(GL_TRIANGLES, 0, 3); }
//
// gcc -I/usr/X11R6/include -L/usr/X11R6/lib -o vbo vbo.cc -lX11 -lGL -lGLU -lm
//

RigidBody
11-13-2004, 08:55 AM
and i should not forget to mention this: the glIsBufferARB call returns <false>.

Rob The Bloke
01-04-2005, 04:34 PM
GreetingsFromMunich,

did you ever sort this problem out? I'm getting exactly the same problem under linux with exactly the same card. (NV quadro 4 900XGL)

jide
01-07-2005, 10:13 AM
Ok. I'm trying to see why.

What does this command returns ?

glxinfo | grep 'GL_ARB_vertex_buffer_object'

weatx
01-07-2005, 11:59 AM
I see one problem with that code snippet. You don't abort the program if one of the buffer extensions don't work, it just tells you if it succeded and then continues. Check to see which one fails and then debug from that point on.

Aaron

V-man
01-07-2005, 05:17 PM
There are a few problems.
Checking to make sure GL context is current.
Checking for the extension.

If those check out, then this would qualify as a genuine possible bug. It would be stupid if this simple thing slipped through QA.

Have you contacted Nvidia? What did they say?

weatx
01-07-2005, 07:04 PM
Hey V-man, what's up. This is WhatEver, the guy whos Spider3D website you hosted for fun. I was looking at your ray tracing screen shots. Pretty impressive. Have you checked out the site RealStorm (http://www.realstorm.com) yet. It's all real-time ray-tracing.

Aaron

V-man
01-10-2005, 01:44 PM
Hi weatx, how's it going?
I remember you saying something about running an aluminum door company.

I've seen their nature sucks demo. They do good work. Low resolution, but good.

Did you mean the GLSL based raytraced scenes?