LinuxQuestions.org
Visit the LQ Articles and Editorials section
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 08-14-2005, 01:30 AM   #1
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Rep: Reputation: 35
Using SDL/OpenGL, need help.


Here's what I have:
Code:
#include<iostream>
#include<SDL/SDL.h>
using namespace std;

int main () {
    if (SDL_Init (SDL_INIT_VIDEO) < 0) {
        printf ("Unable to init SDL: %s\n", SDL_GetError ());
        return 1;
    }
    cout << "All was initialized correctly" << endl;
    cout << "Quiting" << endl;
    SDL_Quit ();
    return 0;
}
Here are errors:
Code:
kornerr@darkstar:~/cpp$ g++ -o SDLtry SDLtry.cpp
/tmp/cccKzq2n.o(.text+0x16): In function `main':
: undefined reference to `SDL_Init'
/tmp/cccKzq2n.o(.text+0x28): In function `main':
: undefined reference to `SDL_GetError'
/tmp/cccKzq2n.o(.text+0x93): In function `main':
: undefined reference to `SDL_Quit'
collect2: ld returned 1 exit status
SDL/SDL.h is in /usr/include and /usr/local/include

What's wrong?

Thanks.
 
Old 08-14-2005, 02:06 AM   #2
kjordan
Member
 
Registered: Jul 2004
Distribution: LFS, I felt the itch and scratched it
Posts: 227

Rep: Reputation: 31
You have to link it with libSDL.so with the -lSDL flag.
 
Old 08-14-2005, 10:15 AM   #3
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Original Poster
Rep: Reputation: 35
Thanks, kjordan.
 
Old 08-16-2005, 02:25 PM   #4
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Original Poster
Rep: Reputation: 35
I think I've made all what described at Cone3D prorgamming "GFX with SDL"
in the 3rd chapter.
I've made only little change - instead of ints used as bools I've used bools itself.
Well, now I can't run an app.
I get "Fatal signal: Segmentation Fault (SDL Parachute Deployed)"
when DrawScene tries to "SDL_Flip (screen)".
When I comment the string with Flip, app works.
Can changing ints to bools make the app fail? (probably not)
If not, what can be wrong? The downloaded source works just fine.

Thanks.
 
Old 08-16-2005, 03:06 PM   #5
lowpro2k3
Member
 
Registered: Oct 2003
Location: Canada
Distribution: Slackware
Posts: 340

Rep: Reputation: 30
Possibly, I'm pretty sure SDL is written in C where theres no such thing as a true bool. If you change your bools back to ints and it works then you've isolated the problem
 
Old 08-16-2005, 04:42 PM   #6
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
Are you changing the ints to bools on callback functions? Callback functions usually have to have a specifically defined prototype, and if you are changing the prototype of those, bad things can happen.
 
Old 08-17-2005, 02:31 AM   #7
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Original Poster
Rep: Reputation: 35
You won't believe. I've changed all files according to the tutorial. And in main () I found a redeclaration of
SDL_Surface *screen, which was declared above all funcs in the same file.

I can only wonder why compiler couldn't see redeclaration.
Because it was a pointer? Seems very strange to me.

Thanks for help anyway.
 
Old 08-19-2005, 10:22 AM   #8
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Original Poster
Rep: Reputation: 35
Code:
kornerr@darkstar:~/cpp/SDL/1GL$ make
g++ -O2 -march=pentium4 -mmmx -msse -msse2 -s -pipe -Wall -o 1 1.cpp -lSDL -lGL -lGLU
/usr/lib/gcc-lib/i486-slackware-linux/3.3.4/../../../../i486-slackware-linux/bin/ld: cannot\
find -lGLU
collect2: ld returned 1 exit status
make: *** [1] Error 1
I have the simpliest app which tries to use OpenGL with SDL.
I have "glu.h" in the same dir where "gl.h" is.

What should I do?

Thanks.
 
Old 08-19-2005, 11:19 AM   #9
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
GLU.h is not the library, it is the header file. There is a big difference. The .h files just store a bunch of declarations for stuff that is compiled as object code in the library, which is linked at runtime. (In this case by using -lGLU.)

