PDA

View Full Version : Problems with OpenGL/GLUT on Linux



maedhros777
03-15-2010, 06:03 PM
Hi, I'm using Ubuntu, and I'm experiencing a problem when running OpenGL/GLUT programs. The window is one place and the intended graphics are always somewhere else. For example, I was trying out a sample GLUT program illustrating fog and here is how it turned out (look at the bottom left of the screen):

http://img705.imageshack.us/img705/4168/screenshotce.png

Thank you for your help, in advance.

ZbuffeR
03-16-2010, 01:28 AM
Looks like a bug in the video driver and/or X server.
(you may have more success on a Ubuntu support forum)
What are your hardware and software specs :
- video card make and model ?
- Ubuntu version ?
- desktop effects enabled or not
- video driver : open source or binary ? version ?
- X server version ?

maedhros777
03-16-2010, 02:02 PM
I'm running Ubuntu 9.10 (Karmic Koala), although I don't know what hardware I'm running. I typed lspci in the terminal, though, and got the following result:



00:00.0 Host bridge: Intel Corporation 82925X/XE Memory Controller Hub (rev 04)
00:01.0 PCI bridge: Intel Corporation 82925X/XE PCI Express Root Port (rev 04)
00:1c.0 PCI bridge: Intel Corporation 82801FB/FBM/FR/FW/FRW (ICH6 Family) PCI Express Port 1 (rev 03)
00:1c.1 PCI bridge: Intel Corporation 82801FB/FBM/FR/FW/FRW (ICH6 Family) PCI Express Port 2 (rev 03)
00:1d.0 USB Controller: Intel Corporation 82801FB/FBM/FR/FW/FRW (ICH6 Family) USB UHCI #1 (rev 03)
00:1d.1 USB Controller: Intel Corporation 82801FB/FBM/FR/FW/FRW (ICH6 Family) USB UHCI #2 (rev 03)
00:1d.2 USB Controller: Intel Corporation 82801FB/FBM/FR/FW/FRW (ICH6 Family) USB UHCI #3 (rev 03)
00:1d.3 USB Controller: Intel Corporation 82801FB/FBM/FR/FW/FRW (ICH6 Family) USB UHCI #4 (rev 03)
00:1d.7 USB Controller: Intel Corporation 82801FB/FBM/FR/FW/FRW (ICH6 Family) USB2 EHCI Controller (rev 03)
00:1e.0 PCI bridge: Intel Corporation 82801 PCI Bridge (rev d3)
00:1e.2 Multimedia audio controller: Intel Corporation 82801FB/FBM/FR/FW/FRW (ICH6 Family) AC'97 Audio Controller (rev 03)
00:1f.0 ISA bridge: Intel Corporation 82801FB/FR (ICH6/ICH6R) LPC Interface Bridge (rev 03)
00:1f.1 IDE interface: Intel Corporation 82801FB/FBM/FR/FW/FRW (ICH6 Family) IDE Controller (rev 03)
00:1f.2 IDE interface: Intel Corporation 82801FR/FRW (ICH6R/ICH6RW) SATA Controller (rev 03)
00:1f.3 SMBus: Intel Corporation 82801FB/FBM/FR/FW/FRW (ICH6 Family) SMBus Controller (rev 03)
01:00.0 VGA compatible controller: ATI Technologies Inc RV370 5B60 [Radeon X300 (PCIE)]
01:00.1 Display controller: ATI Technologies Inc RV370 [Radeon X300SE]
02:00.0 Ethernet controller: Broadcom Corporation NetXtreme BCM5751 Gigabit Ethernet PCI Express (rev 01)
04:01.0 Modem: Intel Corporation FA82537EP 56K V.92 Data/Fax Modem PCI (rev 04)
04:02.0 FireWire (IEEE 1394): Agere Systems FW322/323 (rev 61)

ZbuffeR
03-16-2010, 03:36 PM
What are the 10 or 20 first lines of glxinfo ?

