Help with SDL_SetVideoMode

I’m having trouble using SDL_SetVideoMode a second time. A very
simplified test case follows. I’m using windows 2000. What happens is I
see a 640x480 windows, then it goes to 800x600 fullscreen and crashes
before anything is displayed. Exit code is -11. Could anyone tell me
what I’m doing wrong? Thanks.

stdout.txt:
Video mode set to 800x600x32.
1
2

stderr.txt:
Fatal signal: Segmentation Fault (SDL Parachute Deployed)

testcase.cpp:
#include <stdio.h>
#include <stdlib.h>

#include “SDL.h”

SDL_Surface *screen;

int main(int argc, char *argv[])
{
if ( SDL_Init(SDL_INIT_EVERYTHING) < 0 ) {
fprintf(stderr, “Couldn’t initialize SDL: %s\n”, SDL_GetError());
exit(1);
}

atexit(SDL_Quit);

if ((screen = SDL_SetVideoMode(640, 480, 8,

SDL_SWSURFACE|SDL_ANYFORMAT)) == NULL ) {
fprintf(stderr, “Couldn’t set 640x480x8 video mode: %s\n”,
SDL_GetError());
exit(1);
}

if ((screen = SDL_SetVideoMode(800, 600, 32,

SDL_FULLSCREEN|SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_OPENGL)) == NULL) {
fprintf(stderr, “Couldn’t set video mode 800x600x32. %s\n”,
SDL_GetError());
exit(1);
}
printf(“Video mode set to 800x600x32.\n”);

printf("1\n");
SDL_Rect rect;
rect.x=0;
rect.y=24;
rect.w=22;
rect.h=24;
SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format,255,0,0));

printf("2\n");
SDL_UpdateRect(screen, 0,24, 22, 24);

printf("\nsuccess!\n");

exit( 0 );

}=====
Dave Brondsema
dave at brondsema.net
http://www.brondsema.net


Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/

I’m having trouble using SDL_SetVideoMode a second time. A very
simplified test case follows. I’m using windows 2000. What happens is I
see a 640x480 windows, then it goes to 800x600 fullscreen and crashes
before anything is displayed. Exit code is -11. Could anyone tell me
what I’m doing wrong? Thanks.

Hmmm, segfaults under linux too. If you remove the SDL_OPENGL flag from the
second init call it works fine.

SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format,255,0,0));

printf("2\n");
SDL_UpdateRect(screen, 0,24, 22, 24);

These calls aren’t supposed to work with OpenGL are they are? I haven’t used
OpenGL but this is the impression that I get from messages on this list -
SDL’s purpose with OGL is merely to handle the platform-specific things for
you. If you’re using OGL at all, you should use it for everything.

My guess is that with OGL enabled, the FillRect causes the segfault, since I
don’t get the “2” printed out.

If you also add SDL_OPENGLBLIT to the flags when you re-open the screen;

SDL_FULLSCREEN | SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_OPENGL | SDL_OPENGLBLIT

it doesn’t crash for me. But this comment will probably be followed up by at
least 3 people saying “Never EVER use SDL_OPENGLBLIT” - because it’s
very slow etc etc. If you’re using OGL for any rendering at all, use it for
ALL your rendering.On Sun, 13 Jan 2002, Dave Brondsema wrote:

Mike.

I’m having trouble using SDL_SetVideoMode a second time. A very
simplified test case follows. I’m using windows 2000. What happens is I
see a 640x480 windows, then it goes to 800x600 fullscreen and crashes
before anything is displayed. Exit code is -11. Could anyone tell me
what I’m doing wrong? Thanks.

stdout.txt:
Video mode set to 800x600x32.
1
2

stderr.txt:
Fatal signal: Segmentation Fault (SDL Parachute Deployed)

testcase.cpp:
#include <stdio.h>
#include <stdlib.h>

#include “SDL.h”

SDL_Surface *screen;

