SDL, OpenGL and textures solved

Hello everyone,

during my run to the toilet I came up with the sollution (small area’s
free up my mind! :slight_smile: and it now works perfectly!

Yours,

Niels Wagenaar> -----Oorspronkelijk bericht-----

Van: Niels Wagenaar
Verzonden: maandag 10 december 2001 11:52
Aan: sdl at libsdl.org
Onderwerp: [SDL] SDL, OpenGL and textures

Hello,

Currently I’ve been trying to get some knowlegde about OpenGL and SDL.
I really must say that it works beautyfull, the turorial is really
great and I made some nice progress with SDL and OpenGL!

Now my question, my code is based upon the testgl application
in de SDL
test directory by using the code from DrawLogoTexture. The only
difference
is that I’ve got a SDL_Surface which acts as a buffer (and
has the gfx)
and must be blit all the time. I managed to get the updates working by
changing the function DrawLogoTexture to grab the gfx from the buffer.
Only now I see that my application uses a lot of memory
resulting in use
of swap and a performance downgrade.

It’s possibly that the function DrawLogoTexture from the testgl is
optimized
for a single texture load (like an image in BMP format) and not for a
SDL_Surface which is upgraded frequently. What’s the best way to make
sure
that I can use OpenGL using textures based upon a SDL_Surface
(display)
and
then blit this to the main OpenGL screen (gbascreen). Below
my slightly
changed source has been put. Any help is appreciated. Please
understand
that
I’m a newbie on OpenGL and SDL.

Here’s a snip of my code (DrawLogoTexture was slightly changed while
others
haven’t been changed at all) :

inline void DrawLogoTexture(void)
{
static GLuint texture;
static GLfloat texMinX, texMinY;
static GLfloat texMaxX, texMaxY;
static int x = 0;
static int y = 0;
static int w, h;
static int delta_x = 1;
static int delta_y = 1;
static Uint32 last_moved = 0;

GLfloat texcoord[4];

w = gbascreen->w; // gbascreen is here the OpenGL display
h = gbascreen->h;

if ( !texture ) {
/* Convert the buffer display into an OpenGL texture */
texture = SDL_GL_LoadTexture(display, texcoord);

/* Make texture coordinates easy to understand */
texMinX = texcoord[0];
texMinY = texcoord[1];
texMaxX = texcoord[2];
texMaxY = texcoord[3];

/* Make sure that the texture conversion is okay */
if ( ! texture ) {
printf(“failed!\n”);
return;
}

}
/* Show the image on the screen */
SDL_GL_Enter2DMode();
glBindTexture(GL_TEXTURE_2D, texture);
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(texMinX, texMinY); glVertex2i(x, y );
glTexCoord2f(texMaxX, texMinY); glVertex2i(x+w, y );
glTexCoord2f(texMinX, texMaxY); glVertex2i(x, y+h);
glTexCoord2f(texMaxX, texMaxY); glVertex2i(x+w, y+h);
glEnd();
SDL_GL_Leave2DMode();

/* display and swap the buffers */

SDL_GL_SwapBuffers( );
}

Tnx in advance!

Regards,

Niels Wagenaar


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

A bit too much information than i needed. But glad to see that the end
result provided a solution.

Dominique.

nwagenaar at digitaldynamics.nl wrote:> Hello everyone,

during my run to the toilet I came up with the sollution (small area’s
free up my mind! :slight_smile: and it now works perfectly!

Yours,

Niels Wagenaar

-----Oorspronkelijk bericht-----
Van: Niels Wagenaar
Verzonden: maandag 10 december 2001 11:52
Aan: sdl at libsdl.org
Onderwerp: [SDL] SDL, OpenGL and textures

Hello,

Currently I’ve been trying to get some knowlegde about OpenGL and SDL.
I really must say that it works beautyfull, the turorial is really
great and I made some nice progress with SDL and OpenGL!

Now my question, my code is based upon the testgl application
in de SDL
test directory by using the code from DrawLogoTexture. The only
difference
is that I’ve got a SDL_Surface which acts as a buffer (and
has the gfx)
and must be blit all the time. I managed to get the updates working by
changing the function DrawLogoTexture to grab the gfx from the buffer.
Only now I see that my application uses a lot of memory
resulting in use
of swap and a performance downgrade.

It’s possibly that the function DrawLogoTexture from the testgl is
optimized
for a single texture load (like an image in BMP format) and not for a
SDL_Surface which is upgraded frequently. What’s the best way to make
sure
that I can use OpenGL using textures based upon a SDL_Surface
(display)
and
then blit this to the main OpenGL screen (gbascreen). Below
my slightly
changed source has been put. Any help is appreciated. Please
understand
that
I’m a newbie on OpenGL and SDL.

Here’s a snip of my code (DrawLogoTexture was slightly changed while
others
haven’t been changed at all) :

inline void DrawLogoTexture(void)
{
static GLuint texture;
static GLfloat texMinX, texMinY;
static GLfloat texMaxX, texMaxY;
static int x = 0;
static int y = 0;
static int w, h;
static int delta_x = 1;
static int delta_y = 1;
static Uint32 last_moved = 0;

GLfloat texcoord[4];

w = gbascreen->w; // gbascreen is here the OpenGL display
h = gbascreen->h;

if ( !texture ) {
/* Convert the buffer display into an OpenGL texture */
texture = SDL_GL_LoadTexture(display, texcoord);

/* Make texture coordinates easy to understand */
texMinX = texcoord[0];
texMinY = texcoord[1];
texMaxX = texcoord[2];
texMaxY = texcoord[3];

/* Make sure that the texture conversion is okay */
if ( ! texture ) {
printf(“failed!\n”);
return;
}

}
/* Show the image on the screen */
SDL_GL_Enter2DMode();
glBindTexture(GL_TEXTURE_2D, texture);
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(texMinX, texMinY); glVertex2i(x, y );
glTexCoord2f(texMaxX, texMinY); glVertex2i(x+w, y );
glTexCoord2f(texMinX, texMaxY); glVertex2i(x, y+h);
glTexCoord2f(texMaxX, texMaxY); glVertex2i(x+w, y+h);
glEnd();
SDL_GL_Leave2DMode();

/* display and swap the buffers */
SDL_GL_SwapBuffers( );
}

Tnx in advance!

Regards,

Niels Wagenaar


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