maedhros777
03-16-2010, 04:28 PM
Here's the result of glxinfo, minus the OpenGL extensions:



name of display: :0.0
display: :0 screen: 0
direct rendering: Yes
server glx vendor string: SGI
server glx version string: 1.2
server glx extensions:
GLX_ARB_multisample, GLX_EXT_import_context, GLX_EXT_texture_from_pixmap,
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_visual_select_group
client glx vendor string: SGI
client glx version string: 1.4
client glx extensions:
GLX_ARB_get_proc_address, GLX_ARB_multisample, GLX_EXT_import_context,
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_OML_swap_method, GLX_OML_sync_control,
GLX_SGI_make_current_read, GLX_SGI_swap_control, GLX_SGI_video_sync,
GLX_SGIS_multisample, GLX_SGIX_fbconfig, GLX_SGIX_pbuffer,
GLX_SGIX_visual_select_group, GLX_EXT_texture_from_pixmap
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_MESA_copy_sub_buffer,
GLX_MESA_swap_control, GLX_MESA_swap_frame_usage, 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_visual_select_group
OpenGL vendor string: DRI R300 Project
OpenGL renderer string: Mesa DRI R300 (RV380 5B60) 20090101 x86/MMX/SSE2 TCL
OpenGL version string: 1.5 Mesa 7.6

ZbuffeR
03-16-2010, 04:52 PM
You still have not told your Ubuntu version?

You might want to try disabling or enabling compiz desktop effects, check if that changes something :
http://ohioloco.ubuntuforums.org/showthread.php?p=8337536#5

