Testgl.c? gl texture from sdl_surface uses additional memory?

hello, i’m working on a simple game that loads a large
number of images and simply displays them on the
screen. these images are being loaded the exact same
way as the testgl program in the test/ directory of
the SDL source package when run as “testgl -logo”.
for some reason the amount of memory used by my
program is far larger than the size of my bmp images.
the amount of memory used by my program used to be
equivalent to the size of the images when the glut was
being used. is there a memory issue when creating gl
textures from a SDL_Surface? tia

-steve

here is the code from testgl.c that i don’t fully
understand, if anyone can give a quick explanation of
it i would be very grateful. mainly, why is the
temporary SDL_Surface, “image”, created at a larger
size than the original surface?

SDL_Surface surface;
surface = IMG_Load(“myimage.bmp”);
.
.
.

SDL_Surface image;

/* Use the surface width and
height expanded to powers of 2 /
w = powerOfTwo(surface->w);
h = powerOfTwo(surface->h);
texcoord[0] = 0.0f; /
Min X /
texcoord[1] = 0.0f; /
Min Y /
texcoord[2] = (GLfloat)surface->w/w; /
Max X /
texcoord[3] = (GLfloat)surface->h/h; /
Max Y */

image = SDL_CreateRGBSurface(SDL_SWSURFACE,
w, h, …__________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th
http://taxes.yahoo.com/filing.html

did you free the surface after you made it into a gl texture?

if not thats probly where the extra memory is going (:> ----- Original Message -----

From: geinitz@yahoo.com (steve geinitz)
To:
Sent: Wednesday, April 14, 2004 3:42 PM
Subject: [SDL] testgl.c? gl texture from sdl_surface uses additional memory?

hello, i’m working on a simple game that loads a large
number of images and simply displays them on the
screen. these images are being loaded the exact same
way as the testgl program in the test/ directory of
the SDL source package when run as “testgl -logo”.
for some reason the amount of memory used by my
program is far larger than the size of my bmp images.
the amount of memory used by my program used to be
equivalent to the size of the images when the glut was
being used. is there a memory issue when creating gl
textures from a SDL_Surface? tia

-steve

here is the code from testgl.c that i don’t fully
understand, if anyone can give a quick explanation of
it i would be very grateful. mainly, why is the
temporary SDL_Surface, “image”, created at a larger
size than the original surface?

SDL_Surface surface;
surface = IMG_Load(“myimage.bmp”);
.
.
.

SDL_Surface image;

/* Use the surface width and
height expanded to powers of 2 /
w = powerOfTwo(surface->w);
h = powerOfTwo(surface->h);
texcoord[0] = 0.0f; /
Min X /
texcoord[1] = 0.0f; /
Min Y /
texcoord[2] = (GLfloat)surface->w/w; /
Max X /
texcoord[3] = (GLfloat)surface->h/h; /
Max Y */

image = SDL_CreateRGBSurface(SDL_SWSURFACE,
w, h, …


Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th
http://taxes.yahoo.com/filing.html


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

yes, i’m sorry i suppose i should’ve mentioned that i
was indeed freeing the surface with SDL_FreeSurface. i
even tried using free(image->pixels), but that only
caused it to crash. i assume that the gl texture is
using those same pixels after the SDL_Surface is gone.
but i tried free() because the SDL documentation says
this about SDL_FreeSurface():

Frees the resources used by a previously created
SDL_Surface. If the surface was created using
SDL_CreateRGBSurfaceFrom then the pixel data is not
freed.

so how would you free the pixel data when you used
SDL_CreateRGBSurfaceFrom()? or can you?
thanks for double checking that i’m not being as dumb
as i normally am, and thanks in advance for anything
else.

— Alan Wolfe wrote:> did you free the surface after you made it into a gl

texture?

if not thats probly where the extra memory is going
(:

----- Original Message -----
From: “steve geinitz” <@steve_geinitz>
To:
Sent: Wednesday, April 14, 2004 3:42 PM
Subject: [SDL] testgl.c? gl texture from sdl_surface
uses additional memory?

hello, i’m working on a simple game that loads a
large
number of images and simply displays them on the
screen. these images are being loaded the exact
same
way as the testgl program in the test/ directory
of
the SDL source package when run as “testgl -logo”.
for some reason the amount of memory used by my
program is far larger than the size of my bmp
images.
the amount of memory used by my program used to be
equivalent to the size of the images when the glut
was
being used. is there a memory issue when creating
gl
textures from a SDL_Surface? tia

-steve

here is the code from testgl.c that i don’t fully
understand, if anyone can give a quick explanation
of
it i would be very grateful. mainly, why is the
temporary SDL_Surface, “image”, created at a
larger
size than the original surface?

SDL_Surface surface;
surface = IMG_Load(“myimage.bmp”);
.
.
.

SDL_Surface image;

/* Use the surface width and
height expanded to powers of 2 /
w = powerOfTwo(surface->w);
h = powerOfTwo(surface->h);
texcoord[0] = 0.0f; /
Min X /
texcoord[1] = 0.0f; /
Min Y /
texcoord[2] = (GLfloat)surface->w/w; /
Max X /
texcoord[3] = (GLfloat)surface->h/h; /
Max Y */

image = SDL_CreateRGBSurface(SDL_SWSURFACE,
w, h, …


Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th

steve geinitz wrote:

here is the code from testgl.c that i don’t fully
understand, if anyone can give a quick explanation of
it i would be very grateful. mainly, why is the
temporary SDL_Surface, “image”, created at a larger
size than the original surface?

OpenGL requires texture sizes to be a power of 2. 1, 2, 4, 8, 16, …
you get the idea?

best regards …
clemens

now everything makes perfect sense. i had never
really done anything with gl textures until now,
thanks for your help.

-steve

— Clemens Kirchgatterer wrote:> steve geinitz <@steve_geinitz> wrote:

here is the code from testgl.c that i don’t fully
understand, if anyone can give a quick explanation
of
it i would be very grateful. mainly, why is the
temporary SDL_Surface, “image”, created at a
larger
size than the original surface?

OpenGL requires texture sizes to be a power of 2. 1,
2, 4, 8, 16, …
you get the idea?

best regards …
clemens


Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th