OpenGL Help!

I’m working on a quick OpenGL demo for SDL, basically I took the
aliens demo and dropped the resolution down to 256x256, then I mapped
it to an OpenGL texture and mapped that on a cube (well I borrowed
code to do that). The problem is it runs for about a second
(accelerated, 3 seconds under raw mesa because of lag) and then it
dies and mesa complains, but for the life of me I can’t figure out
what is causing the crash.

members.xoom.com/kokido/glaliens.html

has a link to the code

Phoenix Kokido
members.xoom.com/kokido
@Wes_Poole

Phoenix Kokido schrieb am 21 Mar 2000:

I’m working on a quick OpenGL demo for SDL, basically I took the
aliens demo and dropped the resolution down to 256x256, then I mapped
it to an OpenGL texture and mapped that on a cube (well I borrowed
code to do that).

Hm. I thought that code looks familiar :slight_smile:

The problem is it runs for about a second
(accelerated, 3 seconds under raw mesa because of lag) and then it
dies and mesa complains, but for the life of me I can’t figure out
what is causing the crash.

In your attempt to keep aliens from having 666 lines you accidently deleted
a ‘numupdates = 0;’ line, resulting in an array index out-of-bound. The
attached patch fixes that problem and another one:

It’s not a good idea to generate a new texture ID every frame. You will
quickly eat all available memory. Generate the texture ID once and reuse
it, if you don’t need the old texture contents anymore.

  • Andreas–
    Probably one of the smallest 3D-Games in the world: http://www.gltron.org
    More than 60’000 Downloads of the latest version (0.53)
    -------------- next part --------------
    *** aliens.c.orig Wed Mar 22 11:13:34 2000
    — aliens.c Wed Mar 22 11:15:53 2000

*** 154,161 ****
format = (bpp == 24) ? GL_RGB : GL_RGBA;

/* load the texture into OGL */

! glGenTextures(1, &tex_id);
! glBindTexture(GL_TEXTURE_2D, tex_id);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, format, image->w, image->h, 0,
format, GL_UNSIGNED_BYTE, data);
— 154,160 ----
format = (bpp == 24) ? GL_RGB : GL_RGBA;

/* load the texture into OGL */

!
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, format, image->w, image->h, 0,
format, GL_UNSIGNED_BYTE, data);


*** 331,337 ****
screen, blits[i].dstrect);
}
SDL_UpdateRects(screen, numupdates, dstupdate);
! //ConvertTexture(screen);

glClearColor(0, 0, 0.5, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

— 330,337 ----
screen, blits[i].dstrect);
}
SDL_UpdateRects(screen, numupdates, dstupdate);
! numupdates = 0;
! ConvertTexture(screen);

glClearColor(0, 0, 0.5, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

*** 603,608 ****
— 603,609 ----

main(int argc, char *argv[])
{

  •     int tex_id;
    
    /* Initialize the SDL library */
    if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 ) {
    fprintf(stderr, “Couldn’t initialize SDL: %s\n”,SDL_GetError());

*** 635,640 ****
— 636,644 ----
gluLookAt(0, 0, 2,
0, 0, 0,
0, 1, 0);
+

  • glGenTextures(1, &tex_id);

  • glBindTexture(GL_TEXTURE_2D, tex_id);

    screen=SDL_CreateRGBSurface(SDL_SWSURFACE, 256, 256, 24, 0,
    0,

I was pretty sure I had done something very stupid, thanks for
helping. I actually thought that the problem might have been related
to using all my available texture memory at one time, but now I see
that my code never actually ran that long.

Phoenix Kokido
members.xoom.com/kokido
@Wes_Poole

Andreas Umbach wrote:

Phoenix Kokido <@Wes_Poole> schrieb am 21 Mar 2000:

I’m working on a quick OpenGL demo for SDL, basically I took the
aliens demo and dropped the resolution down to 256x256, then I mapped
it to an OpenGL texture and mapped that on a cube (well I borrowed
code to do that).

Hm. I thought that code looks familiar :slight_smile:

The problem is it runs for about a second
(accelerated, 3 seconds under raw mesa because of lag) and then it
dies and mesa complains, but for the life of me I can’t figure out
what is causing the crash.

In your attempt to keep aliens from having 666 lines you accidently deleted
a ‘numupdates = 0;’ line, resulting in an array index out-of-bound. The
attached patch fixes that problem and another one:

It’s not a good idea to generate a new texture ID every frame. You will
quickly eat all available memory. Generate the texture ID once and reuse
it, if you don’t need the old texture contents anymore.

  • Andreas

    Probably one of the smallest 3D-Games in the world: http://www.gltron.org
    More than 60’000 Downloads of the latest version (0.53)

-------------- next part --------------
*** aliens.c.orig Wed Mar 22 11:13:34 2000
— aliens.c Wed Mar 22 11:15:53 2000***************
*** 154,161 ****
format = (bpp == 24) ? GL_RGB : GL_RGBA;

/* load the texture into OGL */

! glGenTextures(1, &tex_id);
! glBindTexture(GL_TEXTURE_2D, tex_id);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, format, image->w, image->h, 0,
format, GL_UNSIGNED_BYTE, data);
— 154,160 ----
format = (bpp == 24) ? GL_RGB : GL_RGBA;

/* load the texture into OGL */

!
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, format, image->w, image->h, 0,
format, GL_UNSIGNED_BYTE, data);


*** 331,337 ****
screen, blits[i].dstrect);
}
SDL_UpdateRects(screen, numupdates, dstupdate);
! //ConvertTexture(screen);

glClearColor(0, 0, 0.5, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

— 330,337 ----
screen, blits[i].dstrect);
}
SDL_UpdateRects(screen, numupdates, dstupdate);
! numupdates = 0;
! ConvertTexture(screen);

glClearColor(0, 0, 0.5, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

*** 603,608 ****
— 603,609 ----

main(int argc, char *argv[])
{

  •     int tex_id;
    
    /* Initialize the SDL library */
    if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 ) {
    fprintf(stderr, “Couldn’t initialize SDL: %s\n”,SDL_GetError());

*** 635,640 ****
— 636,644 ----
gluLookAt(0, 0, 2,
0, 0, 0,
0, 1, 0);
+

  • glGenTextures(1, &tex_id);

  • glBindTexture(GL_TEXTURE_2D, tex_id);

    screen=SDL_CreateRGBSurface(SDL_SWSURFACE, 256, 256, 24, 0,
    0,