I installed the OpenGL in Linux server (Ubuntu16.04) without a graphical interface, install command below:
apt-get install build-essential libgl1-mesa-dev libglu1-mesa-dev
apt-get install freeglut3-dev libglew1.10 libglew-dev libgl1-mesa-glx libxmu-dev
apt-get install libglew-dev libsdl2-dev libsdl2-image-dev libglm-dev libfreetype6-dev
apt-get install mesa-utils
now, I compile light.c
by gcc light.c -o light -lGL -lglut
.
I want to display it in my Windows mechine by XMing server.
code:
#include <GL/glut.h>
#include <stdlib.h>
void init ( void )
{
GLfloat mat_specular [ ] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat mat_shininess [ ] = { 50.0 };
GLfloat light_position [ ] = { 1.0, 1.0, 1.0, 0.0 };
glClearColor ( 0.0, 0.0, 0.0, 0.0 );
glShadeModel ( GL_SMOOTH );
glMaterialfv ( GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv ( GL_FRONT, GL_SHININESS, mat_shininess);
glLightfv ( GL_LIGHT0, GL_POSITION, light_position);
glEnable (GL_LIGHTING);
glEnable (GL_LIGHT0);
glEnable (GL_DEPTH_TEST);
}
void display ( void )
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidSphere (1.0, 40, 50);
glFlush ();
}
int main(int argc, char** argv)
{
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize (300, 300);
glutInitWindowPosition (100, 100);
glutCreateWindow ( argv [ 0 ] );
init ( );
glutDisplayFunc ( display );
glutMainLoop( );
return 0;
}
but, I get a error:
freeglut (./light): ERROR: Internal error <FBConfig with necessary capabilities not found> in function fgOpenWindow
I search this problem in google, and find some method, but they are not available.
glxinfo
is good.
name of display: :10.0
display: :10 screen: 0
direct rendering: No (LIBGL_ALWAYS_INDIRECT set)
server glx vendor string: SGI
server glx version string: 1.2
server glx extensions:
GLX_ARB_multisample, GLX_EXT_import_context, GLX_EXT_visual_info,
GLX_EXT_visual_rating, GLX_OML_swap_method, GLX_SGIS_multisample,
GLX_SGIX_fbconfig, GLX_SGIX_hyperpipe, GLX_SGIX_swap_barrier,
GLX_SGI_make_current_read
client glx vendor string: NVIDIA Corporation
client glx version string: 1.4
client glx extensions:
GLX_ARB_context_flush_control, GLX_ARB_create_context,
GLX_ARB_create_context_profile, GLX_ARB_create_context_robustness,
GLX_ARB_fbconfig_float, GLX_ARB_get_proc_address, GLX_ARB_multisample,
GLX_EXT_buffer_age, GLX_EXT_create_context_es2_profile,
GLX_EXT_create_context_es_profile, GLX_EXT_fbconfig_packed_float,
GLX_EXT_framebuffer_sRGB, GLX_EXT_import_context, GLX_EXT_stereo_tree,
GLX_EXT_swap_control, GLX_EXT_swap_control_tear,
GLX_EXT_texture_from_pixmap, GLX_EXT_visual_info, GLX_EXT_visual_rating,
GLX_NV_copy_buffer, GLX_NV_copy_image, GLX_NV_delay_before_swap,
GLX_NV_float_buffer, GLX_NV_multisample_coverage, GLX_NV_present_video,
GLX_NV_robustness_video_memory_purge, GLX_NV_swap_group,
GLX_NV_video_capture, GLX_NV_video_out, GLX_SGIX_fbconfig,
GLX_SGIX_pbuffer, GLX_SGI_swap_control, GLX_SGI_video_sync
GLX version: 1.2
GLX extensions:
GLX_ARB_get_proc_address, GLX_ARB_multisample, GLX_EXT_import_context,
GLX_EXT_visual_info, GLX_EXT_visual_rating, GLX_SGIX_fbconfig
OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: GeForce GT 705/PCIe/SSE2
OpenGL version string: 1.2 (4.5.0 NVIDIA 368.39)
OpenGL extensions:
GL_ARB_depth_texture, GL_ARB_imaging, GL_ARB_multitexture,
GL_ARB_point_parameters, GL_ARB_point_sprite, GL_ARB_shadow,
GL_ARB_texture_border_clamp, 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_transpose_matrix,
GL_ARB_window_pos, GL_ATI_texture_mirror_once, 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_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_edge_clamp, GL_EXT_texture_env_add,
GL_EXT_texture_env_combine, GL_EXT_texture_env_dot3, GL_EXT_texture_lod,
GL_EXT_texture_lod_bias, GL_EXT_texture_object, GL_EXT_vertex_array,
GL_IBM_texture_mirrored_repeat, GL_NV_blend_square, GL_NV_point_sprite,
GL_NV_texgen_reflection, GL_NV_texture_rectangle, GL_SGIS_generate_mipmap,
GL_SGIS_texture_lod, GL_SGIX_depth_texture, GL_SGIX_shadow
32 GLX Visuals
visual x bf lv rg d st colorbuffer sr ax dp st accumbuffer ms cav
id dep cl sp sz l ci b ro r g b a F gb bf th cl r g b a ns b eat
----------------------------------------------------------------------------
0x022 24 tc 1 24 0 r . . 8 8 8 0 . . 0 0 0 0 0 0 0 0 0 None
0x023 24 tc 1 24 0 r . . 8 8 8 0 . . 0 0 0 16 16 16 16 0 0 None
0x024 24 tc 1 24 0 r . . 8 8 8 0 . . 0 0 8 0 0 0 0 0 0 None
0x025 24 tc 1 24 0 r . . 8 8 8 0 . . 0 0 8 16 16 16 16 0 0 None
0x026 24 tc 1 24 0 r y . 8 8 8 0 . . 0 0 0 0 0 0 0 0 0 None
0x027 24 tc 1 24 0 r y . 8 8 8 0 . . 0 0 0 16 16 16 16 0 0 None
0x028 24 tc 1 24 0 r y . 8 8 8 0 . . 0 0 8 0 0 0 0 0 0 None
0x029 24 tc 1 24 0 r y . 8 8 8 0 . . 0 0 8 16 16 16 16 1172601720 0 None
0x02a 24 tc 1 24 0 r . . 8 8 8 0 . . 2 0 0 0 0 0 0 1 4 None
0x02b 24 tc 1 24 0 r . . 8 8 8 0 . . 2 0 0 16 16 16 16 0 0 None
0x02c 24 tc 1 24 0 r . . 8 8 8 0 . . 2 0 8 0 0 0 0 26272464 0 None
0x02d 24 tc 1 24 0 r . . 8 8 8 0 . . 2 0 8 16 16 16 16 26259104 0 None
0x02e 24 tc 1 24 0 r y . 8 8 8 0 . . 2 0 0 0 0 0 0 0 0 None
0x02f 24 tc 1 24 0 r y . 8 8 8 0 . . 2 0 0 16 16 16 16 32 0 None
0x030 24 tc 1 24 0 r y . 8 8 8 0 . . 2 0 8 0 0 0 0 0 0 None
0x031 24 tc 1 24 0 r y . 8 8 8 0 . . 2 0 8 16 16 16 16 0 0 None
0x032 24 tc 1 24 0 r . . 8 8 8 0 . . 0 24 0 0 0 0 0 0 0 None
0x033 24 tc 1 24 0 r . . 8 8 8 0 . . 0 24 0 16 16 16 16 0 0 None
0x034 24 tc 1 24 0 r . . 8 8 8 0 . . 0 24 8 0 0 0 0 26262256 1 None
0x035 24 tc 1 24 0 r . . 8 8 8 0 . . 0 24 8 16 16 16 16 26259056 0 None
0x036 24 tc 1 24 0 r y . 8 8 8 0 . . 0 24 0 0 0 0 0 0 0 None
0x037 24 tc 1 24 0 r y . 8 8 8 0 . . 0 24 0 16 16 16 16 0 0 None
0x038 24 tc 1 24 0 r y . 8 8 8 0 . . 0 24 8 0 0 0 0 0 0 None
0x039 24 tc 1 24 0 r y . 8 8 8 0 . . 0 24 8 16 16 16 16 0 0 None
0x03a 24 tc 1 24 0 r . . 8 8 8 0 . . 2 24 0 0 0 0 0 0 0 None
0x03b 24 tc 1 24 0 r . . 8 8 8 0 . . 2 24 0 16 16 16 16 0 0 None
0x03c 24 tc 1 24 0 r . . 8 8 8 0 . . 2 24 8 0 0 0 0 0 0 None
0x03d 24 tc 1 24 0 r . . 8 8 8 0 . . 2 24 8 16 16 16 16 0 0 None
0x03e 24 tc 1 24 0 r y . 8 8 8 0 . . 2 24 0 0 0 0 0 0 0 None
0x03f 24 tc 1 24 0 r y . 8 8 8 0 . . 2 24 0 16 16 16 16 0 0 None
0x040 24 tc 1 24 0 r y . 8 8 8 0 . . 2 24 8 0 0 0 0 0 0 None
0x041 24 tc 1 24 0 r y . 8 8 8 0 . . 2 24 8 16 16 16 16 0 0 None
32 GLXFBConfigs:
visual x bf lv rg d st colorbuffer sr ax dp st accumbuffer ms cav
id dep cl sp sz l ci b ro r g b a F gb bf th cl r g b a ns b eat
----------------------------------------------------------------------------
0x022 24 tc 1 24 0 . . 8 8 8 0 . . 0 0 0 0 0 0 0 0 0 None
0x023 24 tc 1 24 0 . . 8 8 8 0 . . 0 0 0 16 16 16 16 0 0 None
0x024 24 tc 1 24 0 . . 8 8 8 0 . . 0 0 8 0 0 0 0 0 0 None
0x025 24 tc 1 24 0 . . 8 8 8 0 . . 0 0 8 16 16 16 16 0 0 None
0x026 24 tc 1 24 0 y . 8 8 8 0 . . 0 0 0 0 0 0 0 0 0 None
0x027 24 tc 1 24 0 y . 8 8 8 0 . . 0 0 0 16 16 16 16 0 0 None
0x028 24 tc 1 24 0 y . 8 8 8 0 . . 0 0 8 0 0 0 0 0 0 None
0x029 24 tc 1 24 0 y . 8 8 8 0 . . 0 0 8 16 16 16 16 0 0 None
0x02a 24 tc 1 24 0 . . 8 8 8 0 . . 2 0 0 0 0 0 0 0 0 None
0x02b 24 tc 1 24 0 . . 8 8 8 0 . . 2 0 0 16 16 16 16 0 0 None
0x02c 24 tc 1 24 0 . . 8 8 8 0 . . 2 0 8 0 0 0 0 0 0 None
0x02d 24 tc 1 24 0 . . 8 8 8 0 . . 2 0 8 16 16 16 16 0 0 None
0x02e 24 tc 1 24 0 y . 8 8 8 0 . . 2 0 0 0 0 0 0 0 0 None
0x02f 24 tc 1 24 0 y . 8 8 8 0 . . 2 0 0 16 16 16 16 0 0 None
0x030 24 tc 1 24 0 y . 8 8 8 0 . . 2 0 8 0 0 0 0 0 0 None
0x031 24 tc 1 24 0 y . 8 8 8 0 . . 2 0 8 16 16 16 16 0 0 None
0x032 24 tc 1 24 0 . . 8 8 8 0 . . 0 24 0 0 0 0 0 0 0 None
0x033 24 tc 1 24 0 . . 8 8 8 0 . . 0 24 0 16 16 16 16 0 0 None
0x034 24 tc 1 24 0 . . 8 8 8 0 . . 0 24 8 0 0 0 0 0 0 None
0x035 24 tc 1 24 0 . . 8 8 8 0 . . 0 24 8 16 16 16 16 0 0 None
0x036 24 tc 1 24 0 y . 8 8 8 0 . . 0 24 0 0 0 0 0 0 0 None
0x037 24 tc 1 24 0 y . 8 8 8 0 . . 0 24 0 16 16 16 16 0 0 None
0x038 24 tc 1 24 0 y . 8 8 8 0 . . 0 24 8 0 0 0 0 0 0 None
0x039 24 tc 1 24 0 y . 8 8 8 0 . . 0 24 8 16 16 16 16 0 0 None
0x03a 24 tc 1 24 0 . . 8 8 8 0 . . 2 24 0 0 0 0 0 0 0 None
0x03b 24 tc 1 24 0 . . 8 8 8 0 . . 2 24 0 16 16 16 16 0 0 None
0x03c 24 tc 1 24 0 . . 8 8 8 0 . . 2 24 8 0 0 0 0 0 0 None
0x03d 24 tc 1 24 0 . . 8 8 8 0 . . 2 24 8 16 16 16 16 0 0 None
0x03e 24 tc 1 24 0 y . 8 8 8 0 . . 2 24 0 0 0 0 0 0 0 None
0x03f 24 tc 1 24 0 y . 8 8 8 0 . . 2 24 0 16 16 16 16 0 0 None
0x040 24 tc 1 24 0 y . 8 8 8 0 . . 2 24 8 0 0 0 0 0 0 None
0x041 24 tc 1 24 0 y . 8 8 8 0 . . 2 24 8 16 16 16 16 0 0 None
glxdemo
,glxgears
,glxheads
are also good.
When I run the Xlib
code, it is good. Compile is by gcc -o quad quad.c -lX11 -lGL -lGLU
// -- Written in C -- //
#include<stdio.h>
#include<stdlib.h>
#include<X11/X.h>
#include<X11/Xlib.h>
#include<GL/gl.h>
#include<GL/glx.h>
#include<GL/glu.h>
Display *dpy;
Window root;
GLint att[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None };
XVisualInfo *vi;
Colormap cmap;
XSetWindowAttributes swa;
Window win;
GLXContext glc;
XWindowAttributes gwa;
XEvent xev;
void DrawAQuad() {
glClearColor(1.0, 1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1., 1., -1., 1., 1., 20.);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0., 0., 10., 0., 0., 0., 0., 1., 0.);
glBegin(GL_QUADS);
glColor3f(1., 0., 0.); glVertex3f(-.75, -.75, 0.);
glColor3f(0., 1., 0.); glVertex3f( .75, -.75, 0.);
glColor3f(0., 0., 1.); glVertex3f( .75, .75, 0.);
glColor3f(1., 1., 0.); glVertex3f(-.75, .75, 0.);
glEnd();
}
int main(int argc, char *argv[]) {
dpy = XOpenDisplay(NULL);
if(dpy == NULL) {
printf("\n\tcannot connect to X server\n\n");
exit(0);
}
root = DefaultRootWindow(dpy);
vi = glXChooseVisual(dpy, 0, att);
if(vi == NULL) {
printf("\n\tno appropriate visual found\n\n");
exit(0);
}
else {
printf("\n\tvisual %p selected\n", (void *)vi->visualid); /* %p creates hexadecimal output like in glxinfo */
}
cmap = XCreateColormap(dpy, root, vi->visual, AllocNone);
swa.colormap = cmap;
swa.event_mask = ExposureMask | KeyPressMask;
win = XCreateWindow(dpy, root, 0, 0, 600, 600, 0, vi->depth, InputOutput, vi->visual, CWColormap | CWEventMask, &swa);
XMapWindow(dpy, win);
XStoreName(dpy, win, "VERY SIMPLE APPLICATION");
glc = glXCreateContext(dpy, vi, NULL, GL_TRUE);
glXMakeCurrent(dpy, win, glc);
glEnable(GL_DEPTH_TEST);
while(1) {
XNextEvent(dpy, &xev);
if(xev.type == Expose) {
XGetWindowAttributes(dpy, win, &gwa);
glViewport(0, 0, gwa.width, gwa.height);
DrawAQuad();
glXSwapBuffers(dpy, win);
}
else if(xev.type == KeyPress) {
glXMakeCurrent(dpy, None, NULL);
glXDestroyContext(dpy, glc);
XDestroyWindow(dpy, win);
XCloseDisplay(dpy);
exit(0);
}
} /* this closes while(1) { */
} /* this is the } which closes int main(int argc, char *argv[]) { */
What should I do?
Thanks.
direct rendering: No (LIBGL_ALWAYS_INDIRECT set)
Make sure you aren't running afoul of this bug:
2.4.06 doesn't render on remote X server from ubuntu client.
Ubuntu seems to be using freeglut now, and while it renders ok to the local display it fails to draw via GLX on a remote display. Maybe it doesn't get a valid context because glGetString(gl_version) returns null. However glutGet(GLUT_DISPLAY_MODE_POSSIBLE) returns true, and glxgears and glxinfo both work ok, so it appears to be a freeglut problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With