Skip to main content
gamedev.net
🔒 Locked

glBindBuffer

Started by dosto_walla Jul 17, 2008 at 12:42 AM 2 replies 1.1k views
Original Post
dosto_walla
dosto_walla
Hello forum, I have getting segmentation fault while running a small snippet of code about glBindBuffer The code compiled without any errors. Tried with gdb and showed problem in /usr/lib/dri/fglrx_dri.so where i am lost Do i have to link to any other library other than -lGLU -lGL -lglut Thanks in advance!!! Cheers Sajjad
HuntsMan
HuntsMan
And where is that code snippet?
dosto_walla
dosto_walla
Hi

Here it is:


****************************************'
#include

#define GL_GLEXT_PROTOTYPES

#define BUFFER_OFFSET(bytes) ((GLubyte*) NULL + (bytes))


#include
#include
#include
#include

using namespace std;


const GLushort VERTICES = 0;
const GLushort INDICES = 1;
const GLushort NUM_BUFFERS = 2;

GLuint buffers[NUM_BUFFERS];

void setupBind()
{
GLfloat vertices[][3] = {
{-1.0, -1.0, -1.0},
{1.0, -1.0, -1.0},
{1.0, 1.0, -1.0},
{-1.0, 1.0, -1.0},
{-1.0, -1.0, 1.0},
{1.0, -1.0, 1.0},
{1.0, 1.0, 1.0},
{-1.0, 1.0, 1.0}
};

GLubyte indices[][4] = {
{0,1,2,3},
{4,7,6,5},
{0,4,5,1},
{3,2,6,7},
{0,3,7,4},
{1,5,6,2}
};

glGenBuffers(NUM_BUFFERS,buffers);

//bound the buffer objrct
glBindBuffer(GL_ARRAY_BUFFER, buffers[VERTICES]);

//allocate space for that
//to store the vertex data
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices),vertices, GL_STATIC_DRAW );

glVertexPointer(3,GL_FLOAT, 0, BUFFER_OFFSET(0));
glEnableClientState(GL_VERTEX_ARRAY);


glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[INDICES]);


glBufferData(GL_ARRAY_BUFFER, sizeof(indices),indices, GL_STATIC_DRAW );

}



void display()
{
glClear(GL_COLOR_BUFFER_BIT);


glDrawElements(GL_QUADS, 24, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0));
}

void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_SMOOTH);
setupBind();
}

void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D (0.0, (GLdouble) w, 0.0, (GLdouble) h);
}

void keyboard(unsigned char key, int x, int y)
{
switch (key)
{
case 27:
exit(0);
break;
}
}


int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (350, 350);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
//glutMouseFunc(mouse);
glutKeyboardFunc (keyboard);
glutMainLoop();
return 0;
}




******************************************
V-man
V-man
http://www.opengl.org/wiki/index.php/Getting_started

More specifically, the "OpenGL 2.0 and extensions" part explains.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.