LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-07-2017, 10:07 AM   #1
842Mono
Member
 
Registered: Oct 2016
Distribution: Ubuntu
Posts: 35

Rep: Reputation: Disabled
Exclamation coding OpenGL (c++) on Ubuntu vs on Windows


Hello!

So I need to code OpenGL (over c++)

...did my search and found this nice SO question. I installed the libraries listed in the first answer and I started working with them. I compile using g++, that command stated in the answer. Things are looking good, except!!

We got a code snippet to draws batman. It worked for my friends on their windows, but to me it threw a runtime exception with no trace

Code:
"Floating point exception (core dumped)"
It took me hours to figure out the problem, I had to change all the abs() functions to fabs() for some reason.

Also the main method has to return an int instead of void.


I wouldn't have a problem if those were the only differences. Is there some reference to show me a list of such differences? Or at least a reason for such differences. All I know is that OpenGL is a specification rather than a library or a strict implementation.

A friend was asking me how to install OpenGL on Ubuntu, so I told him about these things, he told me "no thanks I'm out, back to windows" hehe XD I told him "I honestly can't guarantee things aren't going to be messy, suit yourself." ...but I want to guarantee it

Any info would be helpful. Thx awesome people

Last edited by 842Mono; 10-08-2017 at 05:22 AM.
 
Old 10-07-2017, 10:24 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,773

