Здравствуйте!
Читая мануал по GLX вот отсюда http://plg.lrn.ru/doc/gl-linux/glx.html при прохождении 2-го примера возникли некоторые проблемы!
Во-первых g++ не мог найти библиотеку libGL.so хотя в /usr/lib лежали файлы libGL.so.1 и libGL.so.1.2, а libGL.so небыло, причем libGL.so.1 был ссылкой на 2-ой файл. Сделал копию libGL.so.1.2 с именем libGL.so и компиляция прошла.
Во-вторых после компиляции при запуске примера 2 glx_example2.cpp выдает вот это
X Error of failed request: GLXBadDrawable
Major opcode of failed request: 163 (GLX)
Minor opcode of failed request: 5 (X_GLXMakeCurrent)
Serial number of failed request: 25
Current serial number in output stream: 25связано ли это как-то с той библиотекой которую я скопировал или это из-за другого?? из-за чего это происходит и как решить?
Заранее спасибо!!!
вот текст glx_example2.cpp
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/keysym.h>
#include <GL/gl.h>
#include <GL/glx.h>
#include <stdio.h>
#include <stdlib.h>
int Attr[] = {GLX_RGBA,
GLX_RED_SIZE, 1,
GLX_GREEN_SIZE, 1,
GLX_BLUE_SIZE, 1,
GLX_DEPTH_SIZE, 16,
None};
XVisualInfo *xvVisualInfo;
Colormap cmColorMap;
XSetWindowAttributes winAttr;
GLXContext glXContext;
Display *dpDisplay;
Window win; // Our window
Pixmap pm; // Pixmap
GLXPixmap pm_glx; // GLX Pixmap
GC gc; // Graphics Context
float alpha; // Rotation angle
int Animation=1; // Animation flag
// SetUp OpenGL parameters
void setup()
{
// Print start message
printf("GLX Example (Pixmaps) by Roman Podobedov\n");
printf("EMail: romka@ut.ee\n");
printf("WEB: http://romka.demonews.com\n\n");
printf("Keys:\n");
printf("Space - Start/Stop animation\n");
printf("Escape - Quit\n");
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
// Main redraw function
void redraw()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f, 1.0f, 1.0f);
glPushMatrix();
// Rotate
glRotatef(alpha, 1, 0, 1);
if (Animation) alpha += 1;
if (alpha > 359) alpha = 0;
// Draw figure
glBegin(GL_QUADS);
glVertex3f(-1.0f, -1.0f, -1.0f);
glVertex3f(1.0f, -1.0f, -1.0f);
glVertex3f(1.0f, 1.0f, -1.0f);
glVertex3f(-1.0f, 1.0f, -1.0f);
glVertex3f(-1.0f, -1.0f, 1.0f);
glVertex3f(1.0f, -1.0f, 1.0f);
glVertex3f(1.0f, 1.0f, 1.0f);
glVertex3f(-1.0f, 1.0f, 1.0f);
glVertex3f(-1.0f, -1.0f, -1.0f);
glVertex3f(-1.0f, 1.0f, -1.0f);
glVertex3f(-1.0f, 1.0f, 1.0f);
glVertex3f(-1.0f, -1.0f, 1.0f);
glVertex3f(1.0f, -1.0f, -1.0f);
glVertex3f(1.0f, 1.0f, -1.0f);
glVertex3f(1.0f, 1.0f, 1.0f);
glVertex3f(1.0f, -1.0f, 1.0f);
glEnd();
glPopMatrix();
glFlush();
}
// Resize function
void resize(unsigned int width, unsigned int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-5.0, 5.0, -5.0, 5.0, 2.0, 50.0);
glMatrixMode(GL_MODELVIEW);
glTranslatef(0, 0, -5);
}
// X Event loop
void event_loop()
{
XEvent event;
while (1)
{
if (XPending(dpDisplay))
{
XNextEvent(dpDisplay, &event); // Get next event in queue and copy it to XEvent structure
switch (event.type)
{
case ConfigureNotify: resize(event.xconfigure.width, event.xconfigure.height); break; // Window resize event
case KeyPress: // Keypress event
switch (XLookupKeysym((XKeyEvent *)&event, 0))
{
case XK_Escape: // Escape key is pressed
glXDestroyContext(dpDisplay, glXContext);
XDestroyWindow(dpDisplay, win);
XCloseDisplay(dpDisplay);
exit(0);
break;
case XK_space: Animation = !Animation; break;
}
break;
}
}
redraw(); // Redraw scene
XCopyArea(dpDisplay, pm, win, gc, 0, 0, 640, 480, 0, 0); // Copy Pixmap content to Window
}
}
int main(int argc, char *argv[])
{
// Connect to X Server
dpDisplay = XOpenDisplay(NULL);
if(dpDisplay == NULL) return 0; // Could not open display
// GLX extension is supported?
if(!glXQueryExtension(dpDisplay, NULL, NULL)) return 0; // Return, if X server haven't GLX
// Find visual
xvVisualInfo = glXChooseVisual(dpDisplay, DefaultScreen(dpDisplay), Attr);
if(xvVisualInfo == NULL) return 0; // If Visual info can't be shoosed
// Create new colormap for our window
cmColorMap = XCreateColormap(dpDisplay, RootWindow(dpDisplay, xvVisualInfo->screen), xvVisualInfo->visual, AllocNone);
winAttr.colormap = cmColorMap;
winAttr.border_pixel = 0;
winAttr.background_pixel = 0;
winAttr.event_mask = ExposureMask | ButtonPressMask | StructureNotifyMask | KeyPressMask;
// Create window
win = XCreateWindow(dpDisplay, RootWindow(dpDisplay, xvVisualInfo->screen),
0, 0,
640, 480, // Width and Height
0,
xvVisualInfo->depth, // Depth
InputOutput,
xvVisualInfo->visual,
CWBorderPixel | CWColormap | CWEventMask,
&winAttr);
// Change parameters of the window
XSetStandardProperties(dpDisplay, win,
"GLX Example, http://romka.demonews.com", "GLX Example",
None, argv, argc, NULL);
// Create pixmap
pm = XCreatePixmap(dpDisplay, win, 640, 480, xvVisualInfo->depth);
// Create GLX pixmap
pm_glx = glXCreateGLXPixmap(dpDisplay, xvVisualInfo, pm);
// Create Graphics context for our window (needed for XCopyArea)
gc = XCreateGC(dpDisplay, win, 0, NULL);
// Create OpenGL rendering context
glXContext = glXCreateContext(dpDisplay, xvVisualInfo, None, True);
if(glXContext == NULL) return 0; // Can't create rendering context
// Make context current (rendering to pixmap)
glXMakeCurrent(dpDisplay, pm, glXContext);
// Map window on the display
XMapWindow(dpDisplay, win);
// Set start parameters
setup();
// Enter to the main X loop
event_loop();
return 0;
}