ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
#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
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.
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
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.
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.
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.
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();
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.