LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Using SDL/OpenGL, need help. (https://www.linuxquestions.org/questions/programming-9/using-sdl-opengl-need-help-353038/)

kornerr 08-14-2005 12:30 AM

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.

kjordan 08-14-2005 01:06 AM

You have to link it with libSDL.so with the -lSDL flag.

kornerr 08-14-2005 09:15 AM

Thanks, kjordan.

kornerr 08-16-2005 01:25 PM

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.

lowpro2k3 08-16-2005 02:06 PM

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 ;)

deiussum 08-16-2005 03:42 PM

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.

kornerr 08-17-2005 01:31 AM

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.

kornerr 08-19-2005 09:22 AM

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.

deiussum 08-19-2005 10:19 AM

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.

kornerr 08-19-2005 11:34 AM

Thanks, deiussum.

kornerr 08-21-2005 09:20 AM

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.

deiussum 08-21-2005 10:58 AM

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();


kornerr 08-21-2005 12:22 PM

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.

deiussum 08-21-2005 12:26 PM

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?

kornerr 08-21-2005 12:30 PM

Drv: NVIDIA-Linux-x86-1.0-7664-pkg1.run
Card: gf4mx440
Lib: SDL-1.2.8


All times are GMT -5. The time now is 05:57 PM.