Sdl and opengl newb problem (sdlopenglblit)

hi, i’m sorry, i’ve read over the archives the last few days and even played
with the testgl program in the test/ directory of the sdl source package.
yet i still have not been able to find a solution to my problem. i am using
the SDL_OPENGLBLIT mode and i am aware that this is deprecated and should not
be used any longer, but for now i like the convenience of it as opposed to
texturing each image i want to use. i am working on a simple 2D game that
mostly just blits some images to the screen but then occasionally i want to
draw some opengl stuff on top of those images. but no matter what i’ve tried
my opengl does not appear on the screen. everything compiles and runs fine,
but i just never see anything. i think i may just being doing some simple
little thing wrong so i was hoping someone might be able to point out my
mistake since i cannot find it. the frustrating thing is i used to do a
similar thing with the glut but i wanted to start using SDL so that i could
use SDL_Image and use several different types of graphics file formats.
anyway, here is the relevant code and thanks in advance for any help.

// SDL AND OPENGL SETUP

// initialize SDL
if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
shutdown(“sdl init failed”);

// fetch video info
videoInfo = SDL_GetVideoInfo( );
if(!videoInfo)
shutdown(“video query failed”);

// flags to pass to SDL_SetVideoMode
videoFlags = SDL_OPENGLBLIT; // openGL in SDL
videoFlags |= SDL_GL_DOUBLEBUFFER; // double buffering
// check to see if surfaces can be stored in memory
(videoInfo->hw_available) ? videoFlags |= SDL_HWSURFACE : videoFlags |=
SDL_SWSURFACE;
// check if hardware blits can be done
if(videoInfo->blit_hw)
videoFlags |= SDL_HWACCEL;
// set up OpenGL double buffering
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
// get a SDL surface
if(mainSurface = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP,
videoFlags) == NULL)
shutdown(“set video mode failed”);

// Set the background black
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

// Depth buffer setup
glClearDepth(1.0f);

// Set Line Antialiasing
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

// Enable Blending
glEnable( GL_BLEND );

// Type Of Blending To Use
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

// Setup our viewport
glViewport(0, 0, (GLint)SCREEN_WIDTH, (GLint)SCREEN_HEIGHT);

// change to the projection matrix and set our viewing volume
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

// set ortho view
glOrtho(0.0f, SCREEN_WIDTH, SCREEN_HEIGHT, 0.0f, -1.0f, 1.0f);

// make sure we’re changing model view and not projection
glMatrixMode(GL_MODELVIEW);

// reset view
glLoadIdentity();

// DISPLAY FUNCTION

SDL_BlitSurface(background, NULL, mainSurface, NULL);
SDL_BlitSurface(gameInfoBox, NULL, mainSurface, &gameInfoBoxPosition);
// there are also a bunch of other blits for other images too,
// this is all working great though

if(SDL_LockSurface(mainSurface) != 0) //tried it without this also
shutdown(“sdl surface was not locked\n”);

glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glLineWidth(5.0);

// draw a simple, big red line across the screen, just to test for now
glColor3ub(255,0,0);
glBegin(GL_LINE_STRIP);
glVertex2i(0,0);
glVertex2i(SCREEN_WIDTH,SCREEN_HEIGHT);
glEnd();

SDL_UnlockSurface(mainSurface);

SDL_Flip(mainSurface);
SDL_GL_SwapBuffers();

aaaagh, this is driving me crazy, thanks again for any help or pointers.
-steve

sorry again, i should have been a little more clear.
what i’d like to do is a combination of blitting and
gl drawing. it would be nice to blit some surfaces,
draw some lines with OGL, then blit some more stuff on
top of that. as is i’ve only been able to
successfully blit, then draw. thx again

-steve__________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th

geinitz at yahoo.com: “[SDL] sdl and opengl newb problem (sdlopenglblit)”…

#hi, i’m sorry, i’ve read over the archives the last few days and even played
#with the testgl program in the test/ directory of the sdl source package.
#yet i still have not been able to find a solution to my problem. i am using
#the SDL_OPENGLBLIT mode and i am aware that this is deprecated and should not
#be used any longer, but for now i like the convenience of it as opposed to
#texturing each image i want to use. i am working on a simple 2D game that
#mostly just blits some images to the screen but then occasionally i want to
#draw some opengl stuff on top of those images. but no matter what i’ve tried
#my opengl does not appear on the screen. everything compiles and runs fine,
#but i just never see anything. i think i may just being doing some simple
#little thing wrong so i was hoping someone might be able to point out my
#mistake since i cannot find it. the frustrating thing is i used to do a
#similar thing with the glut but i wanted to start using SDL so that i could
#use SDL_Image and use several different types of graphics file formats.
#anyway, here is the relevant code and thanks in advance for any help.#