int main(int argc, char *argv[])
{
if ( SDL_Init(SDL_INIT_EVERYTHING) < 0 ) {
fprintf(stderr, “Couldn’t initialize SDL: %s\n”, SDL_GetError());
exit(1);
}

atexit(SDL_Quit);

if ((screen = SDL_SetVideoMode(640, 480, 8,

SDL_SWSURFACE|SDL_ANYFORMAT)) == NULL ) {
fprintf(stderr, “Couldn’t set 640x480x8 video mode: %s\n”,
SDL_GetError());
exit(1);
}

if ((screen = SDL_SetVideoMode(800, 600, 32,

SDL_FULLSCREEN|SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_OPENGL)) == NULL) {
fprintf(stderr, “Couldn’t set video mode 800x600x32. %s\n”,
SDL_GetError());
exit(1);
}

SDL_HWSURFACE can only be used for creating 2D rendering contexts.
You cannot decide whether using HW or SW(e.g. Mesa) OpenGL rendering with
this flag.
To request double-buffering with OpenGL, use SDL_GL_SetAttribute with
SDL_GL_DOUBLEBUFFER, and use SDL_GL_GetAttribute to see if you actually got
it:
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 );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

SDL_SetVideoMode(800, 600, 32, SDL_FULLSCREEN|SDL_OPENGL);

Look at the OpenGL intro from the sdl-doc project:
http://sdldoc.csn.ul.ie/guidevideoopengl.php

printf("Video mode set to 800x600x32.\n");


printf("1\n");
SDL_Rect rect;
rect.x=0;
rect.y=24;
rect.w=22;
rect.h=24;
SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format,255,0,0));

printf("2\n");
SDL_UpdateRect(screen, 0,24, 22, 24);

You cannot use functions from the SDL 2D API with OpenGL.
Use instead pure OpenGL calls.
See testgl in the test folder of the SDL source tree.On Sunday 13 January 2002 19:01, Dave Brondsema wrote:

printf("\nsuccess!\n");

exit( 0 );

}


Johannes Schmidt

< http://libufo.sourceforge.net > Your widget set for OpenGL

if ((screen = SDL_SetVideoMode(800, 600, 32,

SDL_FULLSCREEN|SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_OPENGL)) == NULL) {

This can be one error. You can’t use SDL_DOUBLEBUF with SDL_OPENGL.
If you want to use DoubleBuffering with OpenGL you must use

SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format,255,0,0));
SDL_UpdateRect(screen, 0,24, 22, 24);

And those can be the other errors. If you use OpenGL you can’t blit
or update the screen. But if you want you can pass SDL_OPENGLBLIT
instead of SDL_OPENGL (Use this only as a test!)On Sun, 13 Jan 2002 10:01:26 -0800 (PST) Dave Brondsema wrote:


Sebastian Garcia <@Seba>
Usuario Linux registrado #225450
Debian GNU/Linux ‘Sid’ kernel 2.4.17 sobre AMD K6 II

— Johannes Schmidt wrote:

SDL_HWSURFACE can only be used for creating 2D rendering contexts.
You cannot decide whether using HW or SW(e.g. Mesa) OpenGL rendering
with
this flag.
To request double-buffering with OpenGL, use SDL_GL_SetAttribute with
SDL_GL_DOUBLEBUFFER, and use SDL_GL_GetAttribute to see if you actually
got
it:
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 );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

SDL_SetVideoMode(800, 600, 32, SDL_FULLSCREEN|SDL_OPENGL);

Look at the OpenGL intro from the sdl-doc project:
http://sdldoc.csn.ul.ie/guidevideoopengl.php

You cannot use functions from the SDL 2D API with OpenGL.
Use instead pure OpenGL calls.
See testgl in the test folder of the SDL source tree.


Johannes Schmidt

< http://libufo.sourceforge.net > Your widget set for OpenGL

Thanks for the help, it works now.> On Sunday 13 January 2002 19:01, Dave Brondsema wrote:

=====
Dave Brondsema
dave at brondsema.net
http://www.brondsema.net


Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/

printf("1\n");
SDL_Rect rect;
rect.x=0;
rect.y=24;
rect.w=22;
rect.h=24;
SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format,255,0,0));

Don’t use SDL_FillRect() on an OpenGL surface. Use gl* functions to
define the contents of the surface.

printf("2\n");
SDL_UpdateRect(screen, 0,24, 22, 24);

Use SDL_GL_SwapBuffers() instead of SDL_UpdateRect on an OpenGL surface.

–ryan.