maedhros777
03-16-2010, 05:08 PM
I'm running Ubuntu 9.10 (Karmic Koala). Actually I'd been having a problem with Blender as well and that fixed it, luckily, but I still have a problem with OpenGL. Now when I run the program the screen goes black and when I click with the mouse, it goes back to the regular screen but the graphics still are not on the window (although they're closer).

nigels
03-27-2010, 12:12 PM
As a DX9 generation card, it's probably worth trying the AMD driver installer.

See:
http://en.wikipedia.org/wiki/Radeon_X300
http://support.amd.com/us/gpudownload/Pages/index.aspx

maedhros777
03-29-2010, 06:07 PM
Wait, which installer is the AMD driver installer? I tried the second link, but I wasn't really sure which product family to choose.

IF_EXIST
05-05-2010, 08:50 PM
I think I have the same problem...

http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=277184#Post2771 84

I compile some OPENGL example in ubuntu 9.10,
they are be full screen ,and color is black ,no anything
while I click the window, then have a small box.
that is a really opengl window, while you click it ,
FullScreen and Black again... T.T

I just know if you choose “GLUT_DOUBLE” DisplayMode,
then haven't this problem.

Why?

ZbuffeR
05-06-2010, 12:20 AM
You should always use double buffering anyway.

Or use a lot of glFlush(), which is bad for performance.

maedhros777
05-07-2010, 03:46 PM
Hm...well, I tried it with GLUT_DOUBLE and it didn't work for me. It's probably something with both of our graphics cards/drivers, but I bet we have different ones.

IF_EXIST
05-07-2010, 05:54 PM
but I bet we have different ones.
................

maedhros777
05-08-2010, 08:06 AM
Different graphics cards and/or drivers. By the way, if anyone could solve this problem it would be very much appreciated. I haven't been able to work with OpenGL on this computer in months.

IF_EXIST
05-08-2010, 09:58 PM
Can you upload a code or an opengl program to test?
We can compare something with opengl program.
Just for test....


An example of Code::blocks 8.02
it was running correctly on my computer


/* A simple program to show how to set up an X window for OpenGL rendering.
* X86 compilation: gcc -o -L/usr/X11/lib main main.c -lGL -lX11
* X64 compilation: gcc -o -L/usr/X11/lib64 main main.c -lGL -lX11
*/
#include <stdio.h>
#include <stdlib.h>

#include <GL/glx.h> /* this includes the necessary X headers */
#include <GL/gl.h>

#include <X11/X.h> /* X11 constant (e.g. TrueColor) */
#include <X11/keysym.h>

static int snglBuf[] = {GLX_RGBA, GLX_DEPTH_SIZE, 16, None};
static int dblBuf[] = {GLX_RGBA, GLX_DEPTH_SIZE, 16, GLX_DOUBLEBUFFER, None};

Display *dpy;
Window win;
GLfloat xAngle = 42.0, yAngle = 82.0, zAngle = 112.0;
GLboolean doubleBuffer = GL_TRUE;

void fatalError(char *message)
{
fprintf(stderr, "main: %s\n", message);
exit(1);
}

void redraw(void)
{
static GLboolean displayListInited = GL_FALSE;

if (displayListInited)
{
/* if display list already exists, just execute it */
glCallList(1);
}
else
{
/* otherwise compile and execute to create the display list */
glNewList(1, GL_COMPILE_AND_EXECUTE);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

/* front face */
glBegin(GL_QUADS);
glColor3f(0.0, 0.7, 0.1); /* green */
glVertex3f(-1.0, 1.0, 1.0);
glVertex3f(1.0, 1.0, 1.0);
glVertex3f(1.0, -1.0, 1.0);
glVertex3f(-1.0, -1.0, 1.0);

/* back face */
glColor3f(0.9, 1.0, 0.0); /* yellow */
glVertex3f(-1.0, 1.0, -1.0);
glVertex3f(1.0, 1.0, -1.0);
glVertex3f(1.0, -1.0, -1.0);
glVertex3f(-1.0, -1.0, -1.0);

/* top side face */
glColor3f(0.2, 0.2, 1.0); /* blue */
glVertex3f(-1.0, 1.0, 1.0);
glVertex3f(1.0, 1.0, 1.0);
glVertex3f(1.0, 1.0, -1.0);
glVertex3f(-1.0, 1.0, -1.0);

/* bottom side face */
glColor3f(0.7, 0.0, 0.1); /* red */
glVertex3f(-1.0, -1.0, 1.0);
glVertex3f(1.0, -1.0, 1.0);
glVertex3f(1.0, -1.0, -1.0);
glVertex3f(-1.0, -1.0, -1.0);
glEnd();
glEndList();
displayListInited = GL_TRUE;
}
if (doubleBuffer)
glXSwapBuffers(dpy, win);/* buffer swap does implicit glFlush */
else
glFlush(); /* explicit flush for single buffered case */
}

int main(int argc, char **argv)
{
XVisualInfo *vi;
Colormap cmap;
XSetWindowAttributes swa;
GLXContext cx;
XEvent event;
GLboolean needRedraw = GL_FALSE, recalcModelView = GL_TRUE;
int dummy;

/*** (1) open a connection to the X server ***/

dpy = XOpenDisplay(NULL);
if (dpy == NULL)
fatalError("could not open display");

/*** (2) make sure OpenGL's GLX extension supported ***/

if(!glXQueryExtension(dpy, &amp;dummy, &amp;dummy))
fatalError("X server has no OpenGL GLX extension");

/*** (3) find an appropriate visual ***/

/* find an OpenGL-capable RGB visual with depth buffer */
vi = glXChooseVisual(dpy, DefaultScreen(dpy), dblBuf);
if (vi == NULL)
{
vi = glXChooseVisual(dpy, DefaultScreen(dpy), snglBuf);
if (vi == NULL) fatalError("no RGB visual with depth buffer");
doubleBuffer = GL_FALSE;
}
if(vi->class != TrueColor)
fatalError("TrueColor visual required for this program");

/*** (4) create an OpenGL rendering context ***/

/* create an OpenGL rendering context */
cx = glXCreateContext(dpy, vi, /* no shared dlists */ None,
/* direct rendering if possible */ GL_TRUE);
if (cx == NULL)
fatalError("could not create rendering context");

/*** (5) create an X window with the selected visual ***/

/* create an X colormap since probably not using default visual */
cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual, AllocNone);
swa.colormap = cmap;
swa.border_pixel = 0;
swa.event_mask = KeyPressMask | ExposureMask
| ButtonPressMask | StructureNotifyMask;
win = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0,
300, 300, 0, vi->depth, InputOutput, vi->visual,
CWBorderPixel | CWColormap | CWEventMask, &amp;swa);
XSetStandardProperties(dpy, win, "main", "main", None,
argv, argc, NULL);

