Hi all,

Im having problems rendering to a texture, the way that i understand it works is by:
1) creating a blank texture (initialization)
2) render the scene, and then copy it to the blank texture
3) render the scene

Create:
[pascal]
SetLength(Indexs, 1);

glEnable(GL_TEXTURE_2D);
glGenTextures(1, @Indexs[0]);
glBindTexture(GL_TEXTURE_2D, Indexs[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, Width, Height, 0);
[/pascal]

Draw scene to texture:
[pascal]
If Textures[Texture] = Nil Then Exit;

glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);

glViewport(0, 0, Textures[Texture].Width, Textures[Texture].Height);

glMatrixMode(GL_TEXTURE);
glLoadIdentity;
glMatrixMode(GL_MODELVIEW);

FollowTarget(Pos, Heading, Distance);

glBindTexture(GL_TEXTURE_2D, Indexs[0]);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, Width, Height);

glViewPort(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
[/pascal]

I have bound got something wrong, all i get is a blank white texture