Sign in to follow this  
Zeophlite

OpenGL VBOs & glew undefined references

Recommended Posts

I can get Immediate Mode & Vertex Arrays to work, but not VBOs.


#include <stdlib.h>
#define GLEW_STATIC
#include <GL/glew.h>
#include <stdio.h>
#include "sdl.h"

const int NODRAW = 0;
const int IMMEDIATE = 1;
const int VERTEX_ARRAY = 2;
const int VBO = 3;

extern int method;
extern int print, delay;

GLfloat vertices[] = {
-0.2f, -0.2f, 0.0f,
-0.2f, 0.2f, 0.0f,
0.2f, 0.2f, 0.0f,
0.2f, -0.2f, 0.0f
};

GLfloat colors[] = {
1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 1.0f
};

int numverts = sizeof(vertices) / (3*sizeof(GLfloat));

GLuint vboId = 0;

static int make_resources(void) {
/*
glGenBuffers(1, &vboId);
glBindBuffer(GL_ARRAY_BUFFER, vboId);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices) + sizeof(colors), NULL, GL_STATIC_DRAW);

glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
glBufferSubData(GL_ARRAY_BUFFER, sizeof(vertices), sizeof(colors), colors);


*/


return 1;
}

static int clean_resources(void) {
// glDeleteBuffers(1, &vboId);
}

static void render(void) {
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);

if (method == IMMEDIATE) {
glBegin(GL_POLYGON);

int i;
for(i = 0; i < numverts; i++) {
glColor3fv(&colors[i*3]);
glVertex3fv(&vertices[i*3]);
}

glEnd();
} else if (method == VERTEX_ARRAY) {
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);

glVertexPointer(3, GL_FLOAT, 0, vertices);
glColorPointer(3, GL_FLOAT, 0, colors);

glDrawArrays(GL_POLYGON, 0, numverts);

glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
} else if (method == VBO) {
// glBindBuffer(GL_ARRAY_BUFFER, vboId);

// glEnableClientState(GL_VERTEX_ARRAY);
// glEnableClientState(GL_COLOR_ARRAY);

// glVertexPointer(3, GL_FLOAT, 0, 0);
// glColorPointer(3, GL_FLOAT, 0, (GLvoid*)(numverts * 3 * sizeof(GLfloat)));

// glDrawArrays(GL_LINE_LOOP, 0, numverts);

// glDisableClientState(GL_COLOR_ARRAY);
// glDisableClientState(GL_VERTEX_ARRAY);

// glBindBuffer(GL_ARRAY_BUFFER, 0);
}


SDL_GL_SwapBuffers();
}

extern int done;

int main(int argc, char** argv) {
initSDL();

glewInit();

if (!glewIsSupported("GL_VERSION_2_0")) {
fprintf(stderr, "OpenGL 2.0 not available\n");
return 1;
}

if (!make_resources()) {
fprintf(stderr, "Failed to load resources\n");
return 1;
}

while (!done) {
handleInput();
render();
}
clean_resources();

SDL_Quit();
return 0;
}



I won't bother you with initSDL() or handleInput(), but they are both in a seperate file, sdl.c, along with some ints & have a header, sdl.h. (I realise that that's a bad name, could interfer with SDL.h!)

I'm linking with:
glew32.lib
libopengl32.a
libglu32.a
libmingw32.a
libSDLmain.a
libSDL.dll.a

Now If I uncomment the code in render(), make_resources() & clean_resources(), I get these errors:


build/main.o: In function `make_resources':
src/main.c:35: undefined reference to `__glewGenBuffers'
src/main.c:36: undefined reference to `__glewBindBuffer'
src/main.c:37: undefined reference to `__glewBufferData'
src/main.c:39: undefined reference to `__glewBufferSubData'
src/main.c:40: undefined reference to `__glewBufferSubData'
build/main.o: In function `clean_resources':
src/main.c:49: undefined reference to `__glewDeleteBuffers'
build/main.o: In function `render':
src/main.c:86: undefined reference to `__glewBindBuffer'
src/main.c:99: undefined reference to `__glewBindBuffer'




So what do I have to do to get glew to fix it?

Cheers

Share this post


Link to post
Share on other sites
I tried using MingW using Eclipse. It was really hard to set up. The problem mainly being the library is specifically compiled using Visual Studio and no official support for the MingW library.

With that said however there are ways of getting it to run. 1) Get someone else's compiled MingW library (http://www.nuwen.net) or 2) compile it yourself [Gives access to the latest GLEW library].

I remember seeing a compiled MingW library somewhere in Google, I'll get back to you on that if I come across it.

As an alternative you could just use Microsoft Visual Studio 2008 / 2010 Express Edition and most libraries run "out of the box".

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