PDA

View Full Version : Unhandled exception at 0x00000000 glGenBuffer



umen242
06-21-2011, 11:21 PM
Unhandled exception at 0x00000000 glGenBuffer trying to use lib3ds with opengl.
Im begginer so bare with me here , i like to load 3ds model into simple opengl program , what i did is to use as refernce 2 links i found :
http://pastebin.com/CZ82VYWT http://pastebin.com/CZ82VYWT and http://www.donkerdump.nl/node/207 http://www.donkerdump.nl/node/207 i take the code from the redbook the cube example and tryed to marage between the 2
but all the time i keep getting Unhandled exception at 0x00000000 glGenBuffer exception . in the CModel3DS::CreateVBO() method here is my code :

// main.cpp
#include <stdlib.h>
#include "CModel3DS.h"

CModel3DS * monkey;
// Initialize some OpenGL settings
void initializeGL(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_SMOOTH);

// Enable lighting and set the position of the light
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
GLfloat pos[] = { 0.0, 4.0, 4.0 };
glLightfv(GL_LIGHT0, GL_POSITION, pos);

// Generate Vertex Buffer Objects
monkey->CreateVBO();
}

// Reset viewport and projection matrix after the window was resized
void resizeGL(int width, int height)
{
// Reset the viewport
glViewport(0, 0, width, height);
// Reset the projection and modelview matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// 10 x 10 x 10 viewing volume
glOrtho(-5.0, 5.0, -5.0, 5.0, -5.0, 5.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

// Do all the OpenGL rendering
void paintGL(void)
{
glClear(GL_COLOR_BUFFER_BIT);

// Draw our model
monkey->Draw();

// We don't need to swap the buffers, because QT does that automaticly for us
}

void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_FLAT);

}

void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
glLoadIdentity (); /* clear the matrix */
/* viewing transformation */
gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glScalef (1.0, 2.0, 1.0); /* modeling transformation */
//glutWireCube (1.0);
paintGL();
glFlush ();
}

void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
glMatrixMode (GL_MODELVIEW);
}

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




int main(int argc, char** argv)
{
glutInit(&amp;argc, argv);

glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
GLenum err = glewInit();
if (GLEW_OK != err)
{
/* Problem: glewInit failed, something is seriously wrong. */
fprintf(stderr, "Error: %s\n", glewGetErrorString(err));

}

try
{
monkey = new CModel3DS("monkey.3ds");
initializeGL();
paintGL();
}
catch(std::string error_str)
{
std::cerr << "Error: " << error_str << std::endl;


exit(1);
}
glutMainLoop();
return 0;
}

//the CModel3DS.h

#ifndef CMODEL3DS_H
#define CMODEL3DS_H
#include <GL/glew.h>
#include <GL/glut.h>
#include <string>
#include <iostream>
#include <string>
#include <cstring>
#include <cassert>
#include <lib3ds/file.h>
#include <lib3ds/mesh.h>
// Our 3DS model class
class CModel3DS
{
public:
CModel3DS(std:: string filename);
virtual void Draw() const;
virtual void CreateVBO();
virtual ~CModel3DS();
protected:
void GetFaces();
unsigned int m_TotalFaces;
Lib3dsFile * m_model;
GLuint m_VertexVBO, m_NormalVBO;
};

and the cpp

#include "CModel3DS.h"





// Load 3DS model
CModel3DS::CModel3DS(std:: string filename)
{
m_TotalFaces = 0;

m_model = lib3ds_file_load(filename.c_str());
// If loading the model failed, we throw an exception
if(!m_model)
{
throw strcat("Unable to load ", filename.c_str());
}
}


// Count the total number of faces this model has
void CModel3DS::GetFaces()
{
assert(m_model != NULL);

m_TotalFaces = 0;
Lib3dsMesh * mesh;
// Loop through every mesh
for(mesh = m_model->meshes;mesh != NULL;mesh = mesh->next)
{
// Add the number of faces this mesh has to the total faces
m_TotalFaces += mesh->faces;
}
}


