1

We were happily using glTexSubImage2d to update a texture every few frames which had been initialised with glTexImage2d in our GL initialisation. After adding in a particle system with each particle textured itself our quad showing the glTexSubImage2d texture doesn't display.

The particle's textures are PNG and so we use SDL to load the PNG to an SDL Surface and then glTexImage2d is used to bind the PNG to a texture.

If we change the quad's glTexSubImage2d call to a glTexImage2d call the texture shows but this is extremely inefficient and cuts the framerate in half at least and so would rather be using glTexSubImage2d (as it worked before).

Does anyone have any idea why we now can't use glTexSubImage2d?

Below is relevant pieces of code for the initialisation and binding of textures:

Loading in the particle texture

//Load smoke texture
SDL_Surface *surface;   
SDL_Surface *alpha_image;

if( (surface = IMG_Load("smoke_particle.png")))
{
    SDL_PixelFormat *pixf = SDL_GetVideoSurface()->format;
    alpha_image = SDL_CreateRGBSurface( SDL_SWSURFACE, surface->w, surface->h, 32, pixf->Bmask, pixf->Gmask, pixf->Rmask, pixf->Amask );

    SDL_SetAlpha(surface,0,0);
    SDL_BlitSurface( surface, NULL, alpha_image, NULL );

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

    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );

    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, surface->w, surface->h, 0, 
                GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels );
}

Setting up the quad's texture:

glEnable(GL_TEXTURE_2D);
glGenTextures(1, &texVid);

glBindTexture(GL_TEXTURE_2D, texVid);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, VIDEO_WIDTH, VIDEO_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);

glPixelStorei(GL_UNPACK_ALIGNMENT, 2);

The only calls in initGL() are the enabling of GL_TEXTURE_2D, GL_BLEND setting up glBlendFunc() and the setting up of the quad's texture as above.

Any ideas?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Infiniti Fizz
  • 1,726
  • 4
  • 24
  • 40
  • 2
    Maybe it's a bit of a trivial comment, but do you bind the correct texture before updating its data and using it for drawing? – Christian Rau Jul 28 '11 at 13:03
  • I'd also guess that you don't have the correct texture bound. But it's impossible to tell without at least the update code for the quad and the order in which that stuff happens. – ltjax Jul 28 '11 at 13:25
  • Feeling a bit embarassed now but after using gDebugger to break on glTexSubImage2d() we realised VIDEO_HEIGHT and VIDEO_WIDTH were the wrong way around and so opengl was throwing an INVALID_NUM error because it wanted a 512x1024 and we were passing a 1024x512...oops. Thanks for the comments though. – Infiniti Fizz Jul 29 '11 at 11:26

1 Answers1

0

Stupidly we had VIDEO_WIDTH set to the height of the texture and VIDEO_HEIGHT to the width of the texture.

Sorry if we wasted anyone's time.

Can anyone lock this or delete this or anything?

Thanks,

Infinitifizz

Infiniti Fizz
  • 1,726
  • 4
  • 24
  • 40