Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


GLUT in Linux

This topic is 5554 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I wrote a game in GLUT using MSVC++ (gasp...a Linux user using a Microsoft product?) I recently installed Linux (SuSE 8.2) and tried compiling my game on it. Interestingly enough, MSVC doesn''t allow you to have to for loops, both starting with for(int i;... in the same function, and you have to remove the int from the second for, while gcc considers a variable declared in the initialization of a for loop to be local to the for loop. Anyway, after I fixed that, I successfully got it to compile (with -lglut -lGLU -lGL). Then I ran it. It gives a segmentation fault, and when I added a couple of printf''s, I discovered that the segmentation fault occurs right from the first line (of main): glutInit(&argc, argv); Out of curiosity, I tried commenting out that line, and it successfully ran glutInitDisplayMode, but it gave another segmentation fault at glutEnterGameMode. Does anyone know what my problem is? And how do I get more information about segmentation faults? I''ve never really done any major programming in Linux but I couldn''t even get it to compile in KDevelop and I couldn''t work out how to use the debuggers that come with my distribution (DDD and Debugger). Thank you for your help, Shalom

Share this post

Link to post
Share on other sites
I''m not sure if this will be of any help, but try going to your program''s directory and running the following from a console, you''ll probably prefer KDE''s konsole if you''re running SuSE, it really doesn''t matter.

gdb your_executable''s_filename

this should print out some messages welcoming you to the GNU debugger. Now type:


...and hold tight. It should hopefully give some sort of clue as to where the difficulty originated. If the program won''t die, type "kill", to quit your executable and "quit" to exit the debugger.

GDB is a very powerful debugger and I know almost nothing about it, so I''m sure there are many more advanced ways of using it to track things down, but using the above steps will usually give me enough information to start tinkering with code again.

It does sound very odd that your program would fail so early on though... I can''t be sure why that would be.

Good luck in any case,


Share this post

Link to post
Share on other sites
Hey man where are you from?? I mean country.
Ok use SDL it is much better (and newer) than glut.

"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

Share this post

Link to post
Share on other sites
Thank you everyone for your help. I tried darkoneqwe''s suggestion and it came up with a compile error. First I tried gdb under the real console and interestingly enough, I know something''s working because even if I run it without gdb under the real console it says:

GLUT: Fatal error in game: could not open display.

If, on the other hand, I run it in Konsole, it comes up with:

(gdb) run
Starting program: /home/shalom/Documents/Programs/game

Program received signal SIGSEGV, Segmentation fault.
0x0804cdb9 in ?? ()

If you''re courious where the Goose. comes from, that''s the printf I used to see where it stops. This is a direct copy of the beginning of main():

int main(int argc, char **argv) {
glutInit(&argc, argv);

Does anyone have any idea what error 0x0804cdb9 is? And how it manages to have an error in a function called ?? ()


Share this post

Link to post
Share on other sites
I finally got it to work in KDevelop. I discovered that 0x0804cdb9 isn''t a error number; its a location in my program. Interestingly, in KDevelop it says that the error takes place at 0x804c8b9. What I run it KDevelop''s debugger, it says in disassemble:

0x804c8b9: in $0x48,%al
0x804c8bb: inc %eax
0x804c8bc: cwtl
0x804c8bd: in $0x48,%al
0x804c8bf: inc %eax
0x804c8c0: jo 0x804c90f
0x804c8c2: cmp $0x48d52040,%eax
0x804c8c7: inc %eax
0x804c8c8: add %al,(%eax)
0x804c8ca: add %al,(%eax)
0x804c8cc: sbb %eax,(%eax)
0x804c8ce: add %al,(%eax)
0x804c8d0: mov 0xa04048e4,%al
0x804c8d5: in $0x48,%al
0x804c8d7: inc %eax
0x804c8d8: jo 0x804c928
0x804c8da: cmp $0x48d52040,%eax
0x804c8df: inc %eax
0x804c8e0: add %al,(%eax)
0x804c8e2: add %al,(%eax)
0x804c8e4: sbb %eax,(%eax)
0x804c8e6: add %al,(%eax)
0x804c8e8: test $0xe4,%al
0x804c8ea: dec %eax
0x804c8eb: inc %eax
0x804c8ec: test $0xe4,%al
0x804c8ee: dec %eax
0x804c8ef: inc %eax
0x804c8f0: xor %cl,0x3d(%edi)
0x804c8f3: inc %eax
0x804c8f4: and %dl,%ch
0x804c8f6: dec %eax
0x804c8f7: inc %eax
0x804c8f8: add %al,(%eax)
0x804c8fa: add %al,(%eax)
0x804c8fc: inc %ecx
0x804c8fd: add %al,(%eax)
0x804c8ff: add %dh,0x6e(%ebp)
0x804c902: imul $0x2064,%fs:%gs:0x65(%esi),%bp
0x804c90a: jae 0x804c985
0x804c90c: insl (%dx),%es:(%edi)
0x804c90d: bound %ebp,0x6c(%edi)
0x804c910: cmp (%eax),%ah
0x804c912: jo 0x804c988
0x804c914: push $0x64616572
0x804c919: pop %edi
0x804c91a: imul $0x5f,0x79(%ebp),%esp
0x804c91e: arpl %si,0x65(%edx)
0x804c921: popa
0x804c922: je 0x804c989
0x804c924: add %ch,(%edi)
0x804c926: jne 0x804c99b
0x804c928: jb 0x804c959
0x804c92a: insb (%dx),%es:(%edi)
0x804c92b: imul $0x4762696c,0x2f(%edx),%esp
0x804c932: dec %esp
0x804c933: jae,pn 0x804c9a5
0x804c936: xor %eax,%cs:(%eax)
End of assembler dump.

Under call stack (for some reason I can''t copy and paste so I have to summarize):
0x804c8b9 in ?? ()
0xsomething in _X11TransConnectDisplay() from libX11.so.6
ditto in XOpenDisplay() from libX11.so.6
" in __glutOpenXConnection() from libGlut.so.3
" in __libc_start_main() from libc.so.6

Anyone have any idea what the problem is? I''ve successfully run OpenGL programs on the computer though I doubt any of them have used glut. I''ll try another glut program.

Share this post

Link to post
Share on other sites
I tried a glut program (which worked) and I reinstalled glut (from the sources). In the process I somehow messed up mesa so I reinstalled mesa, glu, and glut from the suse packages and after all that, my program''s still coming up with the same annoying error. By the way, I have a GeForce 2 and I have the nVidia drivers installed.

Share this post

Link to post
Share on other sites
It''s years since I used GLUT, so this is jus a stab in the dark, but try checking that you have 24 bit colour in your X configuration.

Open /etc/X11/XF86Config-4

In the screen section, make sure that default depth is set to 24, and that you have something like this

Section "Screen"
Identifier "screen1"
Device "device1"
Monitor "monitor1"
DefaultColorDepth 24 #this is the important line

#...other subsections

Subsection "Display"
Depth 24 #make sure this subsection is present as well
Modes "1024x768" "800x600" "640x480"

It''s just a thought - the sort of thing that can occasionally cause odd errors for me.

I also came across this whilst trying to remeber what exactly glutInit did - you could try passing different command line parameters to your program and they''ll automatically be transferred to glutInit(&argc,argv); There is a reference here http://www2.cs.uregina.ca/~cdshaw/glut/node10.html

None of this will probably be any help, but just on the off chance. Good luck killing the bug, decent Linux games are always welcome.


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!