SDL -- openGL -- video mode attributes

This is a discussion on SDL -- openGL -- video mode attributes within the Game Programming forums, part of the General Programming Boards category; Okay, so I was having this problem earlier, qv. http://cboard.cprogramming.com/c-pro...ance-exit.html and now I am kind of curious about some things. ...

  1. #1
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300

    SDL -- openGL -- video mode attributes

    Okay, so I was having this problem earlier, qv.

    Significance of exit()

    and now I am kind of curious about some things. SDL requires you to set the video mode.

    SDL_SetVideoMode(WIDTH, HEIGHT, BPP, flags);

    (And yes, I am error checking this.) When I used OGL with glut, there was no setting of video modes -- you just pick a window size, any window size, and away you go. So with my first couple of experiments using SDL (without GL), I just set WIDTH and HEIGHT to anything, or maybe the exact dimensions of my monitor if I was using SDL_FULLSCREEN. No problems.

    But with GL, if I set the video mode above 640x480, I run a significant chance of crashing the windowing system right after the program exits. Otherwise it seems to work (but I haven't done much yet). Working with example 2.8 from the SDL Guide, BPP in a GL setting is determined this way:
    Code:
    const SDL_VideoInfo *info = SDL_GetVideoInfo();
    int BPP= info->vfmt->BitsPerPixel;
    which it's 32, and then there's also this which is necessary:
    Code:
            SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
            SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
            SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
            SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
    I have searched the API docs and googled around a bit, and there is no explanation at all of what all this means. There is one note to the effect that you want the r,g, and b size to be "at least 5". So is this 5+5+5+16=31? Or is this unrelated to BPP? Or, if it means 15 or 16, does this actually mismatch with the depth set using SetVideoMode (32)?

    I'm kind of familiar with GL's interface and AFAIK this is not part of it -- this is for SDL's interface to GL, I guess. Which makes it kind of crappy they can't be bothered to explain this better (or at all), since the docs seem decent otherwise, so far.

    The reason I'm asking is presumably the seg fault (which occurs in libglx.so, part of X windows) is because of this. I do not have a very good video card -- it's an onboard via chrome -- but with glut, the video mode or whatever always matched the window size. Now it seems I am stuck with a 640x480 window (or fullscreen in 640x480 mode) which sucks.

    I guess this won't make much difference to the design of the app itself, etc, since video modes are system dependent. But does anyone have any insight here, like
    1. what is a valid video mode?
    2. how can I get better than 640x480?
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Grrr. Looks like that wasn't it either -- well, maybe it is a factor, but I finally got the SDL Guide's demo to do it, when not running fullscreen, and I really can't look beyond the documentation for a solution. So so much for SDL & portability.

    At one point after the crash, there was a faint repeated image of a giant X cursor down the left side of the text console. That cleared up when I restarted X. Maybe it's my hardware?

    I could not find any previous complaints about this specifically, though there are oodles of people who've reported SDL apps crashing on linux in some manner. I imagine if you weren't programming, this wouldn't be such a big deal since it does run fine, it just crashes X windows afterward.

    Back to glut or something...
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    your equation that equals 31, don't you have to add 1 to it to take the 'all switches off' factor? That is if it's in binary... Other than that I'm clueless about this, but I think I had the same problem with the resolution thingy when I tried SDL
    Currently research OpenGL

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Hmm I have some experience with SDL + OpenGL programming and never had much problems. I've never seen those GL attributes being set though, so you might want to try without it. Also, please tell us exactly the values of the width, height, bpp and flags. You might want to try different values of bpp, see if it still crashes. Try 16 or 24 for instance.

    Also, do you call SDL_Init() before SDL_SetVideoMode()? If so, with what flags? Do you call SQL_Quit() when the program terminates? If not, in my experience, X will start using the new resolution without ever updating the window manager. So it would make it possible the window manager has a bug that causes it to crash if the resolution isn't restored. Though I probably prefer a crash to what I experience if I forget to call SDL_Quit() or the program crashes before it reaches that function.
    Really, I think it's clever to code everything in windowed mode until you actually need it full screen.

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Akkernight View Post
    your equation that equals 31, don't you have to add 1 to it to take the 'all switches off' factor? That is if it's in binary...
    I dunno either. It would seem pretty stupid of them to put it in their docs then. At this point, I cannot determine anything through random experimentation and guesswork because the problem itself is erratic -- like after I matched the video mode to the demo, it didn't happen for a while, then it started again. I thought SDL had a good reputation, but maybe that is just for 2D (non openGL) stuff, as in fact all the SDL apps I have seen are 2D. But I really don't want to do another 2D block breaker. I want a 3D FPS block breaker, because it would be fun to be a giant square that tries to get hit by flying objects

    I posted at the OGL forum, if anyone has an answer, hopefully it's them.

    Maybe all that cross-platform compatibility was too much to ask for. Like, if I'm gonna make a game, I want my friends to be able to use it...but they're all MS users. I guess glut is portable too, but there's no integrated sound.

    Quote Originally Posted by Akkernight View Post
    Other than that I'm clueless about this, but I think I had the same problem with the resolution thingy when I tried SDL
    Just to confirm: the program ran fine, but after you quit the system crashed?

    I'm not really sure what the windows equivalent of this is -- on linux the windowing system can crash and then you are in a plain text terminal (like "safe mode"), so you can get a backtrace of the fault, and restart the windowing system.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    1,197
    Whenever i set those attributes i use the following:
    Code:
    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32);
    And i have created windows up to 1280x800 and never had any problems whatsoever. What other attributes are you setting?

  7. #7
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Thanks for that Shaki, altho it does not seem to solve the problem. Do you know how these relate to the depth setting for SetVideoMode? Eg, if GL_DEPTH is 32, should it also be 32?

    The guide demo does not use the ALPHA attribute, which is strange because when I searched the rest of the guide, it is referred to in only one place, and

    While you can set most OpenGL attributes normally, the attributes list above must be known before SDL sets the video mode.
    Which I will try that next, but post this first in case I crash again

    [later]Ah, now SetVideoMode fails if I use your settings. The key seems to be GL_DEPTH_SIZE, which is limited to 16 on my crap video card (I guess). But bpp keeps coming out 32... Well, I'll keep going, we'll see. I don't like having to run in fullscreen all the time tho.
    Last edited by MK27; 11-18-2009 at 08:32 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  8. #8
    Registered User
    Join Date
    Aug 2003
    Posts
    1,197
    Here is my init-function for OpenGL under SDL:

    Code:
      6 bool CSdlGlWin::InitGL(int x, int y, int bpp, unsigned int flags)
      7 {
      8     m_iWinX = x;
      9     m_iWinY = y;
     10     SDL_Init(SDL_INIT_VIDEO);
     11     m_pSurface = SDL_SetVideoMode(x, y, bpp, flags | SDL_OPENGL);
     12     if(m_pSurface == NULL)
     13         return false;
     14 
     15     SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
     16     SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
     17     SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
     18     SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
     19     SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
     20     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
     21     SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32); // 16 Bit depth-buffer
     22 
     23     glViewport(0, 0, x, y);
     24 
     25     glMatrixMode(GL_PROJECTION);
     26     glLoadIdentity();
     27     gluPerspective(45, ((float)x)/((float)y), 0.0f, 100.0f);
     28 
     29 
     30     glMatrixMode(GL_MODELVIEW);
     31     glLoadIdentity();
     32 
     33     glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
     34     glClearDepth(1.0);
     35     glDepthFunc(GL_ALWAYS);
     36     glEnable(GL_DEPTH_TEST);
     37     glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
     38 
     39     glShadeModel(GL_SMOOTH);
     40 
     41     //glEnable(GL_CULL_FACE);
     42     //glCullFace(GL_FRONT);
     43 
     44     ilInit();
     45 
     46     return true;
     47 }
    And then i use the following to init the whole thing:
    Code:
    app.InitGL(1280, 800, 32, SDL_HWSURFACE | SDL_FULLSCREEN);
    Also in all source-codes ive seen you set the attributes after you initiate the video-mode so that seems weird to say that it should be done before setting video-mode.
    Last edited by Shakti; 11-18-2009 at 08:36 AM.

  9. #9
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Well, if it works, then don't fix it, but going by that line "While you can set most OpenGL attributes normally, the attributes list above* must be known before SDL sets the video mode", you shouldn't call SetVideoMode until after you set the GL attributes.

    You values "work" here if I set them after SetVideoMode is called. If I set them first, SetVideoMode fails unless I reduce DEPTH to 16. So this must have some significance (and maybe it is why people don't do it hahaha). Do you wanna try that and see? I am using the same bpp as you, which was returned by GetVideoInfo. ps. what OS are you using?

    * that list is:
    SDL_GL_RED_SIZE
    SDL_GL_GREEN_SIZE
    SDL_GL_BLUE_SIZE
    SDL_GL_ALPHA_SIZE
    SDL_GL_DOUBLEBUFFER
    SDL_GL_BUFFER_SIZE
    SDL_GL_DEPTH_SIZE
    SDL_GL_STENCIL_SIZE
    SDL_GL_ACCUM_RED_SIZE
    SDL_GL_ACCUM_GREEN_SIZE
    SDL_GL_ACCUM_BLUE_SIZE
    SDL_GL_ACCUM_ALPHA_SIZE
    Last edited by MK27; 11-18-2009 at 08:46 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  10. #10
    Registered User
    Join Date
    Aug 2003
    Posts
    1,197
    My bad, when i changed bpp to 16 i didnt segfault any longer, but i never noticed that X crashed for me. How often does it crash if you do this?
    Last edited by Shakti; 11-18-2009 at 08:50 AM.

  11. #11
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Shakti View Post
    I cant even set those values before i set the video-mode, I just get a seg-fault.
    WTF? Even if you reduce the values? SetVideoMode doesn't return NULL?

    I hate half-assed documentation. I've posted to the SDL forum about all this, presumably they will have something to say sooner or later.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  12. #12
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Shakti View Post
    My bad, when i changed bpp to 16 i didnt segfault any longer, but i never noticed that X crashed for me. How often does it crash if you do this?
    It's hard to say. It crashes less when I run fullscreen. If I really screw with the settings, it will crash more often than not. The guide demo has only crashed once or twice, if I repeatedly execute it enough, but 640x480 is really a waste of time. So now I've got it 1280x800 using your settings (but DEPTH 16) and it hasn't crashed yet (in fullscreen).

    However, I presume it will, which is probably a particular problem here. X's libglx.so is I believe a module to drive the video card's GL capabilities, or emulate them if it isn't capable, which mine isn't (and yours is), so this is probably a significant factor. Hopefully I will be able to stick this out. If you are on linux too and don't have this problem, then I guess SDL GL is feasible. You know, I want everyone playing this game in the spring
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  13. #13
    Registered User
    Join Date
    Aug 2003
    Posts
    1,197
    Yah at this point i would think that the video-card (and its driver) may be at fault rather than X itself, because i have never ever had this problem with OpenGL under SDL.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  2. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  3. OpenGL .dll vs video card dll
    By Silvercord in forum Game Programming
    Replies: 14
    Last Post: 02-12-2003, 06:57 PM
  4. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 09:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21