Rep: Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888
you need to compile with g++ -Wall and handle all the warnings. I think that will help you (but obviously it won't solve all the problems).
 
Old 10-07-2017, 10:49 AM   #3
842Mono
Member
 
Registered: Oct 2016
Distribution: Ubuntu
Posts: 35

Original Poster
Rep: Reputation: Disabled
I just tried with the batman example but there's no difference unfortunately.

g++ -Wall Batman_21529_24491.cpp -o batman -lglut -lGL -lGLU -lGLEW && ./batman
Floating point exception (core dumped)
 
Old 10-07-2017, 10:51 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,302

Rep: Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006
Try this:
Code:
g++ -W -Werror -Wall Batman_21529_24491.cpp -o batman -lglut -lGL -lGLU -lGLEW && gdb ./batman
run
bt

Last edited by NevemTeve; 10-07-2017 at 03:49 PM. Reason: Also add option -g
 
Old 10-07-2017, 11:13 AM   #5
842Mono
Member
 
Registered: Oct 2016
Distribution: Ubuntu
Posts: 35

Original Poster
Rep: Reputation: Disabled
hmmm cool

Code:
(gdb) run
Starting program: /home/mono/Desktop/Code Library/c++/bad batman/batman 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGFPE, Arithmetic exception.
0x000000000040108b in Display() ()
(gdb) bt
#0  0x000000000040108b in Display() ()
#1  0x00007ffff7baf324 in ?? () from /usr/lib/x86_64-linux-gnu/libglut.so.3
#2  0x00007ffff7bb2b89 in fgEnumWindows () from /usr/lib/x86_64-linux-gnu/libglut.so.3
#3  0x00007ffff7baf8dd in glutMainLoopEvent () from /usr/lib/x86_64-linux-gnu/libglut.so.3
#4  0x00007ffff7bb00dd in glutMainLoop () from /usr/lib/x86_64-linux-gnu/libglut.so.3
#5  0x0000000000400d99 in main ()
This seems to be better output than just the exception, but the trace points to the library and end with "in main()"

...formatting question, how do I insert a code block in the post? ...got it XD

Last edited by 842Mono; 10-07-2017 at 11:26 AM.
 
Old 10-07-2017, 11:43 AM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,773

Rep: Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888
I guess the libraries you installed are not compatible with each other (especially libglut.so.3 is one of them)
 
Old 10-07-2017, 02:33 PM   #7
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,302

Rep: Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006
Sorry I forgot option -g

Code:
g++ -g -W -Werror -Wall Batman_21529_24491.cpp -o batman -lglut -lGL -lGLU -lGLEW && gdb ./batman
run
bt
 
1 members found this post helpful.
Old 10-07-2017, 02:44 PM   #8
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: Slackware
Posts: 7,621

Rep: Reputation: 2948Reputation: 2948Reputation: 2948Reputation: 2948Reputation: 2948Reputation: 2948Reputation: 2948Reputation: 2948Reputation: 2948Reputation: 2948Reputation: 2948
Are you and your friends running the exact same code, just in different systems and compilers?

Last edited by dugan; 10-07-2017 at 02:45 PM.
 
Old 10-08-2017, 05:12 AM   #9
842Mono
Member
 
Registered: Oct 2016
Distribution: Ubuntu
Posts: 35

Original Poster
Rep: Reputation: Disabled
Arrow

Quote:
Originally Posted by pan64 View Post
I guess the libraries you installed are not compatible with each other (especially libglut.so.3 is one of them)
I just followed the link I gave above. I followed the first answer, I just installed all the listed libraries with "sudo apt install ...". How can I know which versions are compatible with which?

Quote:
Originally Posted by NevemTeve View Post
Sorry I forgot option -g
Now it shows better trace! It showed which line throws the error!! Thank you!

Code:
(gdb) run
Starting program: /home/mono/Desktop/Code Library/c++/bad batman/batman 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGFPE, Arithmetic exception.
0x000000000040108b in Display () at Batman_21529_24491.cpp:39
39	    double ycordNeg = -3 * sqrt((double)(1 - pow((xcord / 7), 2)))*sqrt((double)(abs(abs(xcord) - 4) / (abs(xcord) - 4)));
(gdb) bt
#0  0x000000000040108b in Display () at Batman_21529_24491.cpp:39
#1  0x00007ffff7baf324 in ?? () from /usr/lib/x86_64-linux-gnu/libglut.so.3
#2  0x00007ffff7bb2b89 in fgEnumWindows ()
   from /usr/lib/x86_64-linux-gnu/libglut.so.3
#3  0x00007ffff7baf8dd in glutMainLoopEvent ()
   from /usr/lib/x86_64-linux-gnu/libglut.so.3
#4  0x00007ffff7bb00dd in glutMainLoop ()
   from /usr/lib/x86_64-linux-gnu/libglut.so.3
#5  0x0000000000400d99 in main (argc=1, argr=0x7fffffffd9a8)
    at Batman_21529_24491.cpp:19
Quote:
Originally Posted by dugan View Post
Are you and your friends running the exact same code, just in different systems and compilers?
Yes exactly. Same code but I'm using g++ on linux and they're using visual studio.

I've attached the code that throws the exception. It should draw batman (but very squashed to the bottom left). In my case the code threw an exception until I replaced every abs() function with fabs()
Attached Files
File Type: txt Batman_21529_24491.cpp.txt (2.2 KB, 7 views)

Last edited by 842Mono; 10-08-2017 at 05:17 AM.
 
Old 10-08-2017, 08:24 AM   #10
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,302

Rep: Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006
Keep debugging, eg
Code:
print xcord
print pow((xcord / 7), 2)
print 1-pow((xcord / 7), 2)
...
 
Old 10-08-2017, 10:37 AM   #11
842Mono
Member
 
Registered: Oct 2016
Distribution: Ubuntu
Posts: 35

Original Poster
Rep: Reputation: Disabled
I already know that the problem is with the abs() function, changing it to fabs() fixes it. And it's a good thing that I can get some good trace now thanks to your command!

It's just that these problems wouldn't happen on windows. I need to share code with windows users.

pan64 says some libraries may be incompatible with others. I want to know if that's the issue and how to fix it.

Otherwise I want to know if there are other issues like this and how to avoid them.
 
Old 10-08-2017, 11:18 AM   #12
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,302

Rep: Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006
No, it is a bug in your program. Obviously, the bug exists in Windows too, only it doesn't manifest in a visible way. Use the debugger to find out the details.
 
Old 10-08-2017, 06:29 PM   #13
842Mono
Member
 
Registered: Oct 2016
Distribution: Ubuntu
Posts: 35

Original Poster
Rep: Reputation: Disabled
I think that's the issue: https://stackoverflow.com/questions/...lsl-abs-broken

abs() supports doubles at 4.10.

I've spent like 5 hours now trying to install an opengl 4.5 development environment (or at least 4.1) but no use. I can't find a "simple guide". And I'm not really familiar with c++, I'm fairly new to it.

I found this https://bcmpinc.wordpress.com/2015/0...th-opengl-4-5/ it seems to be the easiest but I just can't do it.
 
Old 10-09-2017, 12:50 AM   #14
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,302

Rep: Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006
If you think so, please create a mvce (I think it should be 4-5 lines alltogether). And, if the problem persists, file a bug-report. (If no newer version is available.)

Edit: it would be nice if you checked this in C too, instead of C++

Last edited by NevemTeve; 10-09-2017 at 01:00 AM.
 
Old 10-09-2017, 04:44 AM   #15
842Mono
Member
 
Registered: Oct 2016
Distribution: Ubuntu
Posts: 35

Original Poster
Rep: Reputation: Disabled
heh currently my stack overflow account reached its question limit. However I posted this: https://askubuntu.com/questions/9631.../963220#963220
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Windows 8 Beats Ubuntu Linux For Intel "Haswell" OpenGL LXer Syndicated Linux News 0 07-25-2013 02:12 AM
LXer: Windows 8 Outperforming Ubuntu Linux With Intel OpenGL Graphics LXer Syndicated Linux News 1 03-21-2013 06:46 PM
ubuntu qemu windows xp catia uncertified opengl error ,check installation rag123 Ubuntu 0 10-23-2009 05:28 AM
Bad opengl performance with two or more OpenGL windows on nvidia drivers (GF 7600 GS) psokol Linux - Software 0 02-21-2009 11:40 AM
opengl on fedora how to start coding? ashjas Fedora 1 01-17-2008 07:41 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration