SDL Surfaces and OpenGL

Hi Kids :slight_smile:

Hope you’re all having a lush summer! :slight_smile:

Right… um… I’m making SDL Surfaces and turning them in to OpenGL
textures… but all my SDL Surfaces has alpha set on them. So when I’m
drawing on my created surfaces they are always see through… I wish them to
be solid. My code for creating the surface is the usual example stuff (see
all code below).

Any help…?

Steve

SDL_Surface *Graphics::createSurface(int width, int height)
{
SDL_Surface *surface;
Uint32 rmask, gmask, bmask, amask;

/* SDL interprets each pixel as a 32-bit number, so our masks must depend
on the endianness (byte order) of the machine */
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
	rmask = 0xff000000;
	gmask = 0x00ff0000;
	bmask = 0x0000ff00;
	amask = 0x000000ff;
#else
	rmask = 0x000000ff;
	gmask = 0x0000ff00;
	bmask = 0x00ff0000;
	amask = 0xff000000;
#endif

surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, rmask, 

gmask, bmask, amask);

if (surface == NULL)
{
	showErrorAndExit("CreateRGBSurface failed: %s\n", SDL_GetError());
}

SDL_SetAlpha(surface, SDL_SRCALPHA, 255);

return surface;

}

// OpenGL texture generation code (w and h are surface width and height)

SDL_Surface *tmp = createSurface(w, h);

SDL_BlitSurface(surface, NULL, tmp, NULL);

GLuint glTexture;

glGenTextures(1, &glTexture);
glBindTexture(GL_TEXTURE_2D, glTexture);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 

tmp->pixels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

Wow you really didn’t post ANY INFORMATION about your operating
environment, or any of your OpenGL drawing code. Good job.

Cheers, mate. Sorry to have ruined your day(!) Did you read the bottom of the
email I sent…? It contained all the code I am currently using. My OS is
Fedora Core 3 running on an ATI 9700.

What are you trying to do? Do you want your textures to be partially
transparent? Also if you’re using SDL earlier than version 1.1.4, 255
is completely transparent. On that note, why are you setting the alpha
value of the surface to 255? All SDL surfaces are OPAQUE BY DEFAULT.

I don’t want my textures to be transparent, this is the problem. If I load a
PNG, JPG, etc to use as a texture it is not transparent, however if I create
an SDL Surface, draw to it and then create a texture from that surface then
it is transparent, which I don’t want.

I’m guessing you probably have 1:1 blending enabled when you’re drawing
your surfaces. Do you glEnable(GL_BLEND) anywhere in your program? Is
it possible you’re forgetting to glDisable(GL_BLEND) afterward? Or
forgetting to pop your gl attribute stack?

BL_Blend is switched onbefore I draw my surfaces (in Ortho mode). Switching it
off results in large black borders around the images the size of the textures
I have created.

SteveOn Thursday 14 Jul 2005 21:58, you wrote:

Stephen Sweeney wrote:

Hi Kids :slight_smile:

Hope you’re all having a lush summer! :slight_smile:

Right… um… I’m making SDL Surfaces and turning them in to OpenGL
textures… but all my SDL Surfaces has alpha set on them. So when I’m
drawing on my created surfaces they are always see through… I wish them to
be solid. My code for creating the surface is the usual example stuff (see
all code below).

Any help…?

Steve

SDL_Surface *Graphics::createSurface(int width, int height)
{
SDL_Surface *surface;
Uint32 rmask, gmask, bmask, amask;

/* SDL interprets each pixel as a 32-bit number, so our masks must depend
on the endianness (byte order) of the machine */
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
#else
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = 0xff000000;
#endif

surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, rmask,
gmask, bmask, amask);

Because you are passing a mask for alpha, SDL is thinking that you want to use it.
To get rid of the alpha, pass 0 to SDL_CreateRGBSurface in place of amask.
You can also get rid of the declaration of amask, and the lines that assign it a value.