// Copy vertices and normals to the memory of the GPU
void CModel3DS::CreateVBO()
{
assert(m_model != NULL);

// Calculate the number of faces we have in total
GetFaces();

// Allocate memory for our vertices and normals
Lib3dsVector * vertices = new Lib3dsVector[m_TotalFaces * 3];
Lib3dsVector * normals = new Lib3dsVector[m_TotalFaces * 3];

Lib3dsMesh * mesh;
unsigned int FinishedFaces = 0;
// Loop through all the meshes
for(mesh = m_model->meshes;mesh != NULL;mesh = mesh->next)
{
lib3ds_mesh_calculate_normals(mesh, &amp;normals[FinishedFaces*3]);
// Loop through every face
for(unsigned int cur_face = 0; cur_face < mesh->faces;cur_face++)
{
Lib3dsFace * face = &amp;mesh->faceL[cur_face];
for(unsigned int i = 0;i < 3;i++)
{
memcpy(&amp;vertices[FinishedFaces*3 + i], mesh->pointL[face->points[ i ]].pos, sizeof(Lib3dsVector));
}
FinishedFaces++;
}
}

// Generate a Vertex Buffer Object and store it with our vertices
glGenBuffers(1, &amp;m_VertexVBO); <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<---------------------------HERE IS MY EXCEPTION
glBindBuffer(GL_ARRAY_BUFFER, m_VertexVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(Lib3dsVector) * 3 * m_TotalFaces, vertices, GL_STATIC_DRAW);

// Generate another Vertex Buffer Object and store the normals in it
glGenBuffers(1, &amp;m_NormalVBO);
glBindBuffer(GL_ARRAY_BUFFER, m_NormalVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(Lib3dsVector) * 3 * m_TotalFaces, normals, GL_STATIC_DRAW);

// Clean up our allocated memory
delete vertices;
delete normals;

// We no longer need lib3ds
lib3ds_file_free(m_model);
m_model = NULL;
}


// Render the model using Vertex Buffer Objects
void CModel3DS:: Draw() const
{
assert(m_TotalFaces != 0);

// Enable vertex and normal arrays
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);

// Bind the vbo with the normals
glBindBuffer(GL_ARRAY_BUFFER, m_NormalVBO);
// The pointer for the normals is NULL which means that OpenGL will use the currently bound vbo
glNormalPointer(GL_FLOAT, 0, NULL);

glBindBuffer(GL_ARRAY_BUFFER, m_VertexVBO);
glVertexPointer(3, GL_FLOAT, 0, NULL);

// Render the triangles
glDrawArrays(GL_TRIANGLES, 0, m_TotalFaces * 3);

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
}


// Destructor
CModel3DS::~CModel3DS()
{
glDeleteBuffers(1, &amp;m_VertexVBO);
glDeleteBuffers(1, &amp;m_NormalVBO);

if(m_model != NULL)
{
lib3ds_file_free(m_model);
}
}
#endif

in the document ion it says that the glewInit(); needs to be after the opengl init and this is what i do . but its failed

Alfonse Reinheart
06-21-2011, 11:40 PM
but its failed

If glewInit fails, then that's a problem you need to fix, since GLEW is what allows you to use many OpenGL functions (like glGenBuffers).

umen242
06-22-2011, 01:16 AM
sorry for the mistake but all the application as all failed the glewInit
does succeed , now i have different small application that failed on glGenVertexArrays ..
also after reading this post : http://stackoverflow.com/questions/4317062/opengl-how-to-check-if-the-user-supports-glgenbuffers
and changing glGenBuffers() to glGenBuffersARB()
i don't get the exception , but i still puzzled here .
when should i know when to use what ?
here is my OpenGL report from OpenGL Extension viewer :

Renderer: Intel Broadwater G
Vendor: Intel
Memory: 256 MB
Version: 1.4.0 - Build 6.14.10.4670
Shading language version: N/A


Max texture size: 2048 x 2048
Max texture coordinates: 8
Max vertex texture image units: 0
Max texture image units: 16
Max geometry texture units: 0
Max anisotropic filtering value: 2
Max number of light sources: 16
Max viewport size: 2048 x 2048
Max uniform vertex components: 0
Max uniform fragment components: 0
Max geometry uniform components: 0
Max varying floats: 0
Max samples: 0
Max draw buffers: 0


Extensions: 57