#// SDL AND OPENGL SETUP

// initialize SDL

if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )

shutdown(“sdl init failed”);

// fetch video info

videoInfo = SDL_GetVideoInfo( );

if(!videoInfo)

shutdown(“video query failed”);

// flags to pass to SDL_SetVideoMode

videoFlags = SDL_OPENGLBLIT; // openGL in SDL

You might want to add the SDL_OPENGL flag aswell :slight_smile:
Here is my sdl/gl init code (parts of, after SDL_Init which
is the same for you and me):
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_ALPHA_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
int bpp = SDL_GetVideoInfo()->vfmt->BitsPerPixel;
int flags = SDL_OPENGL;
flags |= SDL_FULLSCREEN;

	if( !SDL_SetVideoMode( width, height, bpp, flags ) ) {
		cout << "OpenGL context initialization failed!" <<

endl;
exit(1);
}

	cout << "OpenGL version:  " << glGetString(GL_VERSION) <<

endl;
cout << "OpenGL renderer: " << glGetString(GL_RENDERER) <<
endl;

hope it helps,

/Olof

hi, i’m sorry, i’ve read over the archives the last
few days and even played with the testgl program in
the test/ directory of the sdl source package. yet i
still have not been able to find a solution to my
problem.
i am using the SDL_OPENGLBLIT mode and i am aware that
this is deprecated and should not be used any longer,
but for now i like the convenience of it as opposed to
texturing each image i want to use. i am working on a
simple 2D game that mostly just blits some images to
the screen but then occasionally i want to draw some
opengl stuff on top of those images. but no matter
what i’ve tried my opengl does not appear on the
screen. everything compiles and runs fine, but i just
never see anything. i think i may just being doing
some simple little thing wrong so i was hoping someone
might be able to point out my mistake since i cannot
find it. the frustrating thing is i used to do a
similar thing with the glut but i wanted to start
using SDL so that i could use SDL_Image and use
several
different types of graphics file formats. anyway, here
is the relevant code and thanks in advance for any
help.

// SDL AND OPENGL SETUP

// initialize SDL
if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
shutdown(“sdl init failed”);

// fetch video info
videoInfo = SDL_GetVideoInfo( );
if(!videoInfo)
shutdown(“video query failed”);

// flags to pass to SDL_SetVideoMode
videoFlags = SDL_OPENGLBLIT; // openGL in
SDL
videoFlags |= SDL_GL_DOUBLEBUFFER; // double
buffering
// check to see if surfaces can be stored in memory
(videoInfo->hw_available) ? videoFlags |=
SDL_HWSURFACE : videoFlags |=
SDL_SWSURFACE;
// check if hardware blits can be done
if(videoInfo->blit_hw)
videoFlags |= SDL_HWACCEL;
// set up OpenGL double buffering
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
// get a SDL surface
if(mainSurface = SDL_SetVideoMode(SCREEN_WIDTH,
SCREEN_HEIGHT,
SCREEN_BPP, videoFlags) == NULL)
shutdown(“set video mode failed”);

// Set the background black
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

// Depth buffer setup
glClearDepth(1.0f);

// Set Line Antialiasing
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

// Enable Blending
glEnable( GL_BLEND );

// Type Of Blending To Use
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

// Setup our viewport
glViewport(0, 0, (GLint)SCREEN_WIDTH,
(GLint)SCREEN_HEIGHT);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

// set ortho view
glOrtho(0.0f, SCREEN_WIDTH, SCREEN_HEIGHT, 0.0f,
-1.0f, 1.0f);

glMatrixMode(GL_MODELVIEW);

// reset view
glLoadIdentity();

// DISPLAY FUNCTION

SDL_BlitSurface(background, NULL, mainSurface,
NULL);
SDL_BlitSurface(gameInfoBox, NULL, mainSurface,
&gameInfoBoxPosition);
// there are also a bunch of other blits
// for other images too, this is all
// working great though

if(SDL_LockSurface(mainSurface) != 0)
shutdown(“sdl surface was not locked\n”);

glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glLineWidth(5.0);

// draw a simple, big red line across the
//screen, just to test for now
glColor3ub(255,0,0);
glBegin(GL_LINE_STRIP);
glVertex2i(0,0);
glVertex2i(SCREEN_WIDTH,SCREEN_HEIGHT);
glEnd();

SDL_UnlockSurface(mainSurface);

SDL_Flip(mainSurface);
SDL_GL_SwapBuffers();

aaaagh, this is driving me crazy, thanks again for any
help or pointers.
-steve__________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th

