Render to framebuffer textures are VERY buggy as I found out...

You also have to fill in the mipmap states (Even if you're not using mipmaps its usually a good idea to fully create the texture with mipmaps anyway)

Also the glTexImage2d() with the data argument set to nil can cause crashes on some systems, so I found out. So this is the code I used in my project:



[pascal]
// Note that FTarget is just set to GL_TEXTURE_2D.
// In the original code, it was also used with Cubemap textures too.

// Create a blank texture image first. It's handle is stored in FTexObject

glBindTexture(FTarget, FTexObject);

{ Create mipmap images too. This is to keep the texture from being
inconsistent at startup. Use GL_SGIS_generate_mipmaps to actually fill in
the mipmaps. }
i := 0;
mw := w;
mh := h;
done := FALSE;

try
Addtolog('Uploading mipmaps');
GetMem(Data, w*h*3);
ZeroMemory(Data, w*h*3);

while not done do
begin
if (mw = 1) and (mh = 1) then done := TRUE;
glTexImage2d(FTarget, i, 3, mw, mh, 0, GL_RGB, GL_UNSIGNED_BYTE, Data);
INC(i);
if mw > 1 then mw := mw shr 1;
if mh > 1 then mh := mh shr 1;
end;
glFinish;
finally
FreeMem(Data, w*h*3);
Data := nil;
end;
[/pascal]

It's not pretty and you could probably get away with setting it to nil and not worrying about the glFinish command either, but this seems to work best for all the pc's its run on.