So, the file that it is saying it cannot find is NOT glu.h, but rather libGLU.so... Try to find that file in /usr/lib, /usr/local/lib, or /usr/X11/lib. If it is in /usr/X11R6/lib, you may have to add that path to the library search path by including -L/usr/X11R6/lib. If you can't find it in any of those paths, try to find it with locate or find. If you don't find it, you may not have it installed on your system, so look for the OpenGL development library package for whatever distro you use.
 
Old 08-19-2005, 12:34 PM   #10
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Original Poster
Rep: Reputation: 35
Thanks, deiussum.
 
Old 08-21-2005, 10:20 AM   #11
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Original Poster
Rep: Reputation: 35
I've completed the second NeHe lesson, but app doesn't draw anything.
Neither does the source for Linux/SDL.

Please, have a look at my typing
here
.

NeHe 2nd lesson is here.

Thanks.
 
Old 08-21-2005, 11:58 AM   #12
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
The problem appears to be that you are not calling the draw function until is_active is true. When you first start up the window, that seems to stay false until you do something like switch to another window and switch back. If you do that, everything displays just fine. I haven't used SDL enough to know much about the SDL_ACTIVEEVENT that you are using to set is_active to true, but I didn't do that at all for the few SDL OpenGL apps I have written...

Here's an example of the SDL message processing loop of one of my own SDL apps:

Code:
        bool bRun = true;
        while(bRun)
        {
            SDL_Event oEvent;

            oWnd.Idle();

            while(SDL_PollEvent(&oEvent))
            {
                switch(oEvent.type)
                {
                    case SDL_VIDEOEXPOSE:
                        oWnd.DrawScene();
                        break;
                    case SDL_VIDEORESIZE:
                        oWnd.Resize(oEvent.resize.w, oEvent.resize.h);
                        break;
                    case SDL_KEYDOWN:
                    case SDL_KEYUP:
                        oWnd.KeyboardEvent(oEvent.key);
                        break;
                    case SDL_MOUSEBUTTONDOWN:
                    case SDL_MOUSEBUTTONUP:
                        oWnd.MouseButtonEvent(oEvent.button);
                        break;
                    case SDL_MOUSEMOTION:
                        oWnd.MouseMotionEvent(oEvent.motion);
                        break;
                    case SDL_QUIT:
                        bRun = false;
                        break;
                }

                if (!oWnd.IsRunning())
                {
                    bRun = false;
                    break;
                }
            }
        }

        SDL_Quit();

Last edited by deiussum; 08-21-2005 at 12:03 PM.
 
Old 08-21-2005, 01:22 PM   #13
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Original Poster
Rep: Reputation: 35
Unfortunately, problem is not in event handling.
I've changed code a bit to make sure DrawGLScene is executed.
code
screenshot

I even commented all event handling and did just
Code:
- - -
for (int i=0;i<10000;i++)
    DrawGLScene ();
- - -
Doesn't work.

Any suggestions?

Thanks.

~~~Edit~~~
Now the first link works, sorry for few minutes.

Last edited by kornerr; 08-21-2005 at 01:28 PM.
 
Old 08-21-2005, 01:26 PM   #14
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
Well, on my system it definitely IS the event handling that isn't working correctly. I commented out if (is_active) and it works like a charm...

What video card and drivers are you using?
 
Old 08-21-2005, 01:30 PM   #15
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Original Poster
Rep: Reputation: 35
Drv: NVIDIA-Linux-x86-1.0-7664-pkg1.run
Card: gf4mx440
Lib: SDL-1.2.8
 
  


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
sdl / opengl - cant press up and right atrain Linux - Games 2 03-28-2005 12:29 AM
Question about SDL OpenGL and -lglut doody Programming 2 11-16-2004 05:17 PM
OpenGL and SDL programming with Slackware zsejk Slackware 13 08-03-2004 08:52 PM
Using OpenGL (+SDL) for 2D programs R00ts Programming 4 07-16-2004 01:33 PM
OpenGL lighting with SDL MadCactus Programming 0 09-21-2003 12:52 PM


All times are GMT -5. The time now is 01:50 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration