SDL_BlitSurface and OpenGL

I initialize video mode with SDL_OPENGLBLIT and OpenGL doublebuffer. Then I
load surface by IMG_Load and call SDL_BlitSurface and SDL_GL_SwapBuffers:

MySurface = IMG_Load (“My.jpg”);
SDL_BlitSurface (MySurface, 0, screen, &MyRect);
SDL_GL_SwapBuffers ();

But surface doesn’t blit… Where is error?

I initialize video mode with SDL_OPENGLBLIT and OpenGL
doublebuffer. Then I load surface by IMG_Load and call
SDL_BlitSurface and SDL_GL_SwapBuffers:

MySurface = IMG_Load (“My.jpg”);
^^^^^^^^^
Did you check the return?

SDL_BlitSurface (MySurface, 0, screen, &MyRect);
^^^
I would recommend using NULL here, as a picky compiler would treat 0
as an integer and give you an annoying warning about turning integers
into pointers. (Standard C headers usually define NULL to (void *)0.)

SDL_GL_SwapBuffers ();

But surface doesn’t blit… Where is error?

I could keep guessing, but it’d be easier if you posted a slightly
more complete minimal example that demonstrates the problem. There
are so many ways to get even five lines of code wrong…

BTW, I’d also recommend that you try glSDL(/wrapper) or using OpenGL
directly, dependin on what you’re doing. SDL_OPENGLBLIT is a rather
ineffective last resort hack, which pumps all graphics through a
256x256 texture. With glSDL or native OpenGL, you can load the image
into one (or more, if it’s big) textures and then just keep those on
the 3D card (no constant uploading) until you’re done.

The glSDL wrapper can be found here;

http://olofson.net/mixed.html

…and allows you to make your SDL 2D code use OpenGL “properly” by
tweaking two lines of code, adding a .c file to the
makefile/project/whatever and recompiling.

(Uhm, there was a version 0.7 coming… Let’s just say I had some
trouble getting it right, and now I’m hacking work related stuff
around the clock. I’ll try and make some time for my SDL related
projects one of these days.)

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Friday 23 January 2004 15.52, ALakazam (Skidanov Alexander) wrote:

SDL_BlitSurface (MySurface, 0, screen, &MyRect);
^^^
I would recommend using NULL here, as a picky compiler would treat 0
as an integer and give you an annoying warning about turning integers
into pointers. (Standard C headers usually define NULL to (void *)0.)

Sorry – this is off the subject of SDL, but I just want to squash a
nugget of misinformation.

An ANSI C compiler is required to recognize a bare literal zero as a
valid null pointer constant, when used in a pointer context. So long
as SDL_BlitSurface()'s prototype is visible, even a picky compiler
cannot misread the 0 as an integer constant.

Of course, I think a NULL looks better there anyway, as it clarifies
for the reader that the zero value is in fact a pointer. But there are
stylistic reasons for alternately preferring a bare 0 over NULL (e.g.
conformity with C++'s stronger typing), so it winds up being more a
matter of taste.

b

Hello,

Is it possible to use SDL_BlitSurface(…) with the flag SDL_OPENGL in SDL_SetVideoMode(…) ?

In fact, I want to blit a SDL_Surface and use OpenGL !

Thanks for any help

R?mi wrote:

Hello,

Is it possible to use SDL_BlitSurface(…) with the flag SDL_OPENGL in
SDL_SetVideoMode(…) ?

In fact, I want to blit a SDL_Surface and use OpenGL !

How do you mean? Like, draw using an SDL_Surface and blit an
OpenGL-rendered surface somewhere ON that? Or do you want to blit an
SDL_Surface onto an OpenGL surface/texture? Please specify more what it
is you want to accomplish.

–Scott

R?mi wrote:

Hello,

Is it possible to use SDL_BlitSurface(…) with the flag SDL_OPENGL in
SDL_SetVideoMode(…) ?

In fact, I want to blit a SDL_Surface and use OpenGL !

How do you mean? Like, draw using an SDL_Surface and blit an
OpenGL-rendered surface somewhere ON that? Or do you want to blit an
SDL_Surface onto an OpenGL surface/texture? Please specify more what it
is you want to accomplish.

–Scott

I want to draw a scene using opengl and after blit a surface on the screen.
The code loock like this :

" SDL_Init(SDL_INIT_VIDEO);
SDL_GL_SetAttribute(…);
SDL_Surface* screen = SDL_SetVideoMode(1024,768,0,SDL_FULLSCREEN |
SDL_OPENGL);

SDL_Surface* img = IMG_Load(""); // SDL_Image.h

while(1);{
glClear(…);
gluLookAt(…);
glBegin(…);

glEnd();

SDL_BlitSurface(img,rectimg,screen,rectscreen);
glFlush();
SDL_GL_SwapBuffer(); }"

Can you help me ???

R?mi wrote:

Hello,

Is it possible to use SDL_BlitSurface(…) with the flag SDL_OPENGL in
SDL_SetVideoMode(…) ?

In fact, I want to blit a SDL_Surface and use OpenGL !

Well, you can’t do that (you could with old SDL versions, but the
feature is now long deprecated).

If you’re planning to do some kind of HUD, I advise simply using OpenGL
quads to display the elements of the HUD. As a bonus, that’ll be faster
that software drawing.

Stephane