gpt4 book ai didi

c++ - glGenBuffers 因段错误而崩溃

转载 作者:行者123 更新时间:2023-12-01 23:06:22 26 4
gpt4 key购买 nike

我不明白为什么它总是在 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

这是我的 main()

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 库。

最佳答案

从你的问题来看,不太清楚你正在使用哪个操作系统进行开发,但根据 gdb 的使用情况,我会猜测你正在使用 Linux。

当您获得 OpenGL 1.4 兼容模式(可能是软件渲染堆栈)时,您的显卡硬件支持 OpenGL 4.2。这种情况通常在未安装显卡驱动程序时发生(在 Linux 中,您可能使用开源驱动程序而不是供应商提供的闭源驱动程序),但如果您尝试在远程 session 中运行 OpenGL 程序,也可能会发生这种情况。如果您尝试这样做,安装 VirtualGL 可能会有所帮助 ( http://www.virtualgl.org/ )。

关于c++ - glGenBuffers 因段错误而崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26708389/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com