我通过Synaptics Package manager安装了以下软件包来编译Opengl.
freeglut3 freeglut3-dev freeglut3-dbg libglew1.5 libglew1.5-dev libglu1-mesa libglu1-mesa-dev libgl1-mesa-glx libgl1-mesa-dev
这是我运行程序时的输出.
X Error of failed request: GLXBadFBConfig
Major opcode of failed request: 156 (GLX)
Minor opcode of failed request: 34 ()
Serial number of failed request: 42
Current serial number in output stream: 41
对此的输入
(lspci | grep VGA) ; \
(dpkg -l | egrep 'xorg-video|glx') ; \
(ls -l /usr/lib/xorg/modules/{drivers,extensions})
给出一个输出
01:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Seymour [Radeon HD 6400M/7400M Series]
ii libgl1-mesa-glx:amd64 10.1.0-4ubuntu5 amd64 free implementation of the OpenGL API -- GLX runtime
ii libxcb-glx0:amd64 1.10-2ubuntu1 amd64 X C Binding, glx extension
ii libxcb-glx0-dev:amd64 1.10-2ubuntu1 amd64 X C Binding, glx extension, development files
ii xserver-xorg-video-all 1:7.7+1ubuntu8 amd64 X.Org X server -- output driver metapackage
ii xserver-xorg-video-ati 1:7.3.0-1ubuntu3.1 amd64 X.Org X server -- AMD/ATI display driver wrapper
ii xserver-xorg-video-cirrus 1:1.5.2-1build1 amd64 X.Org X server -- Cirrus display driver
ii xserver-xorg-video-fbdev 1:0.4.4-1build1 amd64 X.Org X server -- fbdev display driver
ii xserver-xorg-video-glamoregl 0.6.0-0ubuntu4 amd64 X.Org X server -- graphics acceleration module based on OpenGL
ii xserver-xorg-video-intel 2:2.99.910-0ubuntu1 amd64 X.Org X server -- Intel i8xx, i9xx display driver
ii xserver-xorg-video-mach64 6.9.4-1build1 amd64 X.Org X server -- ATI Mach64 display driver
ii xserver-xorg-video-mga 1:1.6.3-1build1 amd64 X.Org X server -- MGA display driver
ii xserver-xorg-video-modesetting 0.8.1-1build1 amd64 X.Org X server -- Generic modesetting driver
ii xserver-xorg-video-neomagic 1:1.2.8-1build1 amd64 X.Org X server -- Neomagic display driver
ii xserver-xorg-video-nouveau 1:1.0.10-1ubuntu2 amd64 X.Org X server -- Nouveau display driver
ii xserver-xorg-video-openchrome 1:0.3.3-1build1 amd64 X.Org X server -- VIA display driver
ii xserver-xorg-video-qxl 0.1.1-0ubuntu3 amd64 X.Org X server -- QXL display driver
ii xserver-xorg-video-r128 6.9.2-1build1 amd64 X.Org X server -- ATI r128 display driver
ii xserver-xorg-video-radeon 1:7.3.0-1ubuntu3.1 amd64 X.Org X server -- AMD/ATI Radeon display driver
ii xserver-xorg-video-s3 1:0.6.5-0ubuntu4 amd64 X.Org X server -- legacy S3 display driver
ii xserver-xorg-video-savage 1:2.3.7-2ubuntu2 amd64 X.Org X server -- Savage display driver
ii xserver-xorg-video-siliconmotion 1:1.7.7-2build1 amd64 X.Org X server -- SiliconMotion display driver
ii xserver-xorg-video-sis 1:0.10.7-0ubuntu6 amd64 X.Org X server -- SiS display driver
ii xserver-xorg-video-sisusb 1:0.9.6-2build1 amd64 X.Org X server -- SiS USB display driver
ii xserver-xorg-video-tdfx 1:1.4.5-1build1 amd64 X.Org X server -- tdfx display driver
ii xserver-xorg-video-trident 1:1.3.6-0ubuntu5 amd64 X.Org X server -- Trident display driver
ii xserver-xorg-video-vesa 1:2.3.3-1build1 amd64 X.Org X server -- VESA display driver
ii xserver-xorg-video-vmware 1:13.0.2-2ubuntu1 amd64 X.Org X server -- VMware display driver
/usr/lib/xorg/modules/drivers:
total 4728
-rw-r--r-- 1 root root 10408 مٓی 2 01:55 ati_drv.so
-rw-r--r-- 1 root root 31704 فروري 5 15:32 cirrus_alpine.so
-rw-r--r-- 1 root root 19352 فروري 5 15:32 cirrus_drv.so
-rw-r--r-- 1 root root 27832 فروري 5 15:32 cirrus_laguna.so
-rw-r--r-- 1 root root 23560 فروري 5 15:31 fbdev_drv.so
-rw-r--r-- 1 root root 1460976 فروري 10 17:15 intel_drv.so
-rw-r--r-- 1 root root 174648 فروري 5 15:33 mach64_drv.so
-rw-r--r-- 1 root root 140656 فروري 5 15:36 mga_drv.so
-rw-r--r-- 1 root root 44488 فروري 5 15:37 modesetting_drv.so
-rw-r--r-- 1 root root 66544 فروري 5 15:36 neomagic_drv.so
-rw-r--r-- 1 root root 207440 فروري 5 15:38 nouveau_drv.so
-rw-r--r-- 1 root root 356336 فروري 5 15:41 openchrome_drv.so
-rw-r--r-- 1 root root 172456 فروري 5 15:43 qxl_drv.so
-rw-r--r-- 1 root root 108712 فروري 5 15:39 r128_drv.so
-rw-r--r-- 1 root root 432616 مٓی 2 01:55 radeon_drv.so
-rw-r--r-- 1 root root 57656 فروري 5 15:41 s3_drv.so
-rw-r--r-- 1 root root 140848 فروري 5 15:43 savage_drv.so
-rw-r--r-- 1 root root 112192 فروري 5 15:46 siliconmotion_drv.so
-rw-r--r-- 1 root root 547064 اپريل 2 16:01 sis_drv.so
-rw-r--r-- 1 root root 77144 فروري 5 15:45 sisusb_drv.so
-rw-r--r-- 1 root root 189392 فروري 5 15:43 spiceqxl_drv.so
-rw-r--r-- 1 root root 65936 فروري 5 15:45 tdfx_drv.so
-rw-r--r-- 1 root root 142224 فروري 5 15:50 trident_drv.so
-rw-r--r-- 1 root root 27624 فروري 5 15:52 vesa_drv.so
-rw-r--r-- 1 root root 157720 اپريل 10 13:56 vmware_drv.so
/usr/lib/xorg/modules/extensions:
total 272
-rw-r--r-- 1 root root 277832 اپريل 16 18:38 libglx.so
为此输入
glxinfo
这是输出
name of display: :0
display: :0 screen: 0
direct rendering: Yes
server glx vendor string: SGI
server glx version string: 1.4
server glx extensions:
GLX_ARB_create_context, GLX_ARB_create_context_profile,
GLX_ARB_fbconfig_float, GLX_ARB_framebuffer_sRGB, GLX_ARB_multisample,
GLX_EXT_create_context_es2_profile, GLX_EXT_framebuffer_sRGB,
GLX_EXT_import_context, GLX_EXT_texture_from_pixmap, GLX_EXT_visual_info,
GLX_EXT_visual_rating, GLX_INTEL_swap_event, GLX_MESA_copy_sub_buffer,
GLX_OML_swap_method, GLX_SGIS_multisample, GLX_SGIX_fbconfig,
GLX_SGIX_pbuffer, GLX_SGIX_visual_select_group, GLX_SGI_swap_control
client glx vendor string: Mesa Project and SGI
client glx version string: 1.4
client glx extensions:
GLX_ARB_create_context, GLX_ARB_create_context_profile,
GLX_ARB_create_context_robustness, GLX_ARB_fbconfig_float,
GLX_ARB_framebuffer_sRGB, GLX_ARB_get_proc_address, GLX_ARB_multisample,
GLX_EXT_create_context_es2_profile, GLX_EXT_fbconfig_packed_float,
GLX_EXT_framebuffer_sRGB, GLX_EXT_import_context,
GLX_EXT_texture_from_pixmap, GLX_EXT_visual_info, GLX_EXT_visual_rating,
GLX_INTEL_swap_event, GLX_MESA_copy_sub_buffer,
GLX_MESA_multithread_makecurrent, GLX_MESA_query_renderer,
GLX_MESA_swap_control, GLX_OML_swap_method, GLX_OML_sync_control,
GLX_SGIS_multisample, GLX_SGIX_fbconfig, GLX_SGIX_pbuffer,
GLX_SGIX_visual_select_group, GLX_SGI_make_current_read,
GLX_SGI_swap_control, GLX_SGI_video_sync
GLX version: 1.4
GLX extensions:
GLX_ARB_create_context, GLX_ARB_create_context_profile,
GLX_ARB_fbconfig_float, GLX_ARB_framebuffer_sRGB,
GLX_ARB_get_proc_address, GLX_ARB_multisample,
GLX_EXT_create_context_es2_profile, GLX_EXT_framebuffer_sRGB,
GLX_EXT_import_context, GLX_EXT_texture_from_pixmap, GLX_EXT_visual_info,
GLX_EXT_visual_rating, GLX_INTEL_swap_event, GLX_MESA_copy_sub_buffer,
GLX_MESA_multithread_makecurrent, GLX_MESA_swap_control,
GLX_OML_swap_method, GLX_OML_sync_control, GLX_SGIS_multisample,
GLX_SGIX_fbconfig, GLX_SGIX_pbuffer, GLX_SGIX_visual_select_group,
GLX_SGI_make_current_read, GLX_SGI_swap_control, GLX_SGI_video_sync
OpenGL vendor string: X.Org
OpenGL renderer string: Gallium 0.4 on AMD CAICOS
OpenGL core profile version string: 3.3 (Core Profile) Mesa 10.1.0
OpenGL core profile shading language version string: 3.30
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
GL_AMD_conservative_depth, GL_AMD_draw_buffers_blend,
GL_AMD_seamless_cubemap_per_texture, GL_AMD_shader_stencil_export,
GL_AMD_shader_trinary_minmax, GL_AMD_vertex_shader_layer,
GL_ANGLE_texture_compression_dxt3, GL_ANGLE_texture_compression_dxt5,
GL_ARB_ES2_compatibility, GL_ARB_base_instance,
GL_ARB_blend_func_extended, GL_ARB_clear_buffer_object,
GL_ARB_conservative_depth, GL_ARB_copy_buffer, GL_ARB_debug_output,
GL_ARB_depth_buffer_float, GL_ARB_depth_clamp, GL_ARB_draw_buffers,
GL_ARB_draw_buffers_blend, GL_ARB_draw_elements_base_vertex,
GL_ARB_draw_instanced, GL_ARB_explicit_attrib_location,
GL_ARB_fragment_coord_conventions, GL_ARB_fragment_shader,
GL_ARB_framebuffer_object, GL_ARB_framebuffer_sRGB,
GL_ARB_get_program_binary, GL_ARB_half_float_pixel,
GL_ARB_half_float_vertex, GL_ARB_instanced_arrays,
GL_ARB_internalformat_query, GL_ARB_invalidate_subdata,
GL_ARB_map_buffer_alignment, GL_ARB_map_buffer_range,
GL_ARB_occlusion_query2, GL_ARB_pixel_buffer_object, GL_ARB_point_sprite,
GL_ARB_provoking_vertex, GL_ARB_robustness, GL_ARB_sampler_objects,
GL_ARB_seamless_cube_map, GL_ARB_shader_bit_encoding,
GL_ARB_shader_objects, GL_ARB_shader_stencil_export,
GL_ARB_shader_texture_lod, GL_ARB_shading_language_420pack,
GL_ARB_shading_language_packing, GL_ARB_sync,
GL_ARB_texture_buffer_object, GL_ARB_texture_buffer_object_rgb32,
GL_ARB_texture_buffer_range, GL_ARB_texture_compression_rgtc,
GL_ARB_texture_cube_map_array, GL_ARB_texture_float,
GL_ARB_texture_mirror_clamp_to_edge, GL_ARB_texture_multisample,
GL_ARB_texture_non_power_of_two, GL_ARB_texture_rectangle,
GL_ARB_texture_rg, GL_ARB_texture_rgb10_a2ui, GL_ARB_texture_storage,
GL_ARB_texture_storage_multisample, GL_ARB_texture_swizzle,
GL_ARB_timer_query, GL_ARB_transform_feedback2,
GL_ARB_transform_feedback3, GL_ARB_transform_feedback_instanced,
GL_ARB_uniform_buffer_object, GL_ARB_vertex_array_bgra,
GL_ARB_vertex_array_object, GL_ARB_vertex_attrib_binding,
GL_ARB_vertex_shader, GL_ARB_vertex_type_10f_11f_11f_rev,
GL_ARB_vertex_type_2_10_10_10_rev, GL_ATI_blend_equation_separate,
GL_ATI_texture_compression_3dc, GL_ATI_texture_float,
GL_ATI_texture_mirror_once, GL_EXT_abgr, GL_EXT_blend_equation_separate,
GL_EXT_draw_buffers2, GL_EXT_draw_instanced, GL_EXT_framebuffer_blit,
GL_EXT_framebuffer_multisample, GL_EXT_framebuffer_multisample_blit_scaled,
GL_EXT_framebuffer_sRGB, GL_EXT_packed_depth_stencil, GL_EXT_packed_float,
GL_EXT_pixel_buffer_object, GL_EXT_provoking_vertex, GL_EXT_texture_array,
GL_EXT_texture_compression_dxt1, GL_EXT_texture_compression_latc,
GL_EXT_texture_compression_rgtc, GL_EXT_texture_compression_s3tc,
GL_EXT_texture_filter_anisotropic, GL_EXT_texture_integer,
GL_EXT_texture_mirror_clamp, GL_EXT_texture_sRGB,
GL_EXT_texture_sRGB_decode, GL_EXT_texture_shared_exponent,
GL_EXT_texture_snorm, GL_EXT_texture_swizzle, GL_EXT_timer_query,
GL_EXT_transform_feedback, GL_EXT_vertex_array_bgra,
GL_IBM_multimode_draw_arrays, GL_KHR_debug, GL_MESA_pack_invert,
GL_MESA_texture_signed_rgba, GL_NV_conditional_render, GL_NV_depth_clamp,
GL_NV_packed_depth_stencil, GL_NV_texture_barrier, GL_NV_vdpau_interop,
GL_OES_EGL_image, GL_OES_read_format, GL_S3_s3tc
OpenGL version string: 3.0 Mesa 10.1.0
OpenGL shading language version string: 1.30
OpenGL context flags: (none)
OpenGL extensions:
GL_AMD_conservative_depth, GL_AMD_draw_buffers_blend,
GL_AMD_seamless_cubemap_per_texture, GL_AMD_shader_stencil_export,
GL_AMD_shader_trinary_minmax, GL_ANGLE_texture_compression_dxt3,
GL_ANGLE_texture_compression_dxt5, GL_APPLE_packed_pixels,
GL_APPLE_vertex_array_object, GL_ARB_ES2_compatibility,
GL_ARB_base_instance, GL_ARB_blend_func_extended,
GL_ARB_clear_buffer_object, GL_ARB_color_buffer_float,
GL_ARB_conservative_depth, GL_ARB_copy_buffer, GL_ARB_debug_output,
GL_ARB_depth_buffer_float, GL_ARB_depth_clamp, GL_ARB_depth_texture,
GL_ARB_draw_buffers, GL_ARB_draw_buffers_blend,
GL_ARB_draw_elements_base_vertex, GL_ARB_draw_instanced,
GL_ARB_explicit_attrib_location, GL_ARB_fragment_coord_conventions,
GL_ARB_fragment_program, GL_ARB_fragment_program_shadow,
GL_ARB_fragment_shader, GL_ARB_framebuffer_object,
GL_ARB_framebuffer_sRGB, GL_ARB_get_program_binary,
GL_ARB_half_float_pixel, GL_ARB_half_float_vertex,
GL_ARB_instanced_arrays, GL_ARB_internalformat_query,
GL_ARB_invalidate_subdata, GL_ARB_map_buffer_alignment,
GL_ARB_map_buffer_range, GL_ARB_multisample, GL_ARB_multitexture,
GL_ARB_occlusion_query, GL_ARB_occlusion_query2,
GL_ARB_pixel_buffer_object, GL_ARB_point_parameters, GL_ARB_point_sprite,
GL_ARB_provoking_vertex, GL_ARB_robustness, GL_ARB_sampler_objects,
GL_ARB_seamless_cube_map, GL_ARB_shader_bit_encoding,
GL_ARB_shader_objects, GL_ARB_shader_stencil_export,
GL_ARB_shader_texture_lod, GL_ARB_shading_language_100,
GL_ARB_shading_language_420pack, GL_ARB_shading_language_packing,
GL_ARB_shadow, GL_ARB_sync, GL_ARB_texture_border_clamp,
GL_ARB_texture_compression, GL_ARB_texture_compression_rgtc,
GL_ARB_texture_cube_map, GL_ARB_texture_cube_map_array,
GL_ARB_texture_env_add, GL_ARB_texture_env_combine,
GL_ARB_texture_env_crossbar, GL_ARB_texture_env_dot3,
GL_ARB_texture_float, GL_ARB_texture_mirror_clamp_to_edge,
GL_ARB_texture_mirrored_repeat, GL_ARB_texture_multisample,
GL_ARB_texture_non_power_of_two, GL_ARB_texture_rectangle,
GL_ARB_texture_rg, GL_ARB_texture_rgb10_a2ui, GL_ARB_texture_storage,
GL_ARB_texture_storage_multisample, GL_ARB_texture_swizzle,
GL_ARB_timer_query, GL_ARB_transform_feedback2,
GL_ARB_transform_feedback3, GL_ARB_transform_feedback_instanced,
GL_ARB_transpose_matrix, GL_ARB_uniform_buffer_object,
GL_ARB_vertex_array_bgra, GL_ARB_vertex_array_object,
GL_ARB_vertex_attrib_binding, GL_ARB_vertex_buffer_object,
GL_ARB_vertex_program, GL_ARB_vertex_shader,
GL_ARB_vertex_type_10f_11f_11f_rev, GL_ARB_vertex_type_2_10_10_10_rev,
GL_ARB_window_pos, GL_ATI_blend_equation_separate, GL_ATI_draw_buffers,
GL_ATI_separate_stencil, GL_ATI_texture_compression_3dc,
GL_ATI_texture_env_combine3, GL_ATI_texture_float,
GL_ATI_texture_mirror_once, 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_compiled_vertex_array,
GL_EXT_copy_texture, GL_EXT_draw_buffers2, GL_EXT_draw_instanced,
GL_EXT_draw_range_elements, GL_EXT_fog_coord, GL_EXT_framebuffer_blit,
GL_EXT_framebuffer_multisample, GL_EXT_framebuffer_multisample_blit_scaled,
GL_EXT_framebuffer_object, GL_EXT_framebuffer_sRGB,
GL_EXT_gpu_program_parameters, GL_EXT_multi_draw_arrays,
GL_EXT_packed_depth_stencil, GL_EXT_packed_float, GL_EXT_packed_pixels,
GL_EXT_pixel_buffer_object, GL_EXT_point_parameters,
GL_EXT_polygon_offset, GL_EXT_provoking_vertex, 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_subtexture, GL_EXT_texture, GL_EXT_texture3D,
GL_EXT_texture_array, GL_EXT_texture_compression_dxt1,
GL_EXT_texture_compression_latc, GL_EXT_texture_compression_rgtc,
GL_EXT_texture_compression_s3tc, GL_EXT_texture_cube_map,
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_integer,
GL_EXT_texture_lod_bias, GL_EXT_texture_mirror_clamp,
GL_EXT_texture_object, GL_EXT_texture_rectangle, GL_EXT_texture_sRGB,
GL_EXT_texture_sRGB_decode, GL_EXT_texture_shared_exponent,
GL_EXT_texture_snorm, GL_EXT_texture_swizzle, GL_EXT_timer_query,
GL_EXT_transform_feedback, GL_EXT_vertex_array, GL_EXT_vertex_array_bgra,
GL_IBM_multimode_draw_arrays, GL_IBM_rasterpos_clip,
GL_IBM_texture_mirrored_repeat, GL_INGR_blend_func_separate, GL_KHR_debug,
GL_MESA_pack_invert, GL_MESA_texture_signed_rgba, GL_MESA_window_pos,
GL_NV_blend_square, GL_NV_conditional_render, GL_NV_depth_clamp,
GL_NV_fog_distance, GL_NV_light_max_exponent, GL_NV_packed_depth_stencil,
GL_NV_primitive_restart, GL_NV_texgen_reflection, GL_NV_texture_barrier,
GL_NV_texture_env_combine4, GL_NV_texture_rectangle, GL_NV_vdpau_interop,
GL_OES_EGL_image, GL_OES_read_format, GL_S3_s3tc,
GL_SGIS_generate_mipmap, GL_SGIS_texture_border_clamp,
GL_SGIS_texture_edge_clamp, GL_SGIS_texture_lod, GL_SUN_multi_draw_arrays
由于体限为30000个字符,输出超过70000,因此我将其余部分剪掉了
下面是所有的源代码,我在终端输入以下代码编译它:
g++ triangles.cpp LoadShaders.cpp -o output -lGL -lglut -lGLU -lGLEW
triangles.cpp:
#include <iostream>
using namespace std;
#include "vgl.h"
#include "LoadShaders.h"
enum VAO_IDs {Triangles, NumVAOs};
enum Buffer_IDs {ArrayBuffer, NumBuffers};
enum Attrib_IDs {vPosition = 0};
GLuint VAOs[NumVAOs];
GLuint Buffers[NumBuffers];
const GLuint NumVertices = 6;
//init
void init(void)
{
glGenVertexArrays(NumVAOs, VAOs);
glBindVertexArray(VAOs[Triangles]);
GLfloat vertices[NumVertices][2] = {
{-0.90, -0.90}, //Triangle 1
{ 0.85, -0.90},
{-0.90, 0.85},
{-0.90, -0.85}, //Triangle 2
{ 0.90, 0.90},
{-0.85, 0.90}
};
glGenBuffers(NumBuffers, Buffers);
glBindBuffer(GL_ARRAY_BUFFER, Buffers[ArrayBuffer]);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
ShaderInfo shaders[] = {
{GL_VERTEX_SHADER, "triangles.vert"},
{GL_FRAGMENT_SHADER, "triagles.frag"},
{GL_NONE, NULL}
};
GLuint program = LoadShaders(shaders);
glUseProgram(program);
glVertexAttribPointer(vPosition, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
glEnableVertexAttribArray(vPosition);
}
//display
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glBindVertexArray(VAOs[Triangles]);
glDrawArrays(GL_TRIANGLES, 0, NumVertices);
glFlush();
}
//main
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA);
glutInitWindowSize(512, 512);
glutInitContextVersion(4, 3);
glutInitContextProfile(GLUT_CORE_PROFILE);
glutCreateWindow(argv[0]);
if(glewInit()) {
cerr << "Unable to initialize GLEW...exiting" << endl;
exit(EXIT_FAILURE);
}
init();
glutDisplayFunc(display);
glutMainLoop();
}
vgl.h:
#ifndef __VGL_H__
#define __VGL_H__
// #define USE_GL3W
#ifdef USE_GL3W
#include <GL3/gl3.h>
#include <GL3/gl3w.h>
#else
#define GLEW_STATIC
#include <GL/glew.h>
#ifdef _MSC_VER
# ifdef _DEBUG
# if (_MSC_VER >= 1600)
# pragma comment (lib, "glew_static_vs2010_d.lib")
# else
# pragma comment (lib, "glew_static_d.lib")
# endif
# else
# if (_MSC_VER >= 1600)
# pragma comment (lib, "glew_static_vs2010.lib")
# else
# pragma comment (lib, "glew_static.lib")
# endif
# endif
#endif
#endif
#define FREEGLUT_STATIC
#include <GL/freeglut.h>
#ifdef _MSC_VER
# ifdef _DEBUG
# if (_MSC_VER >= 1600)
# pragma comment (lib, "freeglut_static_vs2010_d.lib")
# else
# pragma comment (lib, "freeglut_static_d.lib")
# endif
# else
# if (_MSC_VER >= 1600)
# pragma comment (lib, "freeglut_static_vs2010.lib")
# else
# pragma comment (lib, "freeglut_static.lib")
# endif
# endif
#endif
#define BUFFER_OFFSET(x) ((const void*) (x))
#endif /* __VGL_H__ */
LoadShaders.h:
//////////////////////////////////////////////////////////////////////////////
//
// --- LoadShaders.h ---
//
//////////////////////////////////////////////////////////////////////////////
#ifndef __LOAD_SHADERS_H__
#define __LOAD_SHADERS_H__
#include <GL/gl.h>
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
//----------------------------------------------------------------------------
//
// LoadShaders() takes an array of ShaderFile structures, each of which
// contains the type of the shader, and a pointer a C-style character
// string (i.e., a NULL-terminated array of characters) containing the
// entire shader source.
//
// The array of structures is terminated by a final Shader with the
// "type" field set to GL_NONE.
//
// LoadShaders() returns the shader program value (as returned by
// glCreateProgram()) on success, or zero on failure.
//
typedef struct {
GLenum type;
const char* filename;
GLuint shader;
} ShaderInfo;
GLuint LoadShaders( ShaderInfo* );
//----------------------------------------------------------------------------
#ifdef __cplusplus
};
#endif // __cplusplus
#endif // __LOAD_SHADERS_H__
LoadShaders.cpp
//////////////////////////////////////////////////////////////////////////////
//
// --- LoadShaders.cxx ---
//
//////////////////////////////////////////////////////////////////////////////
#include <cstdlib>
#include <cstdio>
#include <iostream>
#define GLEW_STATIC
#include <GL/glew.h>
#include "LoadShaders.h"
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
//----------------------------------------------------------------------------
static const GLchar*
ReadShader( const char* filename )
{
#ifdef WIN32
FILE* infile;
fopen_s( &infile, filename, "rb" );
#else
FILE* infile = fopen( filename, "rb" );
#endif // WIN32
if ( !infile ) {
#ifdef _DEBUG
std::cerr << "Unable to open file '" << filename << "'" << std::endl;
#endif /* DEBUG */
return NULL;
}
fseek( infile, 0, SEEK_END );
int len = ftell( infile );
fseek( infile, 0, SEEK_SET );
GLchar* source = new GLchar[len+1];
fread( source, 1, len, infile );
fclose( infile );
source[len] = 0;
return const_cast<const GLchar*>(source);
}
//----------------------------------------------------------------------------
GLuint
LoadShaders( ShaderInfo* shaders )
{
if ( shaders == NULL ) { return 0; }
GLuint program = glCreateProgram();
ShaderInfo* entry = shaders;
while ( entry->type != GL_NONE ) {
GLuint shader = glCreateShader( entry->type );
entry->shader = shader;
const GLchar* source = ReadShader( entry->filename );
if ( source == NULL ) {
for ( entry = shaders; entry->type != GL_NONE; ++entry ) {
glDeleteShader( entry->shader );
entry->shader = 0;
}
return 0;
}
glShaderSource( shader, 1, &source, NULL );
delete [] source;
glCompileShader( shader );
GLint compiled;
glGetShaderiv( shader, GL_COMPILE_STATUS, &compiled );
if ( !compiled ) {
#ifdef _DEBUG
GLsizei len;
glGetShaderiv( shader, GL_INFO_LOG_LENGTH, &len );
GLchar* log = new GLchar[len+1];
glGetShaderInfoLog( shader, len, &len, log );
std::cerr << "Shader compilation failed: " << log << std::endl;
delete [] log;
#endif /* DEBUG */
return 0;
}
glAttachShader( program, shader );
++entry;
}
#ifdef GL_VERSION_4_1
if ( GLEW_VERSION_4_1 ) {
// glProgramParameteri( program, GL_PROGRAM_SEPARABLE, GL_TRUE );
}
#endif /* GL_VERSION_4_1 */
glLinkProgram( program );
GLint linked;
glGetProgramiv( program, GL_LINK_STATUS, &linked );
if ( !linked ) {
#ifdef _DEBUG
GLsizei len;
glGetProgramiv( program, GL_INFO_LOG_LENGTH, &len );
GLchar* log = new GLchar[len+1];
glGetProgramInfoLog( program, len, &len, log );
std::cerr << "Shader linking failed: " << log << std::endl;
delete [] log;
#endif /* DEBUG */
for ( entry = shaders; entry->type != GL_NONE; ++entry ) {
glDeleteShader( entry->shader );
entry->shader = 0;
}
return 0;
}
return program;
}
//----------------------------------------------------------------------------
#ifdef __cplusplus
}
#endif // __cplusplus
解决方法:
错误代码GLXBadFBConfig表示系统的显示系统(X11服务器图形驱动程序)不支持程序请求的像素格式.如果没有安装OpenGL支持的驱动程序,或者请求的FBConfig超出了GPU的功能,则会发生这种情况.
更新:实际问题
现在您发布了代码,很容易看出问题所在:您的系统使用Xorg / DRI / Mesa项目的开源radeon驱动程序.这些驱动程序仅支持OpenGL-3.3(glxinfo也报告):
OpenGL core profile version string: 3.3 (Core Profile) Mesa 10.1.0
但是,您的程序要求提供OpenGL-4.3上下文
glutInitContextVersion(4, 3);
glutInitContextProfile(GLUT_CORE_PROFILE);
这是您的系统无法满足的请求.因此,你没有得到理想的FBConfig.
请注意,到目前为止,您的程序仅使用OpenGL-3.3中也提供的功能,因此我建议您只需在程序中询问3.3上下文.
在你的情况下,我打赌它是第一种情况:你的系统缺乏正确的驱动程序安装.
为了进一步帮助您,请将以下命令的输出添加到您的问题中:
(lspci | grep VGA) ; \
(dpkg -l | egrep 'xorg-video|glx') ; \
(ls -l /usr/lib/xorg/modules/{drivers,extensions})