View Full Version : glCopyTexImage2D
M109uk
07-09-2003, 12:18 AM
Hi all,
im trying to add a CCTV element, basicly i am rendering a certain section of my world to a texture and then rendering it on to a face in the world, except that it isnt working that way :(
The CCTV class has a position and a direction that im setting the viewport to, and then render my world (without the CCTV textures) then using glCopyTexImage2D i assign it on to an already created (blank) texture, then i render my world (with the CCTV textures) but when i try and render my world to get the CCTV textures the whole screen goes blank, but if i dont then it goes ok except for the not having a texture problem.
The code i use to get the CCTV textures is ::
glViewport(0,0,fWidth,fHeight);
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
glLoadIdentity;
glDisable(GL_DEPTH_TEST);
fCamera.X := fPosition[0];
fCamera.Y := fPosition[1];
fCamera.Z := fPosition[2];
fCamera.dX := fDirection[0];
fCamera.dY := fDirection[1];
fCamera.dZ := fDirection[2];
fCamera.SetView;
// Render my world
fTexture.BindTexture;
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, fWidth, fHeight, 0);
glEnable(GL_DEPTH_TEST);
glViewport(0,0,vWidth,vHeight);
This is being called just before the world is rendered so that it is updated, then as im rendering the world i check to if the face has a CCTV texture, if so it is rendered.
thanx for any help :)
lithander
08-09-2003, 01:38 PM
I think your approach is correct and I don't see any problem with the code you posted. (given that the custom methods you call work as they are supposed to ;)) What are the values of fwidth and fheight? They should be the size of the texture and power of two, but I guess you know this allready!
If you flip the buffer after rendering the scene the first time (for the cctv-texture) you should see the complete scene on your screen but in the size of the texture in the low left corner. does it work?
and my last question: how do you generate the blank texture?
greetings,
-lith
M109uk
08-09-2003, 05:21 PM
hi,
The values for Height and Width are 256.
Yes if i dont resize the viewport then i get the world rendered in the lower left cornour. Is their away to get it to render from a different position in the world than i am, cause i have tried to move the camera then create the texture and move it back but this some reason screws everything up :?
I have a texture class that when is created it either loads a texture and records the Index, or it creates a Blank texture and records its Index, I create the blank texture by ::
procedure glGenTextures(n: GLsizei; var textures: GLuint); stdcall; external opengl32;
procedure BlankTexture;
var
pData: Pointer;
begin
GetMem(pData, 256*256*3);
glGenTextures(1, fIndex);
glBindTexture(GL_TEXTURE_2D, fIndex);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); {Texture blends with object background}
glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, pData); // Use when not wanting mipmaps to be built by openGL
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); { only first two can be used }
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); { all of the above can be used }
FreeMem(pData);
end;
Would using ARB_Multitexture effect this in anyway?
When i use glBindTexture i get a blank screen, but if i bind it to a layer i dont get the texture but the world is still rendered?!?
lithander
08-09-2003, 10:33 PM
The parts of code you posted should just work fine...
Yes if i dont resize the viewport then i get the world rendered in the lower left cornour
Well, then there shouldn't be any problems to copy the framebuffer into the texture after rendering. :-/
Would using ARB_Multitexture effect this in anyway?
No, that shouldn't be necessary...
When i use glBindTexture I get a blank screen, but if i bind it to a layer i dont get the texture but the world is still rendered?!?
?!? When you use wich glBindTexture where? You don't try to bind the blank texture _before_ rendering the world, do you? and what is a layer in your case?
Is their away to get it to render from a different position in the world than i am, cause i have tried to move the camera then create the texture and move it back but this some reason screws everything up :?
If your camera class works as it is supposed to, it should allow you to view the world from every position you wish. However, you might want to try saving the matrix by pushing it onto the stack before moving the camera. That way you can restore the former position without moving the camera back...
Hmm. Sorry, that I can't help you but I'm pretty sure that the parts of code you posted are okay... If you want I could have a look at the whole project or respective an excerpt illustrating the problem.
-lith
M109uk
12-09-2003, 12:54 AM
Hi,
I have finally managed to get it working, i think the problem was that i didnt have the glPushMatrix and glPopMatrix in the right places :roll:
and the same reason for the camera class lol
i am using Layer0 and Layer1 with GL_ARB_Multitexture, but it doesnt seem to make any difference if i bind it to either of the layers or just use glBindTexture.
if your intrested this is how it looks now ::
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
Textures.InactiveLayer0; // Deactivate ARB Layer 0
Textures.InactiveLayer1; // Deactivate ARB Layer 1
glDisable(GL_DEPTH_TEST);
glViewport(0,0,256,256);
glPushMatrix;
glLoadIdentity;
glRotatef(-fDirection[0], 1, 0, 0);
glRotatef(-fDirection[1], 0, 1, 0);
glRotatef(-fDirection[2], 0, 0, 1);
glTranslatef(-fPosition[0], -fPosition[1], -fPosition[2]);
// Render world!
fTexture.BindTexture; { glBindTexture(GL_TEXTURE_2D, fTexture.Index); }
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 256, 256, 0);
glPopMatrix;
glBindTexture(GL_TEXTURE_2D, 0);
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
glViewport(0,0,vWidth,vHeight);
Thanx for your help :D
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.