[SDL] sdl patch for new api

Hanno Böck mail at hboeck.de
Wed Sep 27 16:13:47 PDT 2006


On Tue, 2006-09-05 at 00:32 +0200, David Olofson wrote:
> On Monday 04 September 2006 23:29, Bob Pendleton wrote:
> [...]
> > > Right. This was the first problem I ran into: I can't use SDL 
> > > textures, as I can't get at the OpenGL texture name or Direct3D 
> > > texture pointer.
> > 
> > Right there you lost me. SDL doesn't have textures. SDL has
> > surfaces.
> 
> Sorry, I was talking about SDL 1.3, which is a bit different from the 
> SDL 1.2 API. Among other things, source surfaces for display 
> rendering calls have now been replaced with textures, which are 
> basically a bit more abstract than surfaces.

Oh, Duh...

> 
> In short, the SDL 1.3 is designed to work well with modern accelerated 
> APIs like OpenGL and Direct3D, but if need be, it still supports the 
> "retro style" tricks you could do with SDL 1.2.
> 
> 
> > OpenGL has textures, and you get the texture name when you upload
> > the surface in OpenGL. I do not understand the situation in which
> > SDL would hide a texture name from you since SDL does not have
> > textures.
> 
> >From testsprites2.c of SDL 1.3:
> ------------------------------------------------------------
> int
> LoadSprite(char *file)
> {
>     int i;
>     SDL_Surface *temp;
> 
>     /* Load the sprite image */
>     temp = SDL_LoadBMP(file);
>     if (temp == NULL) {
>         fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError());
>         return (-1);
>     }
>     sprite_w = temp->w;
>     sprite_h = temp->h;
> 
>     /* Set transparent pixel as the pixel at (0,0) */
>     if (temp->format->palette) {
>         SDL_SetColorKey(temp, SDL_SRCCOLORKEY,
> 			*(Uint8 *) temp->pixels);
>     }
> 
>     /* Create textures from the image */
>     for (i = 0; i < state->num_windows; ++i) {
>         SDL_SelectRenderer(state->windows[i]);
>         sprites[i] =
>             SDL_CreateTextureFromSurface(0,
> 			SDL_TEXTUREACCESS_REMOTE, temp);
>         if (!sprites[i]) {
>             fprintf(stderr, "Couldn't create texture: %s\n",
> 			SDL_GetError());
>             SDL_FreeSurface(temp);
>             return (-1);
>         }
>     }
>     SDL_FreeSurface(temp);
> 
>     /* We're ready to roll. :) */
>     return (0);
> }
> ------------------------------------------------------------
> 
> The problem is that the SDL_TextureID returned from 
> SDL_CreateTextureFromSurface() is just an internal identifier, and 
> there is no API to get an OpenGL texture name or a Direct3D texture 
> interface object pointer from that.

That sounds like a minor API bug. You just need an API to let you get at
the texture id that SDL has hidden away somewhere else. Just like the
window id hack that is used to get Windows window ids for people who
want to tweak them directly.

That is easy enough to add and does not add complexity to the over all
design. 

		Bob Pendleton

> 
> 
> //David Olofson - Programmer, Composer, Open Source Advocate
> 
> .-------  http://olofson.net - Games, SDL examples  -------.
> |        http://zeespace.net - 2.5D rendering engine       |
> |       http://audiality.org - Music/audio engine          |
> |     http://eel.olofson.net - Real time scripting         |
> '--  http://www.reologica.se - Rheology instrumentation  --'
> 
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl
> 
-- 
+--------------------------------------+
+ Bob Pendleton: writer and programmer +
+ email: Bob at Pendleton.com             +
+ web: www.GameProgrammer.com          +
+ www.Wise2Food.com                    +
+ nutrient info on 7,000+ common foods +
+--------------------------------------+






More information about the SDL mailing list