GL_3DFX_texture_compression_FXT1
GL_ARB_depth_texture
GL_ARB_fragment_program
GL_ARB_multitexture
GL_ARB_occlusion_query
GL_ARB_point_parameters
GL_ARB_shadow
GL_ARB_texture_border_clamp
GL_ARB_texture_compression
GL_ARB_texture_cube_map
GL_ARB_texture_env_add
GL_ARB_texture_env_combine
GL_ARB_texture_env_crossbar
GL_ARB_texture_env_dot3
GL_ARB_transpose_matrix
GL_ARB_vertex_buffer_object
GL_ARB_vertex_program
GL_ARB_window_pos
GL_EXT_abgr
GL_EXT_bgra
GL_EXT_blend_color
GL_EXT_blend_func_separate
GL_EXT_blend_minmax
GL_EXT_blend_subtract
GL_EXT_clip_volume_hint
GL_EXT_compiled_vertex_array
GL_EXT_cull_vertex
GL_EXT_draw_range_elements
GL_EXT_fog_coord
GL_EXT_multi_draw_arrays
GL_EXT_packed_pixels
GL_EXT_rescale_normal
GL_EXT_secondary_color
GL_EXT_separate_specular_color
GL_EXT_shadow_funcs
GL_EXT_stencil_two_side
GL_EXT_stencil_wrap
GL_EXT_texture3D
GL_EXT_texture_compression_s3tc
GL_EXT_texture_env_add
GL_EXT_texture_env_combine
GL_EXT_texture_filter_anisotropic
GL_EXT_texture_lod_bias
GL_IBM_texture_mirrored_repeat
GL_NV_blend_square
GL_NV_texgen_reflection
GL_SGIS_generate_mipmap
GL_SGIS_texture_edge_clamp
GL_SGIS_texture_lod
GL_WIN_swap_hint
WGL_ARB_buffer_region
WGL_ARB_extensions_string
WGL_ARB_make_current_read
WGL_ARB_pbuffer
WGL_ARB_pixel_format
WGL_EXT_extensions_string
WGL_EXT_swap_control

Core features
v1.1 (100 % - 7/7)
v1.2 (100 % - 8/8)
v1.3 (100 % - 9/9)
v1.4 (100 % - 15/15)
v1.5 (100 % - 3/3)
v2.0 (10 % - 1/10)
v2.1 (0 % - 0/3)
v3.0 (0 % - 0/23)
v3.1 (0 % - 0/8)
v3.2 (0 % - 0/9)
v3.3 (0 % - 0/9)
v4.0 (0 % - 0/13)
v4.1 (0 % - 0/7)

OpenGL driver version check (Current: 6.14.10.4670, Latest known: 6.14.10.4642):
Latest version of display drivers found
According the database, you are running the latest display drivers for your video card.

Compiled vertex array support
This feature improves OpenGL performance by using video memory to cache transformed vertices.

Multitexture support
This feature accelerates complex rendering such as lightmaps or environment mapping.

Secondary color support
This feature provides an alternate method of coloring specular highlights on polygons.

S3TC compression support
This feature improves texture mapping performance in some applications by using lossy compression.

Texture edge clamp support
This feature improves texturing quality by adding clamping control to edge texel filtering.

Vertex program support
This feature enables a wide variety of effects via flexible vertex programming (equivalent to DX8 Vertex Shader.)

Fragment program support
This feature enables a wide variety of effects via per pixel programming (equivalent to DX9 Pixel Shader.)

Texture anisotropic filtering support
This feature improves the quality of texture mapping on oblique surfaces.

Occlusion test support
This feature provides hardware accelerated culling for objects.

No OpenGL Shading Language support
This may break compatibility for applications using per pixel shading.

No Frame buffer object support
This may break compatibility for applications using render to texture functions.

Extension verification:
GL_ARB_debug_output was not found, but has the entry point glGetPointerv
GL_ARB_imaging was not found, but has the entry point glBlendEquation
GL_ARB_occlusion_query has been added to the extensions list of Intel Broadwater G

MaxH
06-22-2011, 12:07 PM
Unhandled exception at 0x00000000 ...
Hee hee. This is my favorite error message.

V-man
06-22-2011, 04:22 PM
i don't get the exception , but i still puzzled here .
when should i know when to use what ?

glGenBuffers was introduced in GL 1.5. Check the spec file for GL 1.5

glGenBuffersARB is part of an extension known as GL_ARB_vertex_buffer_object