0
101 Aug 22, 2003 at 21:49

Does somebody know how to blit an sdl surface with opengl?

#### 10 Replies

0
101 Aug 23, 2003 at 09:08

I’ve never tried it myself, but you should be able to access the structure and so you can create an opengl texture.

I found this, it might help:

Slightly edited from the SDL_Surface manpage:

    typedef struct SDL_Surface {
Uint32 flags;
SDL_PixelFormat *format;
int w, h;
Uint16 pitch;
void *pixels;

SDL_Rect clip_rect;

int refcount;
} SDL_Surface;

/*
flags        Surface flags
format       Pixel format
w, h        Width and height of the surface
pitch        Length of a surface scanline in bytes
pixels       Pointer to the actual pixel data
clip_rect      surface clip rectangle
*/


So I guess you can find out what the width and height are. The pixels pointer type will be defined by the format argument. You’ll need to guess or research what the format means though, it wasn’t mentioned. I need to leave you some work ;).

0
101 Aug 24, 2003 at 11:12

why does sdl have a manpage? its all directly written in the headers :D

yeah, upload it onto a texture. thats about all you can do

0
101 Aug 24, 2003 at 17:32

well, it’s easier to type “man SDL_Surface” than find the dir, find the file, then read it ;P. Besides, there is a little more in the man page than in the header.

0
101 Aug 25, 2003 at 13:05

The problem with using it as texture is that I want to use that surface as a 2d image on top of the 3d space, using 2d coordinates. I dont wnat to have to calculate all time the correct 3d coords to put the image on top. Im sure it is faster to blit an image than draw a polygon and texture it.

0
101 Aug 25, 2003 at 15:31

@baldurk

well, it’s easier to type “man SDL_Surface” than find the dir, find the file, then read it ;P. Besides, there is a little more in the man page than in the header.

right click, open, done..

or, rightclick, go to definition, done..

wow THAT was hard :D

0
101 Aug 25, 2003 at 15:34

The problem with using it as texture is that I want to use that surface as a 2d image on top of the 3d space, using 2d coordinates. I dont wnat to have to calculate all time the correct 3d coords to put the image on top.

void glBlitOnScreen(... your texture here ...) {
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();

glTexCoords2i(0,0); glVertex2i(-1,-1);
glTexCoords2i(1,0); glVertex2i( 1,-1);
glTexCoords2i(1,1); glVertex2i( 1, 1);
glTexCoords2i(0,1); glVertex2i(-1, 1);
} glEnd();

glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
}


Im sure it is faster to blit an image than draw a polygon and texture it.

no

0
101 Aug 25, 2003 at 18:28

Well, I’m not on VC++, so it’s more difficult. It’s a moot point on VC++, because windows doesn’t have man pages :).

0
101 Aug 25, 2003 at 18:31

well.. i ment it to honour sdl mainly, because its well documented, independend on os and os features :D thats cool..

0
101 Aug 25, 2003 at 18:54

That is cool. Cool and unfortunately rare.

0
101 Aug 26, 2003 at 07:20

yeah.. :(