hi, i’m sorry, i’ve read over the archives the last
few days and even played with the testgl program in
the test/ directory of the sdl source package. yet i
still have not been able to find a solution to my
problem. i am using the SDL_OPENGLBLIT mode and i am
aware that this is deprecated and should not be used
any longer, but for now i like the convenience of it
as opposed to texturing each image i want to use. i
am working on a simple 2D game that mostly just blits
some images to the screen but then occasionally i want
to draw some opengl stuff on top of those images. but
no matter what i’ve tried my opengl does not appear on
the
screen. everything compiles and runs fine, but i
just never see anything. i think i may just being
doing some simple little thing wrong so i was hoping
someone might be able to point out my mistake since i
cannot find it. the frustrating thing is i used to do
a similar thing with the glut but i wanted to start
using SDL so that i could use SDL_Image and use
several different types of graphics file formats.
anyway, here is the relevant code and thanks in
advance for any help.

// SDL AND OPENGL SETUP

// initialize SDL
if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
shutdown(“sdl init failed”);

// fetch video info
videoInfo = SDL_GetVideoInfo( );
if(!videoInfo)
shutdown(“video query failed”);

// flags to pass to SDL_SetVideoMode
videoFlags = SDL_OPENGLBLIT; // openGL in SDL
videoFlags |= SDL_GL_DOUBLEBUFFER;
// check if surfaces can be stored in memory
(videoInfo->hw_available) ? videoFlags |=
SDL_HWSURFACE : videoFlags |= SDL_SWSURFACE;
// check if hardware blits can be done
if(videoInfo->blit_hw)
videoFlags |= SDL_HWACCEL;
// set up OpenGL double buffering
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
// get a SDL surface
if(mainSurface = SDL_SetVideoMode(SCREEN_WIDTH,
SCREEN_HEIGHT,
SCREEN_BPP, videoFlags) == NULL)
shutdown(“set video mode failed”);

// Set the background black
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

// Depth buffer setup
glClearDepth(1.0f);

// Set Line Antialiasing
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

// Enable Blending
glEnable( GL_BLEND );

// Type Of Blending To Use
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

// Setup our viewport
glViewport(0, 0, (GLint)SCREEN_WIDTH,
(GLint)SCREEN_HEIGHT);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

// set ortho view
glOrtho(0.0f, SCREEN_WIDTH, SCREEN_HEIGHT, 0.0f,
-1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);

// reset view
glLoadIdentity();

// DISPLAY FUNCTION

SDL_BlitSurface(background, NULL, mainSurface,
NULL);
SDL_BlitSurface(gameInfoBox, NULL, mainSurface,
&gameInfoBoxPosition);
// there are also a bunch of other blits
// for other images too, this is all
// working great though

if(SDL_LockSurface(mainSurface) != 0)
shutdown(“sdl surface was not locked\n”);

glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,
GL_ONE_MINUS_SRC_ALPHA);
glLineWidth(5.0);

// draw a simple, big red line across the
//screen, just to test for now
glColor3ub(255,0,0);
glBegin(GL_LINE_STRIP);
glVertex2i(0,0);
glVertex2i(SCREEN_WIDTH,SCREEN_HEIGHT);
glEnd();

SDL_UnlockSurface(mainSurface);

SDL_Flip(mainSurface);
SDL_GL_SwapBuffers();

aaaagh, this is driving me crazy, thanks again for
any help or pointers.

-steve__________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th

thanks a lot for the help, with your input and some
other playing around everything seemed to be working
okay. but in the end i realized that i will probably
go to gl textures just so i can eventually move to a
full time 3d environment. the testgl.c program in the
test/ of the SDL source package was really useful also
in case anyone has related problems in the future.

— Olof Bjarnason wrote:> ### @steve_geinitz: "[SDL] sdl and opengl newb

problem (sdlopenglblit)"…
#hi, i’m sorry, i’ve read over the archives the last
few days and even played
#with the testgl program in the test/ directory of
the sdl source package.
#yet i still have not been able to find a solution
to my problem. i am using
#the SDL_OPENGLBLIT mode and i am aware that this is
deprecated and should not
#be used any longer, but for now i like the
convenience of it as opposed to
#texturing each image i want to use. i am working
on a simple 2D game that
#mostly just blits some images to the screen but
then occasionally i want to
#draw some opengl stuff on top of those images. but
no matter what i’ve tried
#my opengl does not appear on the screen.
everything compiles and runs fine,
#but i just never see anything. i think i may just
being doing some simple
#little thing wrong so i was hoping someone might be
able to point out my
#mistake since i cannot find it. the frustrating
thing is i used to do a
#similar thing with the glut but i wanted to start
using SDL so that i could
#use SDL_Image and use several different types of
graphics file formats.
#anyway, here is the relevant code and thanks in
advance for any help.

#// SDL AND OPENGL SETUP

// initialize SDL

if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )

shutdown(“sdl init failed”);

// fetch video info