/*** (6) bind the rendering context to the window ***/

glXMakeCurrent(dpy, win, cx);

/*** (7) request the X window to be displayed on the screen ***/

XMapWindow(dpy, win);

/*** (8) configure the OpenGL context for rendering ***/

glEnable(GL_DEPTH_TEST); /* enable depth buffering */
glDepthFunc(GL_LESS); /* pedantic, GL_LESS is the default */
glClearDepth(1.0); /* pedantic, 1.0 is the default */

/* frame buffer clears should be to black */
glClearColor(0.0, 0.0, 0.0, 0.0);

/* set up projection transform */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 10.0);
/* establish initial viewport */
/* pedantic, full window size is default viewport */
glViewport(0, 0, 300, 300);

printf( "Press left mouse button to rotate around X axis\n" );
printf( "Press middle mouse button to rotate around Y axis\n" );
printf( "Press right mouse button to rotate around Z axis\n" );
printf( "Press ESC to quit the application\n" );

/*** (9) dispatch X events ***/

while (1)
{
do
{
XNextEvent(dpy, &amp;event);
switch (event.type)
{
case KeyPress:
{
KeySym keysym;
XKeyEvent *kevent;
char buffer[1];
/* It is necessary to convert the keycode to a
* keysym before checking if it is an escape */
kevent = (XKeyEvent *) &event;
if ( (XLookupString((XKeyEvent *)&amp;event,buffer,1,&amp;keysym,NULL) == 1)
&amp;&amp; (keysym == (KeySym)XK_Escape) )
exit(0);
break;
}
case ButtonPress:
recalcModelView = GL_TRUE;
switch (event.xbutton.button)
{
case 1: xAngle += 10.0;
break;
case 2: yAngle += 10.0;
break;
case 3: zAngle += 10.0;
break;
}
break;
case ConfigureNotify:
glViewport(0, 0, event.xconfigure.width,
event.xconfigure.height);
/* fall through... */
case Expose:
needRedraw = GL_TRUE;
break;
}
} while(XPending(dpy)); /* loop to compress events */

if (recalcModelView)
{
glMatrixMode(GL_MODELVIEW);

/* reset modelview matrix to the identity matrix */
glLoadIdentity();

/* move the camera back three units */
glTranslatef(0.0, 0.0, -3.0);

/* rotate by X, Y, and Z angles */
glRotatef(xAngle, 0.1, 0.0, 0.0);
glRotatef(yAngle, 0.0, 0.1, 0.0);
glRotatef(zAngle, 0.0, 0.0, 1.0);

recalcModelView = GL_FALSE;
needRedraw = GL_TRUE;
}
if (needRedraw)
{
redraw();
needRedraw = GL_FALSE;
}
}

return 0;
}

maedhros777
05-09-2010, 06:36 AM
Doesn't exactly work. It shows the correct graphics, but it's not on the window. See this screenshot:

http://img63.imageshack.us/img63/5938/screenshotkm.png

IF_EXIST
05-09-2010, 07:15 AM
O_o Oh , I can't see the screenshot......
It should be a different problem.
But I want to see another person to solve this problem.
Good luck to you.

maedhros777
05-09-2010, 07:45 AM
Thanks, same to you.

ugluk
05-18-2010, 02:20 AM
Whenever I say that ubuntu is not very good for development I get flamed. But maybe you could try some other distro, with which you will better and more recent development tools, as well as drivers, than with Ubuntu. One candidate would be gentoo linux.

