我无法弄清楚为什么它会继续崩溃glGenBuffers
GDB回溯给了我这个
#0 0x00000000 in ?? ()
#1 0x0808701d in setupBuffers () at main_scene.cc:250
#2 0x08088cf8 in main (argc=1, argv=0xbffff3c4) at main_scene.cc:694
这是我的主要()
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
glutInitWindowPosition(20, 20);
glutCreateWindow("New Window");
GLenum err = glewInit();
if (GLEW_OK != err)
{
/* glewInit failed, something is seriously wrong */
fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
}
setupBuffers();
...
/* set callback functions */
glutReshapeFunc (reshape);
glutDisplayFunc (display);
glutKeyboardFunc(input);
glutIdleFunc (idle);
glutMainLoop();
return 0;
}
这是我的setupBuffers()方法
void setupBuffers() {
GLenum errorCode = 0;
// Normal
size_t normal_buffer_size = 0; // Calc buffer size needed
for (size_t i = 0; i < shapes.size(); i++) {
normal_buffer_size += sizeof(float) * shapes[i].mesh.normals.size();
}
glGenBuffers(1, &normal_buffer);
glBindBuffer(GL_ARRAY_BUFFER, normal_buffer);
glBufferData(GL_ARRAY_BUFFER, normal_buffer_size, NULL, GL_STATIC_DRAW);
normal_buffer_size = 0;
for (size_t i = 0; i < shapes.size(); i++) {
glBufferSubData(GL_ARRAY_BUFFER, normal_buffer_size, sizeof(float) * shapes[i].mesh.normals.size(), &shapes[i].mesh.normals[0]); // Add the buffer data
normal_buffer_size += sizeof(float) * shapes[i].mesh.normals.size();
}
glBindBuffer(GL_ARRAY_BUFFER, 0);
...
// draw multiple objects with one draw call
glGenVertexArrays(1, &vertex_array_object);
glBindVertexArray(vertex_array_object);
glBindBuffer(GL_ARRAY_BUFFER, normal_buffer);
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer);
glBindVertexArray(0);
errorCode = glGetError();
if (errorCode != 0) {
fprintf(stderr, "Error data: %s, code %d\n", glewGetErrorString(errorCode), errorCode);
}
}
继承我正在使用的全局变量
GLuint vertex_buffer;
GLuint index_buffer;
GLuint normal_buffer;
GLuint texture_buffer;
GLuint vertex_array_object;
glxinfo的输出(如果你需要的话)
name of display: localhost:11.0
display: localhost:11 screen: 0
direct rendering: No (If you want to find out why, try setting LIBGL_DEBUG=verbose)
server glx vendor string: SGI
server glx version string: 1.4
server glx extensions:
GLX_ARB_multisample, GLX_EXT_import_context, GLX_EXT_visual_info,
GLX_EXT_visual_rating, GLX_MESA_copy_sub_buffer, GLX_OML_swap_method,
GLX_SGI_make_current_read, GLX_SGI_swap_control, GLX_SGIS_multisample,
GLX_SGIX_fbconfig, GLX_SGIX_pbuffer
client glx vendor string: ATI
client glx version string: 1.4
client glx extensions:
GLX_ARB_create_context, GLX_ARB_create_context_profile,
GLX_ARB_get_proc_address, GLX_ARB_multisample, GLX_EXT_import_context,
GLX_EXT_swap_control, GLX_EXT_visual_info, GLX_EXT_visual_rating,
GLX_MESA_allocate_memory, GLX_MESA_copy_sub_buffer, GLX_MESA_swap_control,
GLX_MESA_swap_frame_usage, GLX_NV_swap_group, GLX_OML_swap_method,
GLX_SGI_make_current_read, GLX_SGI_swap_control, GLX_SGI_video_sync,
GLX_SGIS_multisample, GLX_SGIX_fbconfig, GLX_SGIX_pbuffer,
GLX_SGIX_swap_barrier, GLX_SGIX_swap_group, GLX_SGIX_visual_select_group,
GLX_EXT_texture_from_pixmap, GLX_EXT_framebuffer_sRGB,
GLX_ARB_fbconfig_float, GLX_AMD_gpu_association, GLX_EXT_buffer_age
GLX version: 1.4
GLX extensions:
GLX_ARB_get_proc_address, GLX_ARB_multisample, GLX_EXT_import_context,
GLX_EXT_visual_info, GLX_EXT_visual_rating, GLX_MESA_copy_sub_buffer,
GLX_OML_swap_method, GLX_SGI_make_current_read, GLX_SGI_swap_control,
GLX_SGIS_multisample, GLX_SGIX_fbconfig, GLX_SGIX_pbuffer
OpenGL vendor string: ATI Technologies Inc.
OpenGL renderer string: AMD Radeon HD 7800 Series
OpenGL version string: 1.4 (4.4.12967 Compatibility Profile Context 14.200.1004.0)
OpenGL extensions:
GL_ARB_depth_texture, GL_ARB_draw_buffers, GL_ARB_fragment_program,
GL_ARB_fragment_program_shadow, GL_ARB_imaging, GL_ARB_multisample,
GL_ARB_multitexture, GL_ARB_occlusion_query, GL_ARB_point_parameters,
GL_ARB_point_sprite, GL_ARB_shadow, GL_ARB_shadow_ambient,
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_texture_mirrored_repeat,
GL_ARB_texture_non_power_of_two, GL_ARB_texture_rectangle,
GL_ARB_transpose_matrix, GL_ARB_vertex_buffer_object,
GL_ARB_vertex_program, GL_ARB_window_pos, GL_ARB_shader_objects,
GL_ARB_vertex_shader, GL_ARB_fragment_shader, GL_ARB_framebuffer_object,
GL_ARB_geometry_shader4, GL_EXT_abgr, GL_EXT_bgra, GL_EXT_blend_color,
GL_EXT_blend_equation_separate, GL_EXT_blend_func_separate,
GL_EXT_blend_minmax, GL_EXT_blend_subtract, GL_EXT_copy_texture,
GL_EXT_draw_range_elements, GL_EXT_fog_coord, GL_EXT_framebuffer_object,
GL_EXT_multi_draw_arrays, GL_EXT_packed_pixels, GL_EXT_point_parameters,
GL_EXT_rescale_normal, GL_EXT_secondary_color,
GL_EXT_separate_specular_color, GL_EXT_shadow_funcs, GL_EXT_stencil_wrap,
GL_EXT_subtexture, GL_EXT_texture3D, GL_EXT_texture_compression_s3tc,
GL_EXT_texture_edge_clamp, GL_EXT_texture_env_add,
GL_EXT_texture_env_combine, GL_EXT_texture_env_dot3,
GL_EXT_texture_filter_anisotropic, GL_EXT_texture_lod,
GL_EXT_texture_lod_bias, GL_EXT_texture_mirror_clamp,
GL_EXT_texture_object, GL_EXT_texture_rectangle, GL_EXT_vertex_array,
GL_EXT_histogram, GL_EXT_framebuffer_blit, GL_EXT_framebuffer_multisample,
GL_EXT_geometry_shader4, GL_EXT_gpu_shader4, GL_ATI_draw_buffers,
GL_ATI_texture_env_combine3, GL_ATI_texture_float,
GL_ATI_texture_mirror_once, GL_ATIX_texture_env_combine3,
GL_IBM_texture_mirrored_repeat, GL_INGR_blend_func_separate,
GL_SGIS_generate_mipmap, GL_SGIS_texture_border_clamp,
GL_SGIS_texture_edge_clamp, GL_SGIS_texture_lod, GL_SGIX_shadow_ambient,
GL_SUN_multi_draw_arrays, GL_ARB_texture_float
哦,顺便说一句,我正在使用一个静态的glew库。
答案 0 :(得分:1)
你没有正确处理GLEW没有初始化的情况。在打印完一条消息之后,您只需继续使用您的程序,该程序可能会在崩溃中运行。
但更糟糕的是:您不会检查您要使用的特定功能或扩展是否实际可用。 glGenBuffers
实际上是OpenGL-1-5的一个功能,而你只获得一个OpenGL-1.4上下文,至少是版本字符串所说的(这很奇怪,因为显然你的GPU可以做OpenGL-4)。 在使用之前,您必须检查扩展程序的可用性。不言而喻,您不能使用超出OpenGL实现为您提供上下文的OpenGL版本配置文件的功能。您的OpenGL实现支持GL_ARB_vertex_buffer_object
,但如果您想使用它,则必须使用glGenBuffersARB
。
更新我认为系统上的驱动程序安装不正常。服务器字符串报告“供应商SGI”,它与您的GPU驱动程序不匹配。
答案 1 :(得分:1)
从您的问题来看,您使用哪种操作系统进行开发尚不十分清楚,但根据gdb的使用情况,我会猜测您使用的是Linux。
当您获得OpenGL 1.4兼容模式(可能是软件渲染堆栈)时,您的视频卡硬件支持OpenGL 4.2。这通常发生在未安装视频卡驱动程序时(在Linux中,您可能使用的是开源驱动程序而不是供应商提供的闭源驱动程序),但如果您尝试在远程会话中运行OpenGL程序,也会发生这种情况。如果您尝试这样做,安装VirtualGL可能会有所帮助(http://www.virtualgl.org/)。