I’m not sure how OpenGL would handle that - it might still interpret the “missing” bits
as alpha, and use transparency. A safer solution, given that possibility, since OpenGL
might well require the alpha channel to be there, would be to make sure that you set
the alpha value to opaque (255 I think) for every pixel (not just the surface alpha
value), as the transparency might just be because of the bits defaulting to 0, which is
completely transparent.

Chris E.
-------------- next part --------------
A non-text attachment was scrubbed…
Name: signature.asc
Type: application/pgp-signature
Size: 252 bytes
Desc: OpenPGP digital signature
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20050715/aae225c0/attachment.pgp

If you can set up an SDL_Surface to use 24 bit pixels (ie, no alpha
data), you can change the glTexImage2D Image format argument from
GL_RGBA to GL_RGB.

Richard SchreyerOn Jul 15, 2005, at 2:12 AM, Chris E. wrote:

Stephen Sweeney wrote:

Hi Kids :slight_smile:

Hope you’re all having a lush summer! :slight_smile:

Right… um… I’m making SDL Surfaces and turning them in to OpenGL
textures… but all my SDL Surfaces has alpha set on them. So when
I’m
drawing on my created surfaces they are always see through… I
wish them to
be solid. My code for creating the surface is the usual example
stuff (see
all code below).

Any help…?

Steve

SDL_Surface *Graphics::createSurface(int width, int height)
{
SDL_Surface *surface;
Uint32 rmask, gmask, bmask, amask;

/* SDL interprets each pixel as a 32-bit number, so our masks  

must depend
on the endianness (byte order) of the machine */
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
#else
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = 0xff000000;
#endif

surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height,  

32, rmask,
gmask, bmask, amask);

Because you are passing a mask for alpha, SDL is thinking that you
want to use it.
To get rid of the alpha, pass 0 to SDL_CreateRGBSurface in place of
amask.
You can also get rid of the declaration of amask, and the lines
that assign it a value.

I’m not sure how OpenGL would handle that - it might still
interpret the “missing” bits
as alpha, and use transparency. A safer solution, given that
possibility, since OpenGL
might well require the alpha channel to be there, would be to make
sure that you set
the alpha value to opaque (255 I think) for every pixel (not just
the surface alpha
value), as the transparency might just be because of the bits
defaulting to 0, which is
completely transparent.

Chris E.


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

We’re using SDL with openGL to develop a 3D game and I’m tasked with getting
text to appear on the screen. I want to use the SDL_ttf add-on, but I can’t
tell if this is even possible. So I guess my real question is, is it possible
to mix SDL surface drawing with openGL rendering? If so, how?

Doing it “directly” is not recommended.

But if you know your GL, you can upload SDL surfaces to it quite painfully…

/OlofOn 11/11/05, Curly wrote:

We’re using SDL with openGL to develop a 3D game and I’m tasked with getting
text to appear on the screen. I want to use the SDL_ttf add-on, but I can’t
tell if this is even possible. So I guess my real question is, is it possible
to mix SDL surface drawing with openGL rendering? If so, how?


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

Doing it “directly” is not recommended.

But if you know your GL, you can upload SDL surfaces to it quite painfully…
Sorry should’ve been WITHOUT PAIN :)On 11/11/05, Olof Bjarnason <@Olof_Bjarnason> wrote:

/Olof

On 11/11/05, Curly wrote:

We’re using SDL with openGL to develop a 3D game and I’m tasked with getting
text to appear on the screen. I want to use the SDL_ttf add-on, but I can’t
tell if this is even possible. So I guess my real question is, is it possible
to mix SDL surface drawing with openGL rendering? If so, how?


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

El vie, 11-11-2005 a las 07:27, Olof Bjarnason escribi?:

Doing it “directly” is not recommended.

But if you know your GL, you can upload SDL surfaces to it quite painfully…

Do you have some example of bliting sdl surfaces with open gl? I mean
not by using the surface as a texture in a quad.–
Roger D. Vargas
Linux user #180787

  • No hay nada tan importante que no pueda ser olvidado *
    Alzheimer

you cannot blit sdl surfaces to the screen when using opengl.

textures are the way to go, i understandOn 11/11/05, Roger D. Vargas wrote:

El vie, 11-11-2005 a las 07:27, Olof Bjarnason escribi?:

Doing it “directly” is not recommended.

But if you know your GL, you can upload SDL surfaces to it quite painfully…

Do you have some example of bliting sdl surfaces with open gl? I mean
not by using the surface as a texture in a quad.


Roger D. Vargas
Linux user #180787
dsgp.blogspot.com

  • No hay nada tan importante que no pueda ser olvidado *
    Alzheimer

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

You could use glRenderPos and glDrawPixels.

Brian Barrett wrote:> you cannot blit sdl surfaces to the screen when using opengl.

textures are the way to go, i understand

On 11/11/05, Roger D. Vargas wrote:

El vie, 11-11-2005 a las 07:27, Olof Bjarnason escribi?:

Doing it “directly” is not recommended.

But if you know your GL, you can upload SDL surfaces to it quite painfully…

Do you have some example of bliting sdl surfaces with open gl? I mean
not by using the surface as a texture in a quad.


Roger D. Vargas
Linux user #180787
dsgp.blogspot.com

  • No hay nada tan importante que no pueda ser olvidado *
    Alzheimer

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


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

El vie, 11-11-2005 a las 21:24, Brian Barrett escribi?:

you cannot blit sdl surfaces to the screen when using opengl.

textures are the way to go, i understand
there is no way to convert the surface data to one usable by glBitmap?–
Roger D. Vargas
Linux user #180787
dsgp.blogspot.com

  • No hay nada tan importante que no pueda ser olvidado *
    Alzheimer

i meant with the standard SDL functions. if your goiung to do custom
stuff its fairly easy to appy it to a texture, then render it on a
quad…On 11/11/05, Antonio SJ Musumeci wrote:

You could use glRenderPos and glDrawPixels.

Brian Barrett wrote:

you cannot blit sdl surfaces to the screen when using opengl.

textures are the way to go, i understand

On 11/11/05, Roger D. Vargas wrote:

El vie, 11-11-2005 a las 07:27, Olof Bjarnason escribi?:

Doing it “directly” is not recommended.

But if you know your GL, you can upload SDL surfaces to it quite painfully…

Do you have some example of bliting sdl surfaces with open gl? I mean
not by using the surface as a texture in a quad.


Roger D. Vargas
Linux user #180787
dsgp.blogspot.com

  • No hay nada tan importante que no pueda ser olvidado *
    Alzheimer

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


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


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

no standard sdl-blit functionality in opengl mode, sorryOn 11/12/05, Brian Barrett <brian.ripoff at gmail.com> wrote:

i meant with the standard SDL functions. if your goiung to do custom
stuff its fairly easy to appy it to a texture, then render it on a
quad…

On 11/11/05, Antonio SJ Musumeci wrote:

You could use glRenderPos and glDrawPixels.

Brian Barrett wrote:

you cannot blit sdl surfaces to the screen when using opengl.

textures are the way to go, i understand

On 11/11/05, Roger D. Vargas wrote:

El vie, 11-11-2005 a las 07:27, Olof Bjarnason escribi?:

Doing it “directly” is not recommended.

But if you know your GL, you can upload SDL surfaces to it quite painfully…

Do you have some example of bliting sdl surfaces with open gl? I mean
not by using the surface as a texture in a quad.


Roger D. Vargas
Linux user #180787
dsgp.blogspot.com

  • No hay nada tan importante que no pueda ser olvidado *
    Alzheimer

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


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


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


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

El vie, 11-11-2005 a las 22:03, Antonio SJ Musumeci escribi?:

You could use glRenderPos and glDrawPixels.
Yes, thats what I mean. But how cna you convert an sdl surface to the
data use by gldrawpixels?
Whats the method used by glSDL to accelerate blits via open gl?–
Roger D. Vargas
Linux user #180787
dsgp.blogspot.com

  • No hay nada tan importante que no pueda ser olvidado *
    Alzheimer

My English is bad (i hope so you understand me)
I’m using SDL with openGL to develop a 3D game and I see:
IF i use SDL_ttf for draw text on SDL Screen: not problem.
If my text is the same position with OpenGL’s object: text is behind OGL’s Object.
I don’t know why.
I you know why, please send me your solution. Thanks

Curly ?? vi?t: We’re using SDL with openGL to develop a 3D game and I’m tasked with getting
text to appear on the screen. I want to use the SDL_ttf add-on, but I can’t
tell if this is even possible. So I guess my real question is, is it possible
to mix SDL surface drawing with openGL rendering? If so, how?_______________________________________________
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


B?n C? S? D?ng Yahoo! Kh?ng?
M?t m?i v? th? r?c? Yahoo! Th? c? ch??ng tr?nh b?o v? ch?ng th? r?c h?u hi?u nh?t tr?n m?ng
http://vn.mail.yahoo.com

You should not mix OpenGL and SDL_Surface. You should render your text to a
surface and copy this surface to an OpenGL Texture.On 11/13/05, danhchitu wrote:

My English is bad (i hope so you understand me)
I’m using SDL with openGL to develop a 3D game and I see:
IF i use SDL_ttf for draw text on SDL Screen: not problem.
If my text is the same position with OpenGL’s object: text is behind OGL’s
Object.
I don’t know why.
I you know why, please send me your solution. Thanks

Curly ?? vi?t:

We’re using SDL with openGL to develop a 3D game and I’m tasked with
getting
text to appear on the screen. I want to use the SDL_ttf add-on, but I
can’t
tell if this is even possible. So I guess my real question is, is it
possible
to mix SDL surface drawing with openGL rendering? If so, how?


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


B?n C? S? D?ng Yahoo! Kh?ng?
M?t m?i v? th? r?c? Yahoo! Th? c? ch??ng tr?nh b?o v? ch?ng th? r?c h?u
hi?u nh?t tr?n m?ng
http://vn.mail.yahoo.com


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

for opengl text the library ftgl is very good:
http://homepages.paradise.net.nz/henryj/code/#FTGLOn Sunday 13 November 2005 08:19, Olivier Delannoy wrote:

You should not mix OpenGL and SDL_Surface. You should render your text to a
surface and copy this surface to an OpenGL Texture.

On 11/13/05, danhchitu wrote:

My English is bad (i hope so you understand me)
I’m using SDL with openGL to develop a 3D game and I see:
IF i use SDL_ttf for draw text on SDL Screen: not problem.
If my text is the same position with OpenGL’s object: text is behind
OGL’s Object.
I don’t know why.
I you know why, please send me your solution. Thanks

Curly ?? vi?t:

We’re using SDL with openGL to develop a 3D game and I’m tasked with
getting
text to appear on the screen. I want to use the SDL_ttf add-on, but I
can’t
tell if this is even possible. So I guess my real question is, is it
possible
to mix SDL surface drawing with openGL rendering? If so, how?


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


B?n C? S? D?ng Yahoo! Kh?ng?
M?t m?i v? th? r?c? Yahoo! Th? c? ch??ng tr?nh b?o v? ch?ng th? r?c h?u
hi?u nh?t tr?n m?ng
http://vn.mail.yahoo.com


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

Roger D. Vargas wrote:

El vie, 11-11-2005 a las 22:03, Antonio SJ Musumeci escribi?:

You could use glRenderPos and glDrawPixels.

Yes, thats what I mean. But how cna you convert an sdl surface to the
data use by gldrawpixels?
Whats the method used by glSDL to accelerate blits via open gl?

It creates a texture and blits it to screen. Creating a texture has been
measured to be way faster on ATI cards as opposed to using
glDrawPixels, and a bit slower on NVIDIA cards. So it looks like a good
compromise.

The simplest way to convert the surface format is to use SDL_BlitSurface
from your original surface to (for example) a RGBA8 SDL surface, which
is then perfectly suitable as an OpenGL texture source.

Stephane