Jump to content
  • Advertisement
Sign in to follow this  
dosto_walla

glBindBuffer

This topic is 3623 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
Hi

Here it is:


****************************************'
#include <iostream>

#define GL_GLEXT_PROTOTYPES

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


#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <GL/glext.h>

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;
}




******************************************

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!