Dark Photon
05-18-2010, 05:28 AM
Whenever I say that ubuntu is not very good for development I get flamed. But maybe you could try some other distro, with which you will better and more recent development tools, as well as drivers, than with Ubuntu. One candidate would be gentoo linux.
Well, to each his own, but I personally wouldn't recommend Gentoo. You end up building everything yourself and wasting hours and much CPU/clock time updating your system. For the average Joe-user on Linux, this is completely ridiculous and provides no advantage.

Let me throw in a vote for OpenSuSE (http://www.opensuse.org). Great dev tools, package manager, pre-built packages, GUI configuration tools and installation, on-line update and package install, and a new OpenSuSE version (including all packages) released about every 6 months. Good no-hastle dev distro IMO.

maedhros777
05-18-2010, 02:11 PM
Thanks for your suggestions, but I'll stick with Ubuntu for now (I might try OpenSUSE sometime, though). But in any case, if there are drivers in either Gentoo or OpenSUSE that work with my graphics card, couldn't I just use them in Ubuntu? Would you happen to know of any?

ugluk
05-18-2010, 04:15 PM
What can I say? With gentoo you get the newest mesa drivers (which you appear to be using, google for it) without having to bother with installation and setup. So if you neglect the compilation time delay, everything is the same as with OpenSUSE, you can even install some GUI tools for choosing the ebuilds, if that is your thing. The fact that everything builds from source makes the resulting binaries (if you configure CFLAGS correctly) run faster. If you card and/or machine are old, then this makes for a positive user experience. One of my machines is a crappy old 256MB machine and with LXDE, prelink and some other tweaks, it can easily be used for development. Ubuntu steals valuable RAM with KDE or XFCE.

But for the average Joe, it's a bit much. You need to configure and compile the kernel yourself, for example (there is a tool to help you with that, if that's your thing). All taken into account, Gentoo is friendlier than the various *BSDs, in my opinion.

So maybe try SUSE first and Gentoo later.

BTW: I myself have experienced mesa bugs when trying my binaries on the 256MB machine, particulary when calling glMultiDrawElements(). In fact there's an enduring mystery with this, as quake3, enemy-territory and tremulous games somehow "detect" that glMultiDrawElements() is bugged and switch to glDrawElements() automatically.

Dark Photon
05-18-2010, 05:25 PM
All taken into account, Gentoo is friendlier than the various *BSDs, in my opinion.
Beg to differ on that. I used to run FreeBSD before Linux -- never had to build my own kernel or all my own packages. That would have been ridiculous.

Dark Photon
05-18-2010, 05:30 PM
But in any case, if there are drivers in either Gentoo or OpenSUSE that work with my graphics card, couldn't I just use them in Ubuntu? Would you happen to know of any?
The free drivers, the NVidia proprietary drivers, and the ATI proprietary drivers should all work just fine either way. With the latter two, you just run their install script, which builds a driver kernel module. They're more interested in what kernel you're running than what distro you're running.

ugluk
05-18-2010, 07:01 PM
I tried to install freebsd nvidia drivers on my FreeBSD install once and it required kernel sources to be present on the hard drive. So even though you may not have needed to compile the kernel yourself, you still needed to install the kernel sources. If one doesn't have the luxury of a nvidia card, you need to compile the kernel yourself.

With PC-BSD there the nvidia & ATI (for old cards) drivers come prepackaged, but who would use PC-BSD for development?

Dark Photon
05-19-2010, 05:04 AM
I tried to install freebsd nvidia drivers on my FreeBSD install once and it required kernel sources to be present on the hard drive. So even though you may not have needed to compile the kernel yourself, you still needed to install the kernel sources. If one doesn't have the luxury of a nvidia card, you need to compile the kernel yourself.
So you are talking FreeBSD specifically? Interesting.

On Linux with ATI or NVidia, that is definitely not the case. Kernel modules have obviated that need for many years.