videoInfo = SDL_GetVideoInfo( );

if(!videoInfo)

shutdown(“video query failed”);

// flags to pass to SDL_SetVideoMode

videoFlags = SDL_OPENGLBLIT; // openGL

in SDL
You might want to add the SDL_OPENGL flag aswell :slight_smile:
Here is my sdl/gl init code (parts of, after
SDL_Init which
is the same for you and me):
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_ALPHA_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
int bpp = SDL_GetVideoInfo()->vfmt->BitsPerPixel;
int flags = SDL_OPENGL;
flags |= SDL_FULLSCREEN;

  if( !SDL_SetVideoMode( width, height, bpp, flags )

) {
cout << “OpenGL context initialization failed!”
<<
endl;
exit(1);
}

  cout << "OpenGL version:  " <<

glGetString(GL_VERSION) <<
endl;
cout << "OpenGL renderer: " <<
glGetString(GL_RENDERER) <<
endl;

hope it helps,

/Olof


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th

steve geinitz: “Re: [SDL] sdl and opengl newb problem (sdlopenglblit)”…

#thanks a lot for the help, with your input and some
#other playing around everything seemed to be working
#okay. but in the end i realized that i will probably
#go to gl textures just so i can eventually move to a
#full time 3d environment. the testgl.c program in the
#test/ of the SDL source package was really useful also
#in case anyone has related problems in the future.

Sounds like a good idea, the SDL_OPENGLBLIT is a bit of a hack
the rumours says. Also, OpenGL really has all the blitting
functionality (and lots more :wink: that you might need.

good luck,

/Olof#

#— Olof Bjarnason wrote:
#> ### geinitz at yahoo.com: “[SDL] sdl and opengl newb
#> problem (sdlopenglblit)”…
#> #hi, i’m sorry, i’ve read over the archives the last
#> few days and even played
#> #with the testgl program in the test/ directory of
#> the sdl source package.
#> #yet i still have not been able to find a solution
#> to my problem. i am using
#> #the SDL_OPENGLBLIT mode and i am aware that this is
#> deprecated and should not
#> #be used any longer, but for now i like the
#> convenience of it as opposed to
#> #texturing each image i want to use. i am working
#> on a simple 2D game that
#> #mostly just blits some images to the screen but
#> then occasionally i want to
#> #draw some opengl stuff on top of those images. but
#> no matter what i’ve tried
#> #my opengl does not appear on the screen.
#> everything compiles and runs fine,
#> #but i just never see anything. i think i may just
#> being doing some simple
#> #little thing wrong so i was hoping someone might be
#> able to point out my
#> #mistake since i cannot find it. the frustrating
#> thing is i used to do a
#> #similar thing with the glut but i wanted to start
#> using SDL so that i could
#> #use SDL_Image and use several different types of
#> graphics file formats.
#> #anyway, here is the relevant code and thanks in
#> advance for any help.
#> #
#> #
#> #
#> #// SDL AND OPENGL SETUP
#> #
#> # // initialize SDL
#> # if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
#> # shutdown(“sdl init failed”);
#> #
#> # // fetch video info
#> # videoInfo = SDL_GetVideoInfo( );
#> # if(!videoInfo)
#> # shutdown(“video query failed”);
#> #
#> # // flags to pass to SDL_SetVideoMode
#> # videoFlags = SDL_OPENGLBLIT; // openGL
#> in SDL
#> You might want to add the SDL_OPENGL flag aswell :slight_smile:
#> Here is my sdl/gl init code (parts of, after
#> SDL_Init which
#> is the same for you and me):
#> 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_ALPHA_SIZE, 5 );
#> SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
#> SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
#> int bpp = SDL_GetVideoInfo()->vfmt->BitsPerPixel;
#> int flags = SDL_OPENGL;
#> flags |= SDL_FULLSCREEN;
#>
#> if( !SDL_SetVideoMode( width, height, bpp, flags )
#> ) {
#> cout << “OpenGL context initialization failed!”
#> <<
#> endl;
#> exit(1);
#> }
#>
#> cout << "OpenGL version: " <<
#> glGetString(GL_VERSION) <<
#> endl;
#> cout << "OpenGL renderer: " <<
#> glGetString(GL_RENDERER) <<
#> endl;
#>
#> hope it helps,
#>
#> /Olof
#>
#> _______________________________________________
#> SDL mailing list
#> SDL at libsdl.org
#> http://www.libsdl.org/mailman/listinfo/sdl

#__________________________________
#Do you Yahoo!?
#Yahoo! Tax Center - File online by April 15th
#http://taxes.yahoo.com/filing.html

#_______________________________________________
#SDL mailing list
#SDL at libsdl.org
#http://www.libsdl.org/mailman/listinfo/sdl