Knghtbrd reference

sup, knghtbrd said: zeta: talk to the list, they need help =)
referring to me writing an example in the FAQ for converting a SDL
surface to OpenGL texture
just wondering what I should do now, if you guys want me to write one

sup, knghtbrd said: zeta: talk to the list, they need help =)
referring to me writing an example in the FAQ for converting a SDL
surface to OpenGL texture
just wondering what I should do now, if you guys want me to write one


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

I coulda sworn there was a demo somewhere on the docs page
(http://sdldoc.csn.ul.ie/), if not, this is a quick way to do it

int format(SDL_Surface img) {
switch(img->->BytesPerPixel) {
case 1: printf(“8 bit images suck.\n”); exit(-1);
case 2: return GL_RGB4; /
I think */
case 3: return GL_RGB;
case 4: return GL_RGBA;
default: printf(“Unkonwn depth\n”); exit(-1);
}
}

GLint
texture_load_rgba (SDL_Surface *img) {
unsigned int texid;

glGenTextures (1, &texid);
glBindTexture (GL_TEXTURE_2D, texid);
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D (GL_TEXTURE_2D, 0, format(img), img->w, img->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, img->pixels);
return texid;

}

if you know your data is gonna be, say, 32b RGBA, you can
omit the format() function and simple put GL_RGBA in the
glTexImage2D() call

would a howto really be necessary? :slight_smile:

    -Erik <@Erik_Greenwald> [http://math.smsu.edu/~erik]

The opinions expressed by me are not necessarily opinions. In all probability,
they are random rambling, and to be ignored. Failure to ignore may result in
severe boredom or confusion. Shake well before opening. Keep Refrigerated.

Hey Erik,

I think a FAQ addition is more than warranted. People seem not to
realize that SDL_OPENGLBLIT is almost universally a dumb idea until
after they start wondering why the damned thing runs so slowly. Worse,
as often as the question gets asked and answered that people should just
upload their surfaces as OpenGL textures and use them that way, examples
are usually making assumptions regarding things like pixel formats. And
despite my own recent posting of how to set up the screen for overlays
after you’re done drawing pretty 3D with glOrtho, it’s been lost in the
archives.

This question has been asked to death. Each time, people eventually
conclude it’d be a good thing to add to the FAQ. I think this time we
should dispense with the discussion of whether or not it’s a good FAQ
item and just add it. =)On Mon, Oct 15, 2001 at 05:18:59PM -0500, Erik Greenwald wrote:

if you know your data is gonna be, say, 32b RGBA, you can
omit the format() function and simple put GL_RGBA in the
glTexImage2D() call

would a howto really be necessary? :slight_smile:


Joseph Carter Free software developer

innovate /IN no vait/ vb.: 1. To appropriate third-party technology
through purchase, immitation, or theft and to integrate it into a
de-facto, monopoly-position product. 2. To increase in size or complexity
but not in utility; to reduce compatibility or interoperability. 3. To
lock out competitors or to lock in users. 4. To charge more money; to
increase prices or costs. 5. To acquire profits from investments in other
companies but not from direct product or service sales. 6. To stifle or
manipulate a free market; to extend monopoly powers into new markets. 7.
To evade liability for wrong doings; to get off. 8. To purchase
legislation, legistators, legislatures, or chiefs of state. 9. To
mediate all transactions in a global economy; to embezzle; to co-opt power
(coup d’?tat). Cf. innovate, English usage (antonym).
– csbruce, in a Slashdot post

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20011015/711946b3/attachment.pgp

This question has been asked to death. Each time, people eventually
conclude it’d be a good thing to add to the FAQ. I think this time we
should dispense with the discussion of whether or not it’s a good FAQ
item and just add it. =)

Yes, the addition of the SDL_OPENGLBLIT flag was only added so that
a huge body of existing 2D code could work with a 3D application.

If you have any choice at all, write your 2D interface code to use
textures if you’re using OpenGL.

I would be very happy to add a FAQ to the SDL website on how to do
this correctly, if people put this together.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

erik at math.smsu.edu (Erik Greenwald) wrote:

I coulda sworn there was a demo somewhere on the docs page
(http://sdldoc.csn.ul.ie/), if not, this is a quick way to do it

[nonsense code snipped]

try ftp://ptah.lnf.kth.se/pub/misc/convgltex.c instead. It just converts
a surface to the appropriate format (RGB or RGBA), but the rest is not
SDL-specific. Your code ignores the pixel format issue completely

would a howto really be necessary? :slight_smile:

It appears so, yes

apllication/msword ?On Tue, Oct 16, 2001 at 11:15:17AM +0200, Mattias Engdegard wrote:

[nonsense code snipped]

try ftp://ptah.lnf.kth.se/pub/misc/convgltex.c instead. It just converts
a surface to the appropriate format (RGB or RGBA), but the rest is not
SDL-specific. Your code ignores the pixel format issue completely


Joseph Carter Free software developer

Adamel, i think the code you fixed of mine didn’t work
i must not have commited the working code
raptor: like it’s the first time THAT has ever happened =p

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20011016/1b3a3bfb/attachment.pgp

erik at math.smsu.edu (Erik Greenwald) wrote:

I coulda sworn there was a demo somewhere on the docs page
(http://sdldoc.csn.ul.ie/), if not, this is a quick way to do it

[nonsense code snipped]

‘nonsense’?

try ftp://ptah.lnf.kth.se/pub/misc/convgltex.c instead. It just converts
a surface to the appropriate format (RGB or RGBA), but the rest is not
SDL-specific. Your code ignores the pixel format issue completely

yeah, sorry, I’m doing game development, I got a decent amount of control
over format. However, that code introduces extranious unnecessary blits
as opengl 1.2 can do all the various pixel formats, which could trivially be
introduced in my ‘format’ function (which was the reason for pulling that
out to a function instead of doing a logic hack inside the parm list. The
GL part of mine was pulled out of my engine and stripped down to the
bare necessities, the format function was a quick hack to show where to
handle the conversion, just a quick hack, not a perfect solution, but just
enough to make it obvious how to link the two :slight_smile:

would a howto really be necessary? :slight_smile:

It appears so, yes

-Erik

sup, knghtbrd said: zeta: talk to the list, they need help =)
referring to me writing an example in the FAQ for converting a SDL
surface to OpenGL texture
just wondering what I should do now, if you guys want me to write one


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

I coulda sworn there was a demo somewhere on the docs page
(http://sdldoc.csn.ul.ie/), if not, this is a quick way to do it

int format(SDL_Surface img) {
switch(img->->BytesPerPixel) {
case 1: printf(“8 bit images suck.\n”); exit(-1);
case 2: return GL_RGB4; /
I think */
case 3: return GL_RGB;
case 4: return GL_RGBA;
default: printf(“Unkonwn depth\n”); exit(-1);
}
}

GLint
texture_load_rgba (SDL_Surface *img) {
unsigned int texid;

glGenTextures (1, &texid);
glBindTexture (GL_TEXTURE_2D, texid);
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D (GL_TEXTURE_2D, 0, format(img), img->w, img->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, img->pixels);
return texid;

}

if you know your data is gonna be, say, 32b RGBA, you can
omit the format() function and simple put GL_RGBA in the
glTexImage2D() call

would a howto really be necessary? :slight_smile:

It would be good to mention that this will fail for images that
have dimensions that are not powers of 2.

Jp CalderoneOn Mon, 15 Oct 2001, Erik Greenwald wrote:

    -Erik <erik at smluc.org> [http://math.smsu.edu/~erik]

The opinions expressed by me are not necessarily opinions. In all probability,
they are random rambling, and to be ignored. Failure to ignore may result in
severe boredom or confusion. Shake well before opening. Keep Refrigerated.


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

erik at math.smsu.edu (Erik Greenwald) wrote:

yeah, sorry, I’m doing game development, I got a decent amount of control
over format.

most people loading surfaces with SDL will use SDL_LoadBMP or IMG_Load,
and neither of these return surfaces suitable for glTexImage2D other than
by pure luck. SDL_image returns images up to 8bpp as 8bpp surfaces reliably;
anything else might be 15, 16, 24, 32, RGBA, ARGB, BGR, RGB, whatever,
depending on the phase of the moon

erik at math.smsu.edu (Erik Greenwald) wrote:

yeah, sorry, I’m doing game development, I got a decent amount of control
over format.

most people loading surfaces with SDL will use SDL_LoadBMP or IMG_Load,
and neither of these return surfaces suitable for glTexImage2D other than
by pure luck. SDL_image returns images up to 8bpp as 8bpp surfaces reliably;
anything else might be 15, 16, 24, 32, RGBA, ARGB, BGR, RGB, whatever,
depending on the phase of the moon

yes, and opengl handles all those odd formats, GL_RGB GL_RGBA GL_BGR GL_BGRA
GL_UNSIGNED_SHORT_5_6_5 GL_UNSIGNED_SHORT_5_6_5_REV GL_UNSIGNED_SHORT_4_4_4_4,
even odd weird things like GL_UNSIGNED_INT_10_10_10_2. The driver has the code
to make the appropriate translation, and iirc, some cards prefer BGR data, so
always changing it to rgba is A) duplicating what the driver does and B) may
even make it so the driver has to put it back how it was. The format function
way lets you get the driver to see what to do with minimal fuss and cpu time,
thus saving the ‘startup’ time, and with the number of people who bitch about
how slow a lot of games startup times, that’s something to be careful of :slight_smile:

BTW, those formats I listed are mostly OGL 1.2, I believe that the only os in
existance still more than five freakin’ years behind with the ogl interface is
windows, so you might need to either load the features of ogl 1.2 and 1.3 as
extensions, or ditch the libs and header and get something a little more
current. http://www.opengl.org/developers/documentation/OpenGL12.html has links
to information about BGRA formats, packed pixel formats, the spec, etc…

    -Erik <@Erik_Greenwald> [http://math.smsu.edu/~erik]

The opinions expressed by me are not necessarily opinions. In all probability,
they are random rambling, and to be ignored. Failure to ignore may result in
severe boredom or confusion. Shake well before opening. Keep Refrigerated.

erik at math.smsu.edu (Erik Greenwald) wrote:

yes, and opengl handles all those odd formats

no, and in any case they need to be told about it. No opengl driver is psychic

You do realize that OpenGL 1.2 has pixel formats up to and including RGBA
10 10 10 2 (and the same ABGR) right?

The best solution is to support every possible format you’re likely to
load directly - OpenGL is smart and can deal. If there is some random
format that gets thrown at the application and it’s not one you’re
prepared to cope with, convert and then upload. But if you support every
format OpenGL 1.2 will give you, there is VERY little chance you’re ever
going to see one that you could not easily handle.On Wed, Oct 17, 2001 at 11:09:46AM +0200, Mattias Engdegard wrote:

erik at math.smsu.edu (Erik Greenwald) wrote:

yeah, sorry, I’m doing game development, I got a decent amount of control
over format.

most people loading surfaces with SDL will use SDL_LoadBMP or IMG_Load,
and neither of these return surfaces suitable for glTexImage2D other than
by pure luck. SDL_image returns images up to 8bpp as 8bpp surfaces reliably;
anything else might be 15, 16, 24, 32, RGBA, ARGB, BGR, RGB, whatever,
depending on the phase of the moon


Joseph Carter Free software developer

Granted, RMS is a fanatic, I don’t deny this. I’ll even say
he’s a royal pain in the arse most of the time. But he’s
still more often right than not, and he deserves some level of
credit and respect for his work. We would NOT be here today
without him.

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20011017/cbff99d